aboutsummaryrefslogtreecommitdiffstats
path: root/c_parser/src/c_parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'c_parser/src/c_parser.y')
-rw-r--r--c_parser/src/c_parser.y20
1 files changed, 10 insertions, 10 deletions
diff --git a/c_parser/src/c_parser.y b/c_parser/src/c_parser.y
index 351cbf2..ae80446 100644
--- a/c_parser/src/c_parser.y
+++ b/c_parser/src/c_parser.y
@@ -1,7 +1,7 @@
%code requires{
#include "ast.hpp"
-extern const ast_Base *g_root; // A way of getting the AST out
+extern ast_Top *g_root; // A way of getting the AST out
//! This is to fix problems when generating C++
// We are declaring the functions provided by Flex, so
@@ -14,14 +14,14 @@ void yyerror(const char *);
// Represents the value associated with any kind of
// AST node.
%union{
- const ast_Base *expr;
+ const ast_Base *stmnt;
// double number;
std::string *string;
}
-%token T_KEYWORD T_IDENTIFIER T_SC //T_CONSTANT T_OPERATOR T_LCBRACKET T_RCBRACKET
+%token T_KEYWORD T_IDENTIFIER T_SC //T_CONSTANT T_OPERATOR T_LCBRACKET T_RCBRACKET
-%type <expr> STMNT_LIST STMNT DCLRTN // COMP_STMNT EXPR_STMNT SLCT_STMNT ITR_STMNT JMP_STMNT
+%type <stmnt> STMNT DCLRTN STMNT_LIST // COMP_STMNT STMNT_LIST_STMNT SLCT_STMNT ITR_STMNT JMP_STMNT
// %type <number> // T_CONSTANT
%type <string> T_KEYWORD T_IDENTIFIER //T_OPERATOR
@@ -29,10 +29,10 @@ void yyerror(const char *);
%%
-ROOT : STMNT_LIST { g_root = $1; }
+ROOT : STMNT_LIST { ; }
-STMNT_LIST : STMNT { $$ = $1; }
- | STMNT_LIST STMNT { $$ = $2; }
+STMNT_LIST : STMNT { g_root->push_back($1); }
+ | STMNT_LIST STMNT { g_root->push_back($2); }
STMNT : DCLRTN { $$ = $1; }
@@ -40,10 +40,10 @@ DCLRTN : T_KEYWORD T_IDENTIFIER T_SC { $$ = new ast_Declaration(*$2); }
%%
-const ast_Base *g_root; // Definition of variable (to match declaration earlier)
+ast_Top *g_root; // Definition of variable (to match declaration earlier)
-const ast_Base *parseAST() {
- g_root = 0;
+ast_Top *parseAST() {
+ g_root = new ast_Top;
yyparse();
return g_root;
}