aboutsummaryrefslogtreecommitdiffstats
path: root/c_parser/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-02-14 14:02:40 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-02-14 14:02:40 +0000
commitec1bd2264a19542b4e36df08ad2dba2c50f437b3 (patch)
tree808dd28f552355f78b92465071c4abacc9935eba /c_parser/src
parent494894c2072494f199214acc5855155baae6d174 (diff)
downloadCompiler-ec1bd2264a19542b4e36df08ad2dba2c50f437b3.tar.gz
Compiler-ec1bd2264a19542b4e36df08ad2dba2c50f437b3.zip
Working vector in parser
Diffstat (limited to 'c_parser/src')
-rw-r--r--c_parser/src/c_parser.y20
-rw-r--r--c_parser/src/parser_main.cpp6
2 files changed, 13 insertions, 13 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;
}
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 <iostream>
int main(int argc, char *argv[]) {
-
- const ast_Base *ast = parseAST();
- ast->print();
+ ast_Top *ast = parseAST();
+
+ ast->print_vec();
std::cout << std::endl;