From f218a80d6ca8a69ba0b22cb87f99e8b82162bbee Mon Sep 17 00:00:00 2001 From: Teddy Date: Mon, 24 Mar 2014 20:54:55 +0800 Subject: AST Construction: almost done --- ast.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'ast.h') diff --git a/ast.h b/ast.h index d438b92..0b0264a 100644 --- a/ast.h +++ b/ast.h @@ -7,33 +7,48 @@ #define POSTFIX_DOT 1027 #define POSTFIX_PTR 1028 #define EXP_CAST 1029 +#define INITR_NORM 1030 +#define INITR_ARR 1031 +#define DECLR_FUNC 1032 +#define DECLR_ARR 1033 +#define STMT_EXP 1034 +#define STMT_COMP 1035 +#define STMT_IF 1036 +#define STMT_WHILE 1037 +#define STMT_FOR 1038 +#define STMT_CONT 1039 +#define STMT_BREAK 1040 +#define STMT_RET 1041 typedef struct CNode { enum { /* Top Level */ - PROG, FUNC_DEF, PARAMS, + PROG, + FUNC_DEF, DECL, /* declaration */ DECLR, /* declarator */ - DECLRS, - INIT_DECLRS, INIT_DECLR, + INIT_DECLR, INITR, /* initializer */ TYPE_SPEC, - STRUCT, UNION, - PLAIN_DECL, PLAIN_DECLR, + FIELD, /* struct-or-union field */ + PLAIN_DECL, /* Statments */ - EXP_STMT, /* expression-statment */ - COMP_STMT, IF_STMT, /* selection-statment */ - WHILE_STMT, FOR_STMT, - CONT_STMT , BREAK_STMT, RET_STMT, /* 'continue', 'break', 'return' */ + STMT, - /* Expressions (expressions use their token ID to denote their types */ + /* Expressions */ EXP, TYPE_NAME, ID, /* identifier */ INT, /* INT_CONST */ CHAR, - STR + STR, + NOP, + + COMP_STMTS, + COMP_DECLS, + ARGS, + PARAMS } type; union { int intval; @@ -47,15 +62,35 @@ typedef struct CNode { } loc; } CNode; +void cnode_init(); +CNode *cnode_create_nop(); +CNode *cnode_create_general(int type, int subtype, int pnum, va_list ap); +CNode *cnode_append(CNode *node, CNode *tail); + CNode *cnode_create_exp(int exp_type, int pnum, ...); CNode *cnode_create_type_spec(int spec_type, int pnum, ...); -CNode *cnode_append(CNode *node, CNode *tail); +CNode *cnode_create_declr(int declr_type, int pnum, ...); +CNode *cnode_create_stmt(int stmt_type, int pnum, ...); +CNode *cnode_create_initr(int initr_type, CNode *body); + +CNode *cnode_create_decl(CNode *type, CNode *init_declrs); +CNode *cnode_create_func(CNode *type, CNode *plain_decl, CNode *params, CNode *stmt); +CNode *cnode_create_init_declr(CNode *declr, CNode *initr); +CNode *cnode_create_struct_field(CNode *type_spec, CNode *declrs); +CNode *cnode_create_plain_decl(CNode *type_spec, CNode *declr); +CNode *cnode_create_comp_decls(CNode *decls); +CNode *cnode_create_comp_stmts(CNode *stmts); +CNode *cnode_create_args(CNode *arg_list); +CNode *cnode_create_params(CNode *plist); + CNode *cnode_create_identifier(char *val); CNode *cnode_create_int_const(int val); CNode *cnode_create_char_const(int val); CNode *cnode_create_str_const(char *val); -CNode *cnode_debug_print(CNode *ast); + +void cnode_debug_print(CNode *ast); extern CNode *ast_root; +extern CNode *null; #endif -- cgit v1.2.3