Prepare PrintVisitor
This commit is contained in:
@@ -70,6 +70,7 @@ SET(SCULLY_SOURCE
|
|||||||
src/AST/FunctionDefinition.cpp
|
src/AST/FunctionDefinition.cpp
|
||||||
src/AST/IfStatement.cpp
|
src/AST/IfStatement.cpp
|
||||||
src/AST/ParameterList.cpp
|
src/AST/ParameterList.cpp
|
||||||
|
src/AST/PrintVisitor.cpp
|
||||||
src/AST/ReturnStatement.cpp
|
src/AST/ReturnStatement.cpp
|
||||||
src/AST/RandomForStatement.cpp
|
src/AST/RandomForStatement.cpp
|
||||||
src/AST/RandomIfStatement.cpp
|
src/AST/RandomIfStatement.cpp
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
#include "AST/FunctionDefinition.h"
|
#include "AST/FunctionDefinition.h"
|
||||||
#include "AST/IfStatement.h"
|
#include "AST/IfStatement.h"
|
||||||
#include "AST/ParameterList.h"
|
#include "AST/ParameterList.h"
|
||||||
//#include "AST/RandomForStatement.h"
|
#include "AST/PrintVisitor.h"
|
||||||
|
#include "AST/RandomForStatement.h"
|
||||||
#include "AST/RandomIfStatement.h"
|
#include "AST/RandomIfStatement.h"
|
||||||
#include "AST/ReturnStatement.h"
|
#include "AST/ReturnStatement.h"
|
||||||
#include "AST/Scope.h"
|
#include "AST/Scope.h"
|
||||||
@@ -52,8 +53,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
%type program {int}
|
%type program {int}
|
||||||
program ::= fundef(F). { std::cout << F << std::endl; }
|
program ::= fundef(F). { PrintVisitor* pv = new PrintVisitor; F->accept(pv); delete pv; }
|
||||||
program ::= expr(E). { std::cout << E << std::endl; }
|
program ::= expr(E). { PrintVisitor* pv = new PrintVisitor; E->accept(pv); delete pv; }
|
||||||
|
|
||||||
%type fundef {FunctionDefinition*}
|
%type fundef {FunctionDefinition*}
|
||||||
fundef(A) ::= type(T) T_IDENTIFIER(ID) T_LPAREN params(P) T_RPAREN T_BEGIN statements(S) T_END.
|
fundef(A) ::= type(T) T_IDENTIFIER(ID) T_LPAREN params(P) T_RPAREN T_BEGIN statements(S) T_END.
|
||||||
@@ -79,7 +80,7 @@ statement(A) ::= T_RIF T_LPAREN expr(P) T_RPAREN statement(S).
|
|||||||
statement(A) ::= T_FOR T_LPAREN expr(INIT) T_SEMICOLON expr(COND) T_SEMICOLON expr(STEP) T_RPAREN statement(S).
|
statement(A) ::= T_FOR T_LPAREN expr(INIT) T_SEMICOLON expr(COND) T_SEMICOLON expr(STEP) T_RPAREN statement(S).
|
||||||
{ A = new ForStatement(INIT, COND, STEP, S); }
|
{ A = new ForStatement(INIT, COND, STEP, S); }
|
||||||
statement(A) ::= T_RFOR T_LPAREN expr(INIT) T_SEMICOLON expr(P) T_SEMICOLON expr(STEP) T_RPAREN statement(S).
|
statement(A) ::= T_RFOR T_LPAREN expr(INIT) T_SEMICOLON expr(P) T_SEMICOLON expr(STEP) T_RPAREN statement(S).
|
||||||
{ A = 0; /* new RandomForStatement(INIT, P, STEP, S); */ }
|
{ A = new RandomForStatement(INIT, P, STEP, S); }
|
||||||
statement(A) ::= T_RETURN expr(E) T_SEMICOLON. { A = new ReturnStatement(E); }
|
statement(A) ::= T_RETURN expr(E) T_SEMICOLON. { A = new ReturnStatement(E); }
|
||||||
statement(A) ::= T_BEGIN statements(S) T_END. { A = new Scope(S); }
|
statement(A) ::= T_BEGIN statements(S) T_END. { A = new Scope(S); }
|
||||||
statement(A) ::= vardef(V) T_SEMICOLON. { A = V; }
|
statement(A) ::= vardef(V) T_SEMICOLON. { A = V; }
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ public:
|
|||||||
virtual void visit(StatementList* e) = 0;
|
virtual void visit(StatementList* e) = 0;
|
||||||
virtual void visit(ValueList* e) = 0;
|
virtual void visit(ValueList* e) = 0;
|
||||||
virtual void visit(VariableDefinition* e) = 0;
|
virtual void visit(VariableDefinition* e) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ASTVISITOR_H
|
#endif // ASTVISITOR_H
|
||||||
|
|||||||
29
inc/AST/PrintVisitor.h
Normal file
29
inc/AST/PrintVisitor.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef PRINTVISITOR_H
|
||||||
|
#define PRINTVISITOR_H
|
||||||
|
|
||||||
|
#include "ASTVisitor.h"
|
||||||
|
|
||||||
|
class PrintVisitor : public ASTVisitor {
|
||||||
|
public:
|
||||||
|
PrintVisitor();
|
||||||
|
virtual ~PrintVisitor();
|
||||||
|
|
||||||
|
virtual void visit(AssignmentExpression* e);
|
||||||
|
virtual void visit(BinOpExpression* e);
|
||||||
|
virtual void visit(ConstantExpression* e);
|
||||||
|
virtual void visit(ExpressionStatement* e);
|
||||||
|
virtual void visit(ForStatement* e);
|
||||||
|
virtual void visit(FunctionCallExpression* e);
|
||||||
|
virtual void visit(FunctionDefinition* e);
|
||||||
|
virtual void visit(IfStatement* e);
|
||||||
|
virtual void visit(ParameterList* e);
|
||||||
|
virtual void visit(RandomForStatement* e);
|
||||||
|
virtual void visit(RandomIfStatement* e);
|
||||||
|
virtual void visit(ReturnStatement* e);
|
||||||
|
virtual void visit(Scope* e);
|
||||||
|
virtual void visit(StatementList* e);
|
||||||
|
virtual void visit(ValueList* e);
|
||||||
|
virtual void visit(VariableDefinition* e);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PRINTVISITOR_H
|
||||||
73
src/AST/PrintVisitor.cpp
Normal file
73
src/AST/PrintVisitor.cpp
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#include "AST/PrintVisitor.h"
|
||||||
|
|
||||||
|
PrintVisitor::PrintVisitor() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintVisitor::~PrintVisitor() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(AssignmentExpression* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(BinOpExpression* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(ConstantExpression* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(ExpressionStatement* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(ForStatement* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(FunctionCallExpression* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(FunctionDefinition* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(IfStatement* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(ParameterList* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(RandomForStatement* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(RandomIfStatement* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(ReturnStatement* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(Scope* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(StatementList* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(ValueList* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintVisitor::visit(VariableDefinition* e) {
|
||||||
|
// TODO implement
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user