diff options
author | Teddy <[email protected]> | 2014-03-23 20:12:50 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-03-23 20:12:50 +0800 |
commit | 4edd0c4745ed0683867b116dc8ac33c65bf0b99a (patch) | |
tree | 6ef0946837bb4c7b8512eb6d96a9260c14ed1a29 | |
parent | 97fb20538cdac668dda0a0aa82884505bc0df61a (diff) |
add AST
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | ast.h | 32 | ||||
-rw-r--r-- | cibic.y | 1 |
3 files changed, 36 insertions, 0 deletions
@@ -9,3 +9,6 @@ lex.yy.c: cibic.l flex cibic.l cibic.tab.c: cibic.y bison -d cibic.y + +clean: + rm -f cibic lex.yy.c cibic.tab.c @@ -0,0 +1,32 @@ +typedef struct { + enum { + /* Top Level */ + PROG = 1024, FUNC_DEF, PARAMS, + DECL, /* declaration */ + DECLR, /* declarator */ + DECLRS, + INIT_DECLRS, INIT_DECLR, + INITR, /* initializer */ + TYPE_SPEC, + STRUCT, UNION, + PLAIN_DECL, PLAIN_DECLR, + + /* Statments */ + EXP_STMT, /* expression-statment */ + COMP_STMT, IF_STMT, /* selection-statment */ + WHILE_STMT, FOR_STMT, + CONT_STMT , BREAK_STMT, RET_STMT, /* 'continue', 'break', 'return' */ + + /* Expressions (expressions use their token ID to denote their types */ + EXP + } type; + union { + int intval; + char *strvar; + } rec; + struct CNode *chd, *next; + /* For error reporting */ + struct Location { + int row, col; + } loc; +} CNode; @@ -1,5 +1,6 @@ %{ #include <stdio.h> +#include "ast.h" %} %token IDENTIFIER INT_CONST CHAR_CONST STR_CONST %token KW_VOID KW_CHAR KW_INT KW_STRUCT KW_UNION KW_IF KW_ELSE KW_WHILE |