wtf git
parent
98c33d3ec1
commit
c5cf3e2fc9
|
@ -0,0 +1 @@
|
|||
*.o
|
Binary file not shown.
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
* AST.cpp
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
#include "AST.h"
|
||||
#include "AllTypesOfASTNodes.h"
|
||||
|
||||
AST::AST() {
|
||||
root = new ASTProgram();
|
||||
current_node = root;
|
||||
number_of_nodes = 1;
|
||||
level_of_depth = 0;
|
||||
}
|
||||
|
||||
AST::~AST() {
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* AST.h
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef AST_H_
|
||||
#define AST_H_
|
||||
#include "ASTNode.h"
|
||||
|
||||
class AST {
|
||||
public:
|
||||
AST();
|
||||
ASTNode * root;
|
||||
ASTNode * current_node;
|
||||
int number_of_nodes;
|
||||
int level_of_depth;
|
||||
ASTNode * add_node(ASTNode * node);
|
||||
virtual ~AST();
|
||||
};
|
||||
|
||||
#endif /* AST_H_ */
|
|
@ -7,11 +7,13 @@
|
|||
|
||||
#ifndef ASTEXPRESSION_H_
|
||||
#define ASTEXPRESSION_H_
|
||||
#include <string>
|
||||
#include "ASTNode.h"
|
||||
|
||||
class ASTExpression : public ASTNode {
|
||||
public:
|
||||
ASTExpression();
|
||||
|
||||
virtual int evaluate() = 0;
|
||||
virtual ~ASTExpression();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* ASTProgram.cpp
|
||||
*
|
||||
* Created on: Nov 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "ASTProgram.h"
|
||||
|
||||
ASTProgram::ASTProgram() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
ASTProgram::~ASTProgram() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void ASTProgram::execute() {
|
||||
std::cout << "Program started!\n";
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* ASTProgram.h
|
||||
*
|
||||
* Created on: Nov 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef ASTPROGRAM_H_
|
||||
#define ASTPROGRAM_H_
|
||||
#include <iostream>
|
||||
#include "ASTNode.h"
|
||||
#include "ASTStatement.h"
|
||||
|
||||
class ASTProgram : public ASTNode {
|
||||
public:
|
||||
ASTProgram();
|
||||
ASTStatement * add_child(ASTStatement * node);
|
||||
virtual ~ASTProgram();
|
||||
virtual void execute();
|
||||
};
|
||||
|
||||
#endif /* ASTPROGRAM_H_ */
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* BasicExpression.cpp
|
||||
*
|
||||
* Created on: Dec 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "BasicExpression.h"
|
||||
|
||||
void BasicExpression::set_operator(std::string op)
|
||||
{
|
||||
this->oper = op;
|
||||
}
|
||||
|
||||
void BasicExpression::set_left_operand(ASTNode * left)
|
||||
{
|
||||
this->children[0] = left;
|
||||
this->left = static_cast<ASTExpression *>(children[0]);
|
||||
}
|
||||
|
||||
void BasicExpression::set_right_operand(ASTNode * right)
|
||||
{
|
||||
this->children[1] = right;
|
||||
this->right = static_cast<ASTExpression *>(children[1]);
|
||||
}
|
||||
|
||||
virtual int BasicExpression::evaluate()
|
||||
{
|
||||
if(oper == "+")
|
||||
{
|
||||
return left->evaluate() + right->evaluate();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BasicExpression::BasicExpression() {
|
||||
// initialize pointers
|
||||
this->add_children(0);
|
||||
this->add_children(0);
|
||||
left = static_cast<ASTExpression *>(children[0]);
|
||||
right = static_cast<ASTExpression *>(children[1]);
|
||||
}
|
||||
|
||||
BasicExpression::~BasicExpression() {
|
||||
// TODO Auto-generated destructor stub
|
||||
// TODO free children memory
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* BasicExpression.h
|
||||
*
|
||||
* Created on: Dec 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef BASICEXPRESSION_H_
|
||||
#define BASICEXPRESSION_H_
|
||||
#include "ASTExpression.h"
|
||||
#include <string>
|
||||
|
||||
class BasicExpression : public ASTExpression {
|
||||
public:
|
||||
//TODO change oper to enum
|
||||
std::string oper;
|
||||
ASTExpression * left;
|
||||
ASTExpression * right;
|
||||
|
||||
void set_operator(std::string op);
|
||||
void set_left_operand(ASTNode * left);
|
||||
void set_right_operand(ASTNode * right);
|
||||
virtual int evaluate();
|
||||
|
||||
BasicExpression();
|
||||
virtual ~BasicExpression();
|
||||
};
|
||||
|
||||
#endif /* BASICEXPRESSION_H_ */
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* ConstantExpression.cpp
|
||||
*
|
||||
* Created on: Dec 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "ConstantExpression.h"
|
||||
|
||||
ConstantExpression::ConstantExpression() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
ConstantExpression::~ConstantExpression() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* ConstantExpression.h
|
||||
*
|
||||
* Created on: Dec 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef CONSTANTEXPRESSION_H_
|
||||
#define CONSTANTEXPRESSION_H_
|
||||
#include "ASTExpression.h"
|
||||
|
||||
class ConstantExpression : public ASTExpression {
|
||||
public:
|
||||
ConstantExpression();
|
||||
virtual ~ConstantExpression();
|
||||
virtual int evaluate();
|
||||
};
|
||||
|
||||
#endif /* CONSTANTEXPRESSION_H_ */
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* PostfixExpression.cpp
|
||||
*
|
||||
* Created on: Dec 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "PostfixExpression.h"
|
||||
|
||||
PostfixExpression::PostfixExpression() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
PostfixExpression::~PostfixExpression() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* PostfixExpression.h
|
||||
*
|
||||
* Created on: Dec 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef POSTFIXEXPRESSION_H_
|
||||
#define POSTFIXEXPRESSION_H_
|
||||
|
||||
class PostfixExpression {
|
||||
public:
|
||||
PostfixExpression();
|
||||
virtual ~PostfixExpression();
|
||||
};
|
||||
|
||||
#endif /* POSTFIXEXPRESSION_H_ */
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* ASTExpression.cpp
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "ASTExpression.h"
|
||||
|
||||
ASTExpression::ASTExpression() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
ASTExpression::~ASTExpression() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* ASTExpression.h
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef ASTEXPRESSION_H_
|
||||
#define ASTEXPRESSION_H_
|
||||
#include "ASTNode.h"
|
||||
|
||||
class ASTExpression : public ASTNode {
|
||||
public:
|
||||
ASTExpression();
|
||||
virtual ~ASTExpression();
|
||||
};
|
||||
|
||||
#endif /* ASTEXPRESSION_H_ */
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* ASTNode.cpp
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "ASTNode.h"
|
||||
|
||||
ASTNode::ASTNode() {
|
||||
// TODO Auto-generated constructor stub
|
||||
parent = 0;
|
||||
}
|
||||
|
||||
ASTNode::~ASTNode() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* ASTNode.h
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef ASTNODE_H_
|
||||
#define ASTNODE_H_
|
||||
#include <vector>
|
||||
|
||||
class ASTNode {
|
||||
public:
|
||||
ASTNode();
|
||||
ASTNode * parent;
|
||||
std::vector<ASTNode *> children;
|
||||
void add_children(ASTNode *);
|
||||
void remove_most_right_children();
|
||||
void set_parent(ASTNode *);
|
||||
virtual void execute() = 0;
|
||||
virtual ~ASTNode();
|
||||
};
|
||||
|
||||
#endif /* ASTNODE_H_ */
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* ASTPrimary.cpp
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "ASTPrimary.h"
|
||||
|
||||
ASTPrimary::ASTPrimary(ASTNode * parent) {
|
||||
// TODO Auto-generated constructor stub
|
||||
value = "";
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
ASTPrimary::~ASTPrimary() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* ASTPrimary.h
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef ASTPRIMARY_H_
|
||||
#define ASTPRIMARY_H_
|
||||
#include "ASTNode.h"
|
||||
#include <string>
|
||||
|
||||
class ASTPrimary : public ASTNode {
|
||||
public:
|
||||
ASTPrimary(ASTNode * parent);
|
||||
|
||||
virtual ~ASTPrimary();
|
||||
virtual void execute() {};
|
||||
std::string value;
|
||||
|
||||
};
|
||||
|
||||
#endif /* ASTPRIMARY_H_ */
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* ASTProgram.cpp
|
||||
*
|
||||
* Created on: Nov 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "ASTProgram.h"
|
||||
|
||||
ASTProgram::ASTProgram() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
ASTProgram::~ASTProgram() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void ASTProgram::execute() {
|
||||
std::cout << "Program started!\n";
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* ASTProgram.h
|
||||
*
|
||||
* Created on: Nov 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef ASTPROGRAM_H_
|
||||
#define ASTPROGRAM_H_
|
||||
#include <iostream>
|
||||
#include "ASTNode.h"
|
||||
#include "ASTStatement.h"
|
||||
|
||||
class ASTProgram : public ASTNode {
|
||||
public:
|
||||
ASTProgram();
|
||||
ASTStatement * add_child(ASTStatement * node);
|
||||
virtual ~ASTProgram();
|
||||
virtual void execute();
|
||||
};
|
||||
|
||||
#endif /* ASTPROGRAM_H_ */
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* ASTStatement.cpp
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#include "ASTStatement.h"
|
||||
|
||||
ASTStatement::ASTStatement() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
ASTStatement::~ASTStatement() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* ASTStatement.h
|
||||
*
|
||||
* Created on: Nov 4, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef ASTSTATEMENT_H_
|
||||
#define ASTSTATEMENT_H_
|
||||
#include "ASTNode.h"
|
||||
|
||||
class ASTStatement : public ASTNode {
|
||||
public:
|
||||
ASTStatement();
|
||||
virtual ~ASTStatement();
|
||||
};
|
||||
|
||||
#endif /* ASTSTATEMENT_H_ */
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* AllTypesOfASTNodes.h
|
||||
*
|
||||
* Created on: Nov 5, 2012
|
||||
* Author: attero
|
||||
*/
|
||||
|
||||
#ifndef ALLTYPESOFASTNODES_H_
|
||||
#define ALLTYPESOFASTNODES_H_
|
||||
|
||||
#include "ASTNode.h"
|
||||
#include "ASTProgram.h"
|
||||
#include "ASTStatement.h"
|
||||
#include "ASTExpression.h"
|
||||
#include "ASTPrimary.h"
|
||||
|
||||
//And probably more
|
||||
//TODO actualize it
|
||||
|
||||
#endif /* ALLTYPESOFASTNODES_H_ */
|
Binary file not shown.
|
@ -1,16 +0,0 @@
|
|||
AST.d: ../AST.cpp ../AST.h ../ASTNode.h ../AllTypesOfASTNodes.h \
|
||||
../ASTProgram.h ../ASTStatement.h ../ASTExpression.h ../ASTPrimary.h
|
||||
|
||||
../AST.h:
|
||||
|
||||
../ASTNode.h:
|
||||
|
||||
../AllTypesOfASTNodes.h:
|
||||
|
||||
../ASTProgram.h:
|
||||
|
||||
../ASTStatement.h:
|
||||
|
||||
../ASTExpression.h:
|
||||
|
||||
../ASTPrimary.h:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,8 +0,0 @@
|
|||
AST/ASTProgram.d: ../AST/ASTProgram.cpp ../AST/ASTProgram.h \
|
||||
../AST/ASTNode.h ../AST/ASTStatement.h
|
||||
|
||||
../AST/ASTProgram.h:
|
||||
|
||||
../AST/ASTNode.h:
|
||||
|
||||
../AST/ASTStatement.h:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,5 +0,0 @@
|
|||
ASTExpression.d: ../ASTExpression.cpp ../ASTExpression.h ../ASTNode.h
|
||||
|
||||
../ASTExpression.h:
|
||||
|
||||
../ASTNode.h:
|
Binary file not shown.
|
@ -1,3 +0,0 @@
|
|||
ASTNode.d: ../ASTNode.cpp ../ASTNode.h
|
||||
|
||||
../ASTNode.h:
|
Binary file not shown.
|
@ -1,5 +0,0 @@
|
|||
ASTPrimary.d: ../ASTPrimary.cpp ../ASTPrimary.h ../ASTNode.h
|
||||
|
||||
../ASTPrimary.h:
|
||||
|
||||
../ASTNode.h:
|
Binary file not shown.
|
@ -1,8 +0,0 @@
|
|||
ASTProgram.d: ../ASTProgram.cpp ../ASTProgram.h ../ASTNode.h \
|
||||
../ASTStatement.h
|
||||
|
||||
../ASTProgram.h:
|
||||
|
||||
../ASTNode.h:
|
||||
|
||||
../ASTStatement.h:
|
Binary file not shown.
|
@ -1,5 +0,0 @@
|
|||
ASTStatement.d: ../ASTStatement.cpp ../ASTStatement.h ../ASTNode.h
|
||||
|
||||
../ASTStatement.h:
|
||||
|
||||
../ASTNode.h:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -37,15 +37,15 @@ class Parser
|
|||
void report(string s);
|
||||
|
||||
//TODO change functions below to use AST nodes
|
||||
void statement();
|
||||
ASTNode * statement(ASTNode * node);
|
||||
|
||||
void mul_expr();
|
||||
void add_expr();
|
||||
void prim_expr();
|
||||
void postfix_expr();
|
||||
void rel_expr();
|
||||
void eq_expr();
|
||||
void expr();
|
||||
ASTNode * mul_expr(ASTNode * node);
|
||||
ASTNode * add_expr(ASTNode * node);
|
||||
ASTNode * prim_expr(ASTNode * node);
|
||||
ASTNode * postfix_expr(ASTNode * node);
|
||||
ASTNode * rel_expr(ASTNode * node);
|
||||
ASTNode * eq_expr(ASTNode * node);
|
||||
ASTNode * expr(ASTNode * node);
|
||||
};
|
||||
|
||||
#endif // PARSER_H
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue