#pragma once #include typedef enum ASTtype{ AST_LIST, AST_WORD, AST_NUMBER, AST_STRING, AST_SYMBOL, } ASTtype; typedef struct AST AST; typedef struct ASTlist{ int len; AST **nodes; bool quoted; } ASTlist; typedef struct ASTword{ char *word; } ASTword; typedef struct ASTnumber{ double num; } ASTnumber; typedef struct ASTstring{ char *str; int len; } ASTstring; 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. //You should probably use ast_symbol(), in which case you don't have to do anything. } ASTsymbol; struct AST{ ASTtype type; union { ASTlist l; ASTword w; ASTnumber n; ASTstring S; ASTsymbol s; }; }; void ast_free(AST *ast); AST* ast_copy(const AST *ast); char* ast_stringify(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_string(char *str,int len); AST* ast_symbol(char *name);