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

View File

@@ -4,21 +4,20 @@
#include <string>
#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_;
};

View File

@@ -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_;
}

View File

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