Merge branch 'master' of git.tuxzone.org:woc2013
This commit is contained in:
@@ -66,10 +66,12 @@ SET(SCULLY_SOURCE
|
||||
src/AST/Expression.cpp
|
||||
src/AST/ExpressionStatement.cpp
|
||||
src/AST/ForStatement.cpp
|
||||
src/AST/FunctionCallExpression.cpp
|
||||
src/AST/FunctionDefinition.cpp
|
||||
src/AST/IfStatement.cpp
|
||||
src/AST/ParameterList.cpp
|
||||
src/AST/ReturnStatement.cpp
|
||||
src/AST/RandomForStatement.cpp
|
||||
src/AST/RandomIfStatement.cpp
|
||||
src/AST/Scope.cpp
|
||||
src/AST/Statement.cpp
|
||||
@@ -77,7 +79,6 @@ SET(SCULLY_SOURCE
|
||||
src/AST/Type.cpp
|
||||
src/AST/VariableDefinition.cpp
|
||||
src/AST/ValueList.cpp
|
||||
src/AST/FunctionCallExpression.cpp
|
||||
|
||||
${CMAKE_CURRENT_BINARY_DIR}/grammar.cpp
|
||||
)
|
||||
|
||||
@@ -14,9 +14,11 @@
|
||||
#include "AST/Expression.h"
|
||||
#include "AST/ExpressionStatement.h"
|
||||
#include "AST/ForStatement.h"
|
||||
#include "AST/FunctionCallExpression.h"
|
||||
#include "AST/FunctionDefinition.h"
|
||||
#include "AST/IfStatement.h"
|
||||
#include "AST/ParameterList.h"
|
||||
//#include "AST/RandomForStatement.h"
|
||||
#include "AST/RandomIfStatement.h"
|
||||
#include "AST/ReturnStatement.h"
|
||||
#include "AST/Scope.h"
|
||||
@@ -77,7 +79,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).
|
||||
{ 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).
|
||||
{ A = 0; /* INIT P STEP S */ }
|
||||
{ A = 0; /* new RandomForStatement(INIT, P, STEP, S); */ }
|
||||
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) ::= vardef(V) T_SEMICOLON. { A = V; }
|
||||
@@ -99,7 +101,7 @@ expr(A) ::= T_CINT(I). { A = new ConstantExpression(I->getText()); }
|
||||
expr(A) ::= T_TRUE. { A = new ConstantExpression("true"); }
|
||||
expr(A) ::= T_FALSE. { A = new ConstantExpression("false"); }
|
||||
expr(A) ::= T_IDENTIFIER(ID) T_LPAREN values(V) T_RPAREN.
|
||||
{ A = 0; /* ID V */ }
|
||||
{ A = new FunctionCallExpression(ID->getText(), V); }
|
||||
|
||||
%type vardef {VariableDefinition*}
|
||||
vardef(A) ::= type(T) T_IDENTIFIER(ID). { A = new VariableDefinition(T, ID->getText()); }
|
||||
|
||||
@@ -6,16 +6,17 @@
|
||||
#include "ConstantExpression.h"
|
||||
#include "ExpressionStatement.h"
|
||||
#include "ForStatement.h"
|
||||
#include "FunctionCallExpression.h"
|
||||
#include "FunctionDefinition.h"
|
||||
#include "IfStatement.h"
|
||||
#include "ParameterList.h"
|
||||
#include "RandomForStatement.h"
|
||||
#include "RandomIfStatement.h"
|
||||
#include "ReturnStatement.h"
|
||||
#include "Scope.h"
|
||||
#include "StatementList.h"
|
||||
#include "ValueList.h"
|
||||
#include "VariableDefinition.h"
|
||||
#include "FunctionCallExpression.h"
|
||||
|
||||
|
||||
class ASTVisitor {
|
||||
@@ -28,16 +29,17 @@ public:
|
||||
virtual void visit(ConstantExpression* e) = 0;
|
||||
virtual void visit(ExpressionStatement* e) = 0;
|
||||
virtual void visit(ForStatement* e) = 0;
|
||||
virtual void visit(FunctionCallExpression* e) = 0;
|
||||
virtual void visit(FunctionDefinition* e) = 0;
|
||||
virtual void visit(IfStatement* e) = 0;
|
||||
virtual void visit(ParameterList* e) = 0;
|
||||
virtual void visit(RandomForStatement* e) = 0;
|
||||
virtual void visit(RandomIfStatement* e) = 0;
|
||||
virtual void visit(ReturnStatement* e) = 0;
|
||||
virtual void visit(Scope* e) = 0;
|
||||
virtual void visit(StatementList* e) = 0;
|
||||
virtual void visit(ValueList* e) = 0;
|
||||
virtual void visit(VariableDefinition* e) = 0;
|
||||
virtual void visit(FunctionCallExpression* e) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
Expression* getInit();
|
||||
Expression* getCond();
|
||||
Expression* getStep();
|
||||
Statement* GetStmt();
|
||||
Statement* getStmt();
|
||||
private:
|
||||
Expression* init_;
|
||||
Expression* cond_;
|
||||
|
||||
26
inc/AST/RandomForStatement.h
Normal file
26
inc/AST/RandomForStatement.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef RANDOMFORSTATEMENT_H
|
||||
#define RANDOMFORSTATEMENT_H
|
||||
|
||||
#include "AST/Expression.h"
|
||||
#include "AST/Statement.h"
|
||||
|
||||
class RandomForStatement : public Statement
|
||||
{
|
||||
public:
|
||||
RandomForStatement(Expression* init, Expression* prob, Expression* step, Statement* stmt);
|
||||
virtual ~RandomForStatement();
|
||||
|
||||
virtual void accept(ASTVisitor *visitor);
|
||||
|
||||
Expression* getInit();
|
||||
Expression* getProb();
|
||||
Expression* getStep();
|
||||
Statement* getStmt();
|
||||
private:
|
||||
Expression* init_;
|
||||
Expression* prob_;
|
||||
Expression* step_;
|
||||
Statement* stmt_;
|
||||
};
|
||||
|
||||
#endif // RANDOMFORSTATEMENT_H
|
||||
@@ -25,6 +25,6 @@ Expression* ForStatement::getStep() {
|
||||
return step_;
|
||||
}
|
||||
|
||||
Statement* ForStatement::GetStmt() {
|
||||
Statement* ForStatement::getStmt() {
|
||||
return stmt_;
|
||||
}
|
||||
|
||||
32
src/AST/RandomForStatement.cpp
Normal file
32
src/AST/RandomForStatement.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "AST/RandomForStatement.h"
|
||||
#include "AST/ASTVisitor.h"
|
||||
|
||||
RandomForStatement::RandomForStatement(Expression *init, Expression *prob, Expression *step, Statement *stmt) : init_(init),prob_(prob),step_(step),stmt_(stmt)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
RandomForStatement::~RandomForStatement() {
|
||||
//
|
||||
}
|
||||
|
||||
void RandomForStatement::accept(ASTVisitor *visitor) {
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
Expression* RandomForStatement::getInit() {
|
||||
return init_;
|
||||
}
|
||||
|
||||
Expression* RandomForStatement::getProb() {
|
||||
return prob_;
|
||||
}
|
||||
|
||||
Expression* RandomForStatement::getStep() {
|
||||
return step_;
|
||||
}
|
||||
|
||||
Statement* RandomForStatement::getStmt() {
|
||||
return stmt_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user