diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-08-18 20:52:28 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-08-18 20:52:28 +0200 |
commit | 2c30522aa65126ebacfd52f7b38a2e24682d7065 (patch) | |
tree | 12baf2dfe17cc86f3c9711a700f6f9bbd3764275 /ast.h | |
parent | 235ffca9db0c2ba0d1ecbc79bdfb3dcdfca939c7 (diff) |
Second
Diffstat (limited to 'ast.h')
-rw-r--r-- | ast.h | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -0,0 +1,53 @@ +#pragma once + + +typedef enum ASTtype{ + AST_LIST, + AST_WORD, + AST_NUMBER, + AST_SYMBOL, +} ASTtype; + + +typedef struct AST AST; + +typedef struct ASTlist{ + int len; + AST **nodes; +} ASTlist; + +typedef struct ASTword{ + char *word; +} ASTword; + +typedef struct ASTnumber{ + double num; +} ASTnumber; + +typedef struct ASTsymbol{ + char *name; + int symid; + //if you're not the interpreter: + // if you just allocated the ASTsymbol yourself, set symid to -1; + // else, leave symid alone. +} ASTsymbol; + +struct AST{ + ASTtype type; + union { + ASTlist l; + ASTword w; + ASTnumber n; + ASTsymbol s; + }; +}; + + +void ast_free(AST *ast); + +AST* ast_copy(const AST *ast); + +AST* ast_list(int len,AST **nodes); //these convenience functions DO NOT copy their arguments +AST* ast_word(char *word); +AST* ast_number(double num); +AST* ast_symbol(char *name); |