Use Type in VariableDefinition

This commit is contained in:
Markus Hauschild
2013-06-01 00:43:30 +02:00
parent e2ab5af964
commit a6f0c9ec81
4 changed files with 11 additions and 12 deletions

View File

@@ -38,7 +38,7 @@
%type program {int} %type program {int}
program ::= fundefs(F). { std::cout << F << std::endl; } 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} %type fundefs {int}
fundefs(A) ::= . { A = 0; } 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 */ } { A = INIT + 1 + STEP + S; /* P */ }
statement(A) ::= T_RETURN expr(E) T_SEMICOLON. { A = E; } statement(A) ::= T_RETURN expr(E) T_SEMICOLON. { A = E; }
statement(A) ::= T_BEGIN statements(S) T_END. { A = S; } 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; } statement(A) ::= expr(E) T_SEMICOLON. { A = E; }
%type statements {int} %type statements {int}
@@ -87,8 +87,8 @@ expr(A) ::= T_TRUE. { A = 1; }
expr(A) ::= T_FALSE. { A = 1; } expr(A) ::= T_FALSE. { A = 1; }
expr(A) ::= T_IDENTIFIER(ID) T_LPAREN values(V) T_RPAREN. { A = 1 + V; /* ID */ } expr(A) ::= T_IDENTIFIER(ID) T_LPAREN values(V) T_RPAREN. { A = 1 + V; /* ID */ }
%type vardef {int} %type vardef {VariableDefinition*}
vardef(A) ::= type(T) T_IDENTIFIER(ID). { A = 1 + 1; /* T ID */ } vardef(A) ::= type(T) T_IDENTIFIER(ID). { A = new VariableDefinition(T, ID->getText()); }
%type values {int} %type values {int}
values(A) ::= . { A = 0; } values(A) ::= . { A = 0; }

View File

@@ -4,21 +4,20 @@
#include <string> #include <string>
#include "AST/Statement.h" #include "AST/Statement.h"
#include "AST/Type.h"
class VariableDefinition : public Statement class VariableDefinition : public Statement
{ {
public: public:
VariableDefinition(int type, std::string name); VariableDefinition(Type *type, std::string name);
virtual ~VariableDefinition(); virtual ~VariableDefinition();
virtual void accept(ASTVisitor* visitor); virtual void accept(ASTVisitor* visitor);
// Type* getType(); Type* getType();
int getType();
std::string getName(); std::string getName();
private: private:
// Type* type_ Type* type_;
int type_;
std::string name_; std::string name_;
}; };

View File

@@ -1,7 +1,7 @@
#include "AST/VariableDefinition.h" #include "AST/VariableDefinition.h"
#include "AST/ASTVisitor.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); visitor->visit(this);
} }
int VariableDefinition::getType() { Type* VariableDefinition::getType() {
return type_; return type_;
} }

View File

@@ -59,7 +59,7 @@ int main() {
lexertl::generator::build(rules, state_machine); lexertl::generator::build(rules, state_machine);
state_machine.minimise(); 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); void* parser = scullyParserAlloc(malloc);