From ccab148f1310b3cadffb99005941e39fa932d295 Mon Sep 17 00:00:00 2001 From: Teddy Date: Mon, 24 Mar 2014 12:40:12 +0800 Subject: AST construction for expressions --- ast.h | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'ast.h') diff --git a/ast.h b/ast.h index f6db7da..d438b92 100644 --- a/ast.h +++ b/ast.h @@ -1,7 +1,17 @@ -typedef struct { +#ifndef AST_H +#define AST_H + +#define EXP_POSTFIX 1024 +#define POSTFIX_ARR 1025 +#define POSTFIX_CALL 1026 +#define POSTFIX_DOT 1027 +#define POSTFIX_PTR 1028 +#define EXP_CAST 1029 + +typedef struct CNode { enum { /* Top Level */ - PROG = 1024, FUNC_DEF, PARAMS, + PROG, FUNC_DEF, PARAMS, DECL, /* declaration */ DECLR, /* declarator */ DECLRS, @@ -18,11 +28,17 @@ typedef struct { CONT_STMT , BREAK_STMT, RET_STMT, /* 'continue', 'break', 'return' */ /* Expressions (expressions use their token ID to denote their types */ - EXP + EXP, + TYPE_NAME, + ID, /* identifier */ + INT, /* INT_CONST */ + CHAR, + STR } type; union { int intval; - char *strvar; + int subtype; + char *strval; } rec; struct CNode *chd, *next; /* For error reporting */ @@ -30,3 +46,16 @@ typedef struct { int row, col; } loc; } CNode; + +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_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); + +extern CNode *ast_root; + +#endif -- cgit v1.2.3-70-g09d2