From ec1bd2264a19542b4e36df08ad2dba2c50f437b3 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Tue, 14 Feb 2017 14:02:40 +0000 Subject: Working vector in parser --- c_parser/src/c_parser.y | 20 ++++++++++---------- c_parser/src/parser_main.cpp | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'c_parser/src') 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 STMNT_LIST STMNT DCLRTN // COMP_STMNT EXPR_STMNT SLCT_STMNT ITR_STMNT JMP_STMNT +%type STMNT DCLRTN STMNT_LIST // COMP_STMNT STMNT_LIST_STMNT SLCT_STMNT ITR_STMNT JMP_STMNT // %type // T_CONSTANT %type 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; } diff --git a/c_parser/src/parser_main.cpp b/c_parser/src/parser_main.cpp index 4dd25eb..53209e3 100644 --- a/c_parser/src/parser_main.cpp +++ b/c_parser/src/parser_main.cpp @@ -3,9 +3,9 @@ #include int main(int argc, char *argv[]) { - - const ast_Base *ast = parseAST(); - ast->print(); + ast_Top *ast = parseAST(); + + ast->print_vec(); std::cout << std::endl; -- cgit