aboutsummaryrefslogtreecommitdiffstats
path: root/c_parser/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-02-17 21:55:16 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-02-17 21:55:16 +0000
commit850f46eeb6de286d4b079373104af87e3aca781c (patch)
tree9f5f3c7b73d1447487030112c03c112ca85c7e55 /c_parser/src
parentce93fb7754f4565f70fe5572bd7d4a2c368ea9cd (diff)
downloadCompiler-850f46eeb6de286d4b079373104af87e3aca781c.tar.gz
Compiler-850f46eeb6de286d4b079373104af87e3aca781c.zip
Finished functions completely, now moving on to statements
Diffstat (limited to 'c_parser/src')
-rw-r--r--c_parser/src/c_parser.y15
1 files changed, 13 insertions, 2 deletions
diff --git a/c_parser/src/c_parser.y b/c_parser/src/c_parser.y
index bdafa5b..d8396a8 100644
--- a/c_parser/src/c_parser.y
+++ b/c_parser/src/c_parser.y
@@ -26,7 +26,7 @@ void yyerror(const char *);
%type <stmnt> EXT_DEF EXT_DECLARATION
%type <stmnt> FUNC_DEF PARAMETER_LIST PARAMETER PARAM_DECLARATOR
%type <stmnt> DECLARATION_LIST DECLARATION DECLARATION_SPEC DECLARATION_SPEC_T INIT_DECLARATOR INIT_DECLARATOR_LIST DECLARATOR INITIALIZER
-%type <stmnt> COMPOUND_STATEMENT COMPOUND_STATEMENT_2
+%type <stmnt> STATEMENT_LIST STATEMENT COMPOUND_STATEMENT COMPOUND_STATEMENT_2
// %type <number> // T_CONSTANT
%type <string> T_IDENTIFIER //T_OPERATOR
@@ -96,13 +96,24 @@ INITIALIZER : T_INT_CONST { ; }
// STATEMENT
+STATEMENT_LIST : STATEMENT { $$ = new ast_StatementList($1); }
+ | STATEMENT_LIST STATEMENT { $$->push($2); }
+;
+
+STATEMENT : COMPOUND_STATEMENT { $$ = $1; }
+;
+
COMPOUND_STATEMENT : T_LCB COMPOUND_STATEMENT_2 { $$ = $2; }
;
-COMPOUND_STATEMENT_2 : T_RCB { $$ = new ast_CompoundStatement(); }
+COMPOUND_STATEMENT_2 : T_RCB { $$ = new ast_CompoundStatement; }
| DECLARATION_LIST T_RCB { $$ = new ast_CompoundStatement($1); }
+| DECLARATION_LIST STATEMENT_LIST T_RCB { $$ = new ast_CompoundStatement($1, $2); }
+ | STATEMENT_LIST T_RCB { $$ = new ast_CompoundStatement($1); }
;
+// Expressions
+
%%
ast_Top *g_root; // Definition of variable (to match declaration earlier)