From a6f0c9ec8199513e5b6a697dc6f57b0a3c21e430 Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Sat, 1 Jun 2013 00:43:30 +0200 Subject: [PATCH] Use Type in VariableDefinition --- grammar/grammar.y | 8 ++++---- inc/AST/VariableDefinition.h | 9 ++++----- src/AST/VariableDefinition.cpp | 4 ++-- src/test.cpp | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/grammar/grammar.y b/grammar/grammar.y index 227d46c..a65cd0f 100644 --- a/grammar/grammar.y +++ b/grammar/grammar.y @@ -38,7 +38,7 @@ %type program {int} program ::= fundefs(F). { std::cout << F << std::endl; } -//program ::= expr(E). { std::cout << E << std::endl; } +program ::= expr(E). { std::cout << E << std::endl; } %type fundefs {int} fundefs(A) ::= . { A = 0; } @@ -67,7 +67,7 @@ statement(A) ::= T_RFOR T_LPAREN expr(INIT) T_SEMICOLON T_CINT(P) T_SEMICOLON ex { A = INIT + 1 + STEP + S; /* P */ } statement(A) ::= T_RETURN expr(E) T_SEMICOLON. { A = E; } statement(A) ::= T_BEGIN statements(S) T_END. { A = S; } -statement(A) ::= vardef(V) T_SEMICOLON. { A = V; } +statement(A) ::= vardef(V) T_SEMICOLON. { A = 1; /* V */ } statement(A) ::= expr(E) T_SEMICOLON. { A = E; } %type statements {int} @@ -87,8 +87,8 @@ expr(A) ::= T_TRUE. { A = 1; } expr(A) ::= T_FALSE. { A = 1; } expr(A) ::= T_IDENTIFIER(ID) T_LPAREN values(V) T_RPAREN. { A = 1 + V; /* ID */ } -%type vardef {int} -vardef(A) ::= type(T) T_IDENTIFIER(ID). { A = 1 + 1; /* T ID */ } +%type vardef {VariableDefinition*} +vardef(A) ::= type(T) T_IDENTIFIER(ID). { A = new VariableDefinition(T, ID->getText()); } %type values {int} values(A) ::= . { A = 0; } diff --git a/inc/AST/VariableDefinition.h b/inc/AST/VariableDefinition.h index 5c3041b..338428c 100644 --- a/inc/AST/VariableDefinition.h +++ b/inc/AST/VariableDefinition.h @@ -4,21 +4,20 @@ #include #include "AST/Statement.h" +#include "AST/Type.h" class VariableDefinition : public Statement { public: - VariableDefinition(int type, std::string name); + VariableDefinition(Type *type, std::string name); virtual ~VariableDefinition(); virtual void accept(ASTVisitor* visitor); - // Type* getType(); - int getType(); + Type* getType(); std::string getName(); private: - // Type* type_ - int type_; + Type* type_; std::string name_; }; diff --git a/src/AST/VariableDefinition.cpp b/src/AST/VariableDefinition.cpp index b47e85b..281704b 100644 --- a/src/AST/VariableDefinition.cpp +++ b/src/AST/VariableDefinition.cpp @@ -1,7 +1,7 @@ #include "AST/VariableDefinition.h" #include "AST/ASTVisitor.h" -VariableDefinition::VariableDefinition(int type, std::string name) : type_(type), name_(name) { +VariableDefinition::VariableDefinition(Type* type, std::string name) : type_(type), name_(name) { // } @@ -13,7 +13,7 @@ void VariableDefinition::accept(ASTVisitor* visitor) { visitor->visit(this); } -int VariableDefinition::getType() { +Type* VariableDefinition::getType() { return type_; } diff --git a/src/test.cpp b/src/test.cpp index 9f3a759..c3575da 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -59,7 +59,7 @@ int main() { lexertl::generator::build(rules, state_machine); state_machine.minimise(); - std::cout << "The scully programming languae v0.1" << std::endl; + std::cout << "The scully programming language v0.1" << std::endl; void* parser = scullyParserAlloc(malloc);