#pragma once #include #include #include typedef enum ASTtype{ AST_BLOCK, AST_OP, AST_NUM, AST_STR, AST_VAR, AST_CALL, AST_IF, AST_WHILE, } ASTtype; typedef struct AST AST; typedef struct ASTblock ASTblock; typedef struct ASTop ASTop; typedef struct ASTnum ASTnum; typedef struct ASTstr ASTstr; typedef struct ASTvar ASTvar; typedef struct ASTcall ASTcall; typedef struct ASTif ASTif; typedef struct ASTwhile ASTwhile; struct ASTblock{ int len; AST **exprs; }; struct ASTop{ const char *op; // Constant string, does not need to be freed AST *left,*right; }; struct ASTnum{ bool isint; union { int64_t i; double d; }; }; struct ASTstr{ int len; // Excludes terminating null char char *str; // May contain null chars before terminating null char }; struct ASTvar{ char *name; }; struct ASTcall{ char *func; int nargs; AST **args; }; struct ASTif{ AST *cond; AST *thenb,*elseb; }; struct ASTwhile{ AST *cond; AST *body; }; typedef struct AST{ ASTtype type; union { ASTblock b; ASTop o; ASTnum n; ASTstr s; ASTvar v; ASTcall c; ASTif i; ASTwhile w; }; } AST; typedef enum Associativity{ AS_PREFIX, AS_SUFFIX, AS_LEFT, AS_RIGHT, AS_NONASSOC } Associativity; AST* parse(const char *source,char **errmsg); void ast_debug(FILE *stream,const AST *ast); void ast_free(AST *ast);