From b45834151bd6621fd39088894f43a1eb34c59a21 Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Sat, 1 Jun 2013 01:53:15 +0200 Subject: [PATCH] Prepare for StatementList --- grammar/grammar.y | 7 ++++--- src/AST/ParameterList.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/grammar/grammar.y b/grammar/grammar.y index a3b4088..64e70db 100644 --- a/grammar/grammar.y +++ b/grammar/grammar.y @@ -14,6 +14,7 @@ #include "AST/Expression.h" #include "AST/ParameterList.h" #include "AST/Statement.h" +#include "AST/StatementList.h" #include "AST/Type.h" #include "AST/VariableDefinition.h" @@ -74,9 +75,9 @@ statement(A) ::= T_BEGIN statements(S) T_END. { A = S; } statement(A) ::= vardef(V) T_SEMICOLON. { A = 1; /* V */ } statement(A) ::= expr(E) T_SEMICOLON. { A = 1; /* E */ } -%type statements {int} -statements(A) ::= . { A = 0; } -statements(A) ::= statements(B) statement(C). { A = B + C; } +%type statements {StatementList*} +statements(A) ::= . { A = new StatementList(); } +statements(A) ::= statements(B) statement(C). { B->addStatement(C); A = B; } %type expr {Expression*} expr(A) ::= T_IDENTIFIER(ID) T_ASSIGN expr(E). { A = new AssignmentExpression(ID->getText(), E); } diff --git a/src/AST/ParameterList.cpp b/src/AST/ParameterList.cpp index de07112..4501e89 100644 --- a/src/AST/ParameterList.cpp +++ b/src/AST/ParameterList.cpp @@ -15,7 +15,7 @@ void ParameterList::accept(ASTVisitor* visitor) { } void ParameterList::addParameter(Type* type, std::string name) { - std::cout << "added parameter of type" << type->getName() << " and name " << name << std::endl; + std::cout << "added parameter of type " << type->getName() << " and name " << name << std::endl; params_.push_back(Parameter(type, name)); }