#ifndef PARSE_H #define PARSE_H #include "report.h" #include #include typedef enum { PExprTy_Err, PExprTy_Ident, PExprTy_SubLabel, PExprTy_Imm, PExprTy_Str, PExprTy_Mem, PExprTy_Not, PExprTy_Negate, PExprTy_Or, PExprTy_Xor, PExprTy_And, PExprTy_Shl, PExprTy_Shr, PExprTy_Add, PExprTy_Sub, PExprTy_Mul, PExprTy_Div, PExprTy_Mod, } PExprTy; typedef struct PExpr PExpr; struct PExpr { PExprTy ty; Loc loc; union { char* str; uint16_t imm; PExpr* operand; struct { PExpr* left; PExpr* right; }; }; }; void pexpr_free(PExpr* expr); typedef struct { Loc loc; char* ident; PExpr* value; } PConst; void pconst_free(PConst* stmt); typedef struct { Loc loc; char* filename; } PInclude; void pinclude_free(PInclude* stmt); typedef struct { Loc loc; char* ident; bool local; } PLabel; void plabel_free(PLabel* stmt); typedef struct { Loc loc; char* ident; PExpr* ops[2]; size_t ops_size; } PLine; void pline_free(PLine* stmt); typedef struct Parser Parser; Parser* parser_new(const char* filename, const char* text); void parser_free(Parser* parser); void parser_skip_newlines(Parser* parser); bool parser_next_is_const(Parser* parser); bool parser_next_is_include(Parser* parser); bool parser_next_is_label(Parser* parser); PConst* parser_parse_const(Parser* parser); PInclude* parser_parse_include(Parser* parser); PLabel* parser_parse_label(Parser* parser); PLine* parser_parse_line(Parser* parser); bool parser_done(const Parser* parser); bool parser_error_occured(const Parser* parser); #endif