#ifndef CERC_PARSE_H #define CERC_PARSE_H #include "expr.h" struct ast_local { struct location loc; const char *name; struct type type; struct expr *init; }; struct ast_assign { struct location loc; struct expr lhs; struct expr rhs; }; enum crement { INCREMENT, DECREMENT, }; struct ast_elsebody { struct ast_stmt *stmts; int stmtsz, stmtlen; }; struct ast_else { struct location loc; int cond; union { struct ast_if *conditional; struct ast_elsebody body; } action; }; struct ast_if { struct location loc; struct expr cond; struct ast_stmt *stmts; int stmtsz, stmtlen; struct ast_else *alt; }; struct ast_for { struct location loc; struct ast_stmt *init; struct expr cond; struct ast_stmt *step; struct ast_stmt *stmts; int stmtsz, stmtlen; }; struct ast_return { struct location loc; struct expr *value; }; enum stmt { S_LOCALVAR, S_ASSIGN, S_ADDASSIGN, S_SUBASSIGN, S_MULASSIGN, S_DIVASSIGN, S_REMASSIGN, S_ANDASSIGN, S_ORASSIGN, S_XORASSIGN, S_INCR, S_DECR, S_IF, S_FOR, S_RETURN, S_EXPR, }; struct ast_stmt { struct location loc; enum stmt kind; union { struct ast_local localvar; struct ast_assign assign; enum crement cre; struct ast_if conditional; struct ast_for loop; struct ast_return ret; struct expr e; } stmt; }; struct ast_include { struct location loc; const char *path; }; struct ast_global { struct location loc; const char *name; int ispub; int isextern; struct type type; }; struct ast_const { struct location loc; const char *name; struct expr value; }; struct ast_enumvar { struct location loc; const char *name; struct expr *override; }; struct ast_enum { struct location loc; struct expr init; struct ast_enumvar *variants; int variantsz, variantlen; }; struct ast_field { struct location loc; const char *name; struct type type; }; struct ast_struct { struct location loc; const char *name; int align; struct ast_field *fields; int fieldsz, fieldlen; }; struct ast_union { struct location loc; const char *name; struct type *types; int typesz, typelen; }; struct ast_func { struct location loc; int ispub; int isextern; const char *name; struct ast_field *params; int paramsz, paramlen; struct type *ret; struct ast_stmt *stmts; int stmtsz, stmtlen; }; enum toplevel { TOP_INCLUDE, TOP_GLOBAL, TOP_CONST, TOP_ENUM, TOP_STRUCT, TOP_UNION, TOP_FUNC, }; struct ast_toplevel { struct location loc; enum toplevel kind; union { struct ast_include include; struct ast_global globalvar; struct ast_const constant; struct ast_enum enumconst; struct ast_struct structdecl; struct ast_union uniondecl; struct ast_func function; } tl; }; struct ast_unit { struct ast_toplevel *tops; int topsz, toplen; }; void parse(struct lexer *lexer, struct ast_unit *ast); #endif