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)); }