summaryrefslogtreecommitdiff
path: root/parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'parser.h')
-rw-r--r--parser.h54
1 files changed, 30 insertions, 24 deletions
diff --git a/parser.h b/parser.h
index dd378ae..caafe25 100644
--- a/parser.h
+++ b/parser.h
@@ -13,55 +13,59 @@ typedef enum ASTtype{
AST_CALL,
AST_IF,
AST_WHILE,
+ AST_FUNC,
+ AST_PROGRAM,
} 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{
+typedef struct ASTblock{
int len;
AST **exprs;
-};
-struct ASTop{
+} ASTblock;
+typedef struct ASTop{
const char *op; // Constant string, does not need to be freed
AST *left,*right;
-};
-struct ASTnum{
+} ASTop;
+typedef struct ASTnum{
bool isint;
union {
int64_t i;
double d;
};
-};
-struct ASTstr{
+} ASTnum;
+typedef struct ASTstr{
int len; // Excludes terminating null char
char *str; // May contain null chars before terminating null char
-};
-struct ASTvar{
+} ASTstr;
+typedef struct ASTvar{
char *name;
-};
-struct ASTcall{
+} ASTvar;
+typedef struct ASTcall{
char *func;
int nargs;
AST **args;
-};
-struct ASTif{
+} ASTcall;
+typedef struct ASTif{
AST *cond;
AST *thenb,*elseb;
-};
-struct ASTwhile{
+} ASTif;
+typedef struct ASTwhile{
AST *cond;
AST *body;
-};
+} ASTwhile;
+typedef struct ASTfunc{
+ char *name;
+ int nargs;
+ char **args;
+ AST *body;
+} ASTfunc;
+typedef struct ASTprogram{
+ int nfuncs;
+ AST **funcs;
+} ASTprogram;
typedef struct AST{
ASTtype type;
@@ -74,6 +78,8 @@ typedef struct AST{
ASTcall c;
ASTif i;
ASTwhile w;
+ ASTfunc f;
+ ASTprogram p;
};
} AST;