some refactoring in basic structure of AST, mainly destructors

functions
Justyna Ilczuk 2012-12-17 09:25:58 +01:00
parent cc0a923959
commit 3ff8c49cb7
17 changed files with 1863 additions and 100 deletions

View File

@ -16,10 +16,7 @@ public:
ASTNode();
ASTNode * parent;
std::vector<ASTNode *> children;
void add_children(ASTNode *);
void remove_most_right_children();
void set_parent(ASTNode *);
bool evaluate_condition();
virtual std::string debug() = 0;
virtual void execute() = 0;

View File

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

View File

@ -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_ */

View File

@ -76,6 +76,10 @@ Assignment::Assignment(ASTNode * parent, Context * context)
Assignment::~Assignment() {
// TODO Auto-generated destructor stub
for(auto it = children.begin(); it != children.end(); )
{
delete *it;
it = children.erase(it);
}
}

View File

@ -10,7 +10,15 @@
DeclarationStatement::~DeclarationStatement() {
// TODO Auto-generated destructor stub
if(is_function)
{
delete body;
}
for(auto it = children.begin(); it != children.end(); )
{
delete *it;
it = children.erase(it);
}
}
void DeclarationStatement::add_right_value(ASTExpression * right)

View File

@ -31,7 +31,11 @@ bool IfNode::evaluate_condition()
}
IfNode::~IfNode() {
for(auto it = children.begin(); it != children.end(); )
{
delete *it;
it = children.erase(it);
}
}
void IfNode::add_condition(ASTExpression * expression)

View File

@ -14,7 +14,7 @@ IncorrectExpression::IncorrectExpression(ASTNode * parent, std::string error_mes
}
IncorrectExpression::~IncorrectExpression() {
// TODO Auto-generated destructor stub
// do nothing
}
SenchaObject IncorrectExpression::evaluate()

View File

@ -1,18 +0,0 @@
/*
* LogicalExpression.cpp
*
* Created on: Dec 8, 2012
* Author: attero
*/
#include "LogicalExpression.h"
LogicalExpression::LogicalExpression() {
// TODO Auto-generated constructor stub
}
LogicalExpression::~LogicalExpression() {
// TODO Auto-generated destructor stub
}

View File

@ -1,19 +0,0 @@
/*
* LogicalExpression.h
*
* Created on: Dec 8, 2012
* Author: attero
*/
#ifndef LOGICALEXPRESSION_H_
#define LOGICALEXPRESSION_H_
#include "ASTExpression.h"
class LogicalExpression: public ASTExpression {
public:
LogicalExpression();
virtual ~LogicalExpression();
};
#endif /* LOGICALEXPRESSION_H_ */

View File

@ -15,7 +15,11 @@ PostfixExpression::PostfixExpression(ASTNode * parent, Context * context) {
}
PostfixExpression::~PostfixExpression() {
// TODO Auto-generated destructor stub
for(auto i = arguments.begin(); i != arguments.end();)
{
delete *i;
i = arguments.erase(i);
}
}
@ -44,5 +48,6 @@ void PostfixExpression::execute() {
std::string PostfixExpression::debug()
{
//TODO implement it or something
return "Postfix expression tadadah!";
}

View File

@ -22,7 +22,7 @@ public:
virtual SenchaObject evaluate();
virtual void execute();
virtual void execute_quietly(){//do nothing
virtual void execute_quietly(){ execute();
};

View File

@ -13,13 +13,17 @@ ProgramNode::ProgramNode() {
}
ProgramNode::~ProgramNode() {
// TODO Auto-generated destructor stub
for(auto it = children.begin(); it != children.end(); )
{
delete *it;
it = children.erase(it);
}
}
void ProgramNode::execute() {
for (std::vector<ASTNode *>::iterator it = children.begin(); it!=children.end(); ++it) {
(*it)->execute();
}
(*it)->execute();
}
}
void ProgramNode::execute_last()

View File

@ -16,7 +16,7 @@ RepeatStatement::RepeatStatement(ASTNode * parent)
RepeatStatement::~RepeatStatement()
{
delete body;
}
void RepeatStatement::execute()

View File

@ -8,13 +8,17 @@
#include "WhileNode.h"
WhileNode::WhileNode(ASTNode * parent) {
// TODO Auto-generated constructor stub
body = NULL;
this->parent = parent;
}
WhileNode::~WhileNode() {
// TODO Auto-generated destructor stub
delete body;
for(auto it = children.begin(); it != children.end(); )
{
delete *it;
it = children.erase(it);
}
}
void WhileNode::add_condition(ASTExpression * expression)

View File

@ -40,7 +40,6 @@ std::string Lexer::unescape_string(string text)
case '[':
replacement = 27;
break;
}
}
@ -50,10 +49,8 @@ std::string Lexer::unescape_string(string text)
replacement_chars[0] = replacement;
replacement_chars[1] = 0;
std::cout << result << " escaping..." << replacement_chars << std::endl;
result.replace(i + offset, 2, replacement_chars);
offset--;
std::cout << result << " escaped..." << std::endl;
}

View File

@ -10,6 +10,18 @@
using namespace std;
/*TODO
* Known bugs:
*
* >> print("I like bananas", dupa");
I like bananasnull
Context: 0: dupa"); type: null
null
dupa"); declaration? hello?
*/
SenchaObject print(vector<ASTExpression *> arguments)
{
for (auto argument: arguments)

1808
Sencha-lang/sencha Normal file

File diff suppressed because it is too large Load Diff