AST small changes

devel
Justyna Att Ilczuk 2012-12-03 23:40:47 +01:00
parent 5a0fbd6434
commit 98c33d3ec1
16 changed files with 137 additions and 12 deletions

View File

@ -8,7 +8,7 @@
#include "AllTypesOfASTNodes.h"
AST::AST() {
root = new ASTProgram();
root = new ProgramNode();
current_node = root;
number_of_nodes = 1;
level_of_depth = 0;

View File

@ -9,7 +9,7 @@
#define ALLTYPESOFASTNODES_H_
#include "ASTNode.h"
#include "ASTProgram.h"
#include "ProgramNode.h"
#include "ASTStatement.h"
#include "ASTExpression.h"
#include "ASTPrimary.h"

View File

@ -0,0 +1,32 @@
/*
* IfNode.cpp
*
* Created on: Nov 18, 2012
* Author: attero
*/
#include "IfNode.h"
IfNode::IfNode(ASTNode * parent) {
this->parent = parent;
}
IfNode::~IfNode() {
}
void IfNode::add_condition(ASTExpression * expression)
{
children.push_back(expression);
}
void IfNode::add_body(ASTStatement * statement)
{
children.push_back(statement);
}
void IfNode::add_else_block(ASTStatement * statement)
{
children.push_back(statement);
}

25
Sencha-lang/AST/IfNode.h Normal file
View File

@ -0,0 +1,25 @@
/*
* IfNode.h
*
* Created on: Nov 18, 2012
* Author: attero
*/
#ifndef IFNODE_H_
#define IFNODE_H_
#include "ASTStatement.h"
#include "ASTExpression.h"
class IfNode : public ASTStatement
{
public:
void add_condition(ASTExpression * expression);
void add_body(ASTStatement * statement);
void add_else_block(ASTStatement * statement);
IfNode(ASTNode * parent);
virtual ~IfNode();
};
#endif /* IFNODE_H_ */

View File

@ -0,0 +1,21 @@
/*
* ProgramNode.cpp
*
* Created on: Nov 5, 2012
* Author: attero
*/
#include "ProgramNode.h"
ProgramNode::ProgramNode() {
// TODO Auto-generated constructor stub
}
ProgramNode::~ProgramNode() {
// TODO Auto-generated destructor stub
}
void ProgramNode::execute() {
std::cout << "Program started!\n";
}

View File

@ -0,0 +1,22 @@
/*
* ASTProgram.h
*
* Created on: Nov 5, 2012
* Author: attero
*/
#ifndef PROGRAMNODE_H_
#define PROGRAMNODE_H_
#include <iostream>
#include "ASTNode.h"
#include "ASTStatement.h"
class ProgramNode : public ASTNode {
public:
ProgramNode();
ASTStatement * add_child(ASTStatement * node);
virtual ~ProgramNode();
virtual void execute();
};
#endif /* PROGRAMNODE_H_ */

View File

@ -1,5 +1,5 @@
AST/AST.d: ../AST/AST.cpp ../AST/AST.h ../AST/ASTNode.h \
../AST/AllTypesOfASTNodes.h ../AST/ASTProgram.h ../AST/ASTStatement.h \
../AST/AllTypesOfASTNodes.h ../AST/ProgramNode.h ../AST/ASTStatement.h \
../AST/ASTExpression.h ../AST/ASTPrimary.h
../AST/AST.h:
@ -8,7 +8,7 @@ AST/AST.d: ../AST/AST.cpp ../AST/AST.h ../AST/ASTNode.h \
../AST/AllTypesOfASTNodes.h:
../AST/ASTProgram.h:
../AST/ProgramNode.h:
../AST/ASTStatement.h:

Binary file not shown.

View File

@ -0,0 +1,10 @@
AST/IfNode.d: ../AST/IfNode.cpp ../AST/IfNode.h ../AST/ASTStatement.h \
../AST/ASTNode.h ../AST/ASTExpression.h
../AST/IfNode.h:
../AST/ASTStatement.h:
../AST/ASTNode.h:
../AST/ASTExpression.h:

Binary file not shown.

View File

@ -0,0 +1,8 @@
AST/ProgramNode.d: ../AST/ProgramNode.cpp ../AST/ProgramNode.h \
../AST/ASTNode.h ../AST/ASTStatement.h
../AST/ProgramNode.h:
../AST/ASTNode.h:
../AST/ASTStatement.h:

Binary file not shown.

View File

@ -8,24 +8,27 @@ CPP_SRCS += \
../AST/ASTExpression.cpp \
../AST/ASTNode.cpp \
../AST/ASTPrimary.cpp \
../AST/ASTProgram.cpp \
../AST/ASTStatement.cpp
../AST/ASTStatement.cpp \
../AST/IfNode.cpp \
../AST/ProgramNode.cpp
OBJS += \
./AST/AST.o \
./AST/ASTExpression.o \
./AST/ASTNode.o \
./AST/ASTPrimary.o \
./AST/ASTProgram.o \
./AST/ASTStatement.o
./AST/ASTStatement.o \
./AST/IfNode.o \
./AST/ProgramNode.o
CPP_DEPS += \
./AST/AST.d \
./AST/ASTExpression.d \
./AST/ASTNode.d \
./AST/ASTPrimary.d \
./AST/ASTProgram.d \
./AST/ASTStatement.d
./AST/ASTStatement.d \
./AST/IfNode.d \
./AST/ProgramNode.d
# Each subdirectory must supply rules for building sources it contributes

Binary file not shown.

Binary file not shown.

View File

@ -3,9 +3,10 @@
#include <string>
#include <vector>
#include "Token.h"
#include "../AST/AllTypesOfASTNodes.h"
using namespace std;
class Parser
{
public:
@ -16,7 +17,9 @@ class Parser
string error_message;
void add_tokens(vector<Token> tokens);
string show_tokens();
protected:
private:
Token current_token;
string tok_value;
@ -32,7 +35,8 @@ class Parser
void error(string s);
void report(string s);
//TODO change functions below to use AST nodes
void statement();
void mul_expr();