From 4edd0c4745ed0683867b116dc8ac33c65bf0b99a Mon Sep 17 00:00:00 2001 From: Teddy Date: Sun, 23 Mar 2014 20:12:50 +0800 Subject: add AST --- Makefile | 3 +++ ast.h | 32 ++++++++++++++++++++++++++++++++ cibic.y | 1 + 3 files changed, 36 insertions(+) create mode 100644 ast.h diff --git a/Makefile b/Makefile index 6deae78..b6eeb33 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/ast.h b/ast.h new file mode 100644 index 0000000..f6db7da --- /dev/null +++ b/ast.h @@ -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; diff --git a/cibic.y b/cibic.y index 92f0cfe..a27c247 100644 --- a/cibic.y +++ b/cibic.y @@ -1,5 +1,6 @@ %{ #include +#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 -- cgit v1.2.3