diff options
author | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-28 11:01:48 +0100 |
---|---|---|
committer | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-28 11:01:48 +0100 |
commit | 77399daf66a8768258de9b38f945804691bc9a40 (patch) | |
tree | 1fa33313bfd1bd34f9176c78041c858635df0f00 /Sencha-lang | |
parent | 4bbba3bdc93f5647b243d48a97fe299cb1bad5e4 (diff) | |
download | sencha-lang-77399daf66a8768258de9b38f945804691bc9a40.tar.gz sencha-lang-77399daf66a8768258de9b38f945804691bc9a40.tar.bz2 sencha-lang-77399daf66a8768258de9b38f945804691bc9a40.tar.xz sencha-lang-77399daf66a8768258de9b38f945804691bc9a40.zip |
Old, outdated part of project has been removed.
I added some comments to BasicExpression
I removed "parent" from all ASTClasses. Why? It wasn't useful at all,
and it make my design much better and easier to improve later.
Diffstat (limited to 'Sencha-lang')
29 files changed, 117 insertions, 141 deletions
diff --git a/Sencha-lang/AST/ASTExpression.cpp b/Sencha-lang/AST/ASTExpression.cpp index 72ba75b..b9a8d15 100644 --- a/Sencha-lang/AST/ASTExpression.cpp +++ b/Sencha-lang/AST/ASTExpression.cpp @@ -9,7 +9,6 @@ ASTExpression::ASTExpression() { - this->parent = parent; } diff --git a/Sencha-lang/AST/ASTNode.cpp b/Sencha-lang/AST/ASTNode.cpp index d6bd441..8875c21 100644 --- a/Sencha-lang/AST/ASTNode.cpp +++ b/Sencha-lang/AST/ASTNode.cpp @@ -8,7 +8,7 @@ #include "ASTNode.h" ASTNode::ASTNode() { - parent = 0; + } ASTNode::~ASTNode() { diff --git a/Sencha-lang/AST/ASTNode.h b/Sencha-lang/AST/ASTNode.h index 4092669..c5f3019 100644 --- a/Sencha-lang/AST/ASTNode.h +++ b/Sencha-lang/AST/ASTNode.h @@ -15,7 +15,6 @@ class ASTNode : public Visitable{ public: ASTNode(); - ASTNode * parent; std::vector<ASTNode *> children; virtual void accept(Visitor * visitor){ visitor->visit(this); }; diff --git a/Sencha-lang/AST/Assignment.cpp b/Sencha-lang/AST/Assignment.cpp index 33f817c..1e98070 100644 --- a/Sencha-lang/AST/Assignment.cpp +++ b/Sencha-lang/AST/Assignment.cpp @@ -65,9 +65,8 @@ std::string Assignment::debug() return debug_note; } -Assignment::Assignment(ASTNode * parent, Context * context) +Assignment::Assignment(Context * context) { - this->parent = parent; this->context = context; this->type = "Assignment"; } diff --git a/Sencha-lang/AST/Assignment.h b/Sencha-lang/AST/Assignment.h index 74721c9..4bb9a1a 100644 --- a/Sencha-lang/AST/Assignment.h +++ b/Sencha-lang/AST/Assignment.h @@ -24,7 +24,7 @@ public: void add_lvalue(ASTExpression *); void add_rvalue(ASTExpression *); virtual std::string debug() ; - Assignment(ASTNode * parent, Context * context); + Assignment(Context * context); virtual ~Assignment(); }; diff --git a/Sencha-lang/AST/BasicExpression.cpp b/Sencha-lang/AST/BasicExpression.cpp index 779c007..540dca4 100644 --- a/Sencha-lang/AST/BasicExpression.cpp +++ b/Sencha-lang/AST/BasicExpression.cpp @@ -44,8 +44,6 @@ void BasicExpression::set_right_operand(ASTNode * right) } void BasicExpression::execute() { - //children[0]->execute(); - //children[1]->execute(); std::cout << evaluate().repr() << std::endl; } @@ -106,7 +104,6 @@ SenchaObject BasicExpression::evaluate() { so = SenchaObject(left < right); } - //TODO actually those should get through parser else if(oper == "&&") { so = SenchaObject(left.is_true() && right.is_true()); @@ -118,8 +115,7 @@ SenchaObject BasicExpression::evaluate() return so; } -BasicExpression::BasicExpression(ASTNode * parent) : children_set(false){ - this->parent = parent; +BasicExpression::BasicExpression() : children_set(false){ this->type= "BasicExpression"; } diff --git a/Sencha-lang/AST/BasicExpression.h b/Sencha-lang/AST/BasicExpression.h index 47c8484..69b3f18 100644 --- a/Sencha-lang/AST/BasicExpression.h +++ b/Sencha-lang/AST/BasicExpression.h @@ -9,6 +9,14 @@ #define BASICEXPRESSION_H_ #include "ASTExpression.h" #include <iostream> + +/** + * BasicExpression is a very important class in my AST design. It always has + * two children, which are actually left and right operands. Basic expression stores + * a type of operation it does. It can be "+" or "-" for example. + * Type of operator is very important when expression evaluates itself. + * + */ class BasicExpression : public ASTExpression { public: @@ -21,10 +29,11 @@ public: std::string get_operator() { return oper; } virtual void accept(Visitor * visitor); - BasicExpression(ASTNode * parent); + BasicExpression(); virtual ~BasicExpression(); private: + //Do I use it for anything actually? bool children_set; std::string oper; }; diff --git a/Sencha-lang/AST/BasicStatement.cpp b/Sencha-lang/AST/BasicStatement.cpp index 16848fe..9a59d44 100644 --- a/Sencha-lang/AST/BasicStatement.cpp +++ b/Sencha-lang/AST/BasicStatement.cpp @@ -7,8 +7,7 @@ #include "BasicStatement.h" -BasicStatement::BasicStatement(ASTNode * parent) { - this->parent = parent; +BasicStatement::BasicStatement() { this->type = "BasicStatement"; } diff --git a/Sencha-lang/AST/BasicStatement.h b/Sencha-lang/AST/BasicStatement.h index 502cab0..4d29a16 100644 --- a/Sencha-lang/AST/BasicStatement.h +++ b/Sencha-lang/AST/BasicStatement.h @@ -14,7 +14,7 @@ class BasicStatement : public ASTStatement { public: - BasicStatement(ASTNode * parent); + BasicStatement(); void add_expression(ASTExpression * expr); virtual SenchaObject evaluate(); virtual void execute(); diff --git a/Sencha-lang/AST/ConstantExpression.cpp b/Sencha-lang/AST/ConstantExpression.cpp index 4f80a4a..69a81ce 100644 --- a/Sencha-lang/AST/ConstantExpression.cpp +++ b/Sencha-lang/AST/ConstantExpression.cpp @@ -7,9 +7,8 @@ #include "ConstantExpression.h" -ConstantExpression::ConstantExpression(ASTNode * parent) //Constructor which sets value to null SenchaObject. +ConstantExpression::ConstantExpression() //Constructor which sets value to null SenchaObject. { - this->parent = parent; value = SenchaObject(); this->type = "ConstantExpression"; } @@ -18,9 +17,8 @@ ConstantExpression::~ConstantExpression() { } -ConstantExpression::ConstantExpression(ASTNode * parent, SenchaObject value) : value(value) +ConstantExpression::ConstantExpression(SenchaObject value) : value(value) { - this->parent = parent; this->type = "ConstantExpression"; } @@ -44,21 +42,21 @@ void ConstantExpression::accept(Visitor * visitor) visitor->visit(this); } -ConstantExpression::ConstantExpression(ASTNode * parent, int number) +ConstantExpression::ConstantExpression( int number) { - this->parent = parent; value = SenchaObject(number); + value = SenchaObject(number); this->type = "ConstantExpression"; } -ConstantExpression::ConstantExpression(ASTNode * parent, double number) +ConstantExpression::ConstantExpression( double number) { - this->parent = parent; + this->type = "ConstantExpression"; value = SenchaObject(number); } -ConstantExpression::ConstantExpression(ASTNode * parent, std::string text) +ConstantExpression::ConstantExpression( std::string text) { this->type = "ConstantExpression"; - this->parent = parent; value = SenchaObject(text); + value = SenchaObject(text); } diff --git a/Sencha-lang/AST/ConstantExpression.h b/Sencha-lang/AST/ConstantExpression.h index aba07d8..e55660b 100644 --- a/Sencha-lang/AST/ConstantExpression.h +++ b/Sencha-lang/AST/ConstantExpression.h @@ -24,40 +24,35 @@ public: /** * Constructor which sets value to null SenchaObject.o it - * @param parent of the ConstantExpression node * @param number value will be set to SenchaObject representing this number */ - ConstantExpression(ASTNode * parent); + ConstantExpression(); /** *Constructor which creates SenchaObject(number) and sets value to it - * @param parent of the ConstantExpression node * @param number value will be set to SenchaObject representing this number */ - ConstantExpression(ASTNode * parent, int number) ; + ConstantExpression( int number) ; /** * Constructor which creates SenchaObject(number) and sets value to it - * @param parent of the ConstantExpression node * @param number value will be set to SenchaObject representing this number */ - ConstantExpression(ASTNode * parent, double number) ; + ConstantExpression( double number) ; /** * Constructor which creates SenchaObject(text) and sets value to it - * @param parent of the ConstantExpression node * @param text value will be set to SenchaObject representing this text */ - ConstantExpression(ASTNode * parent, std::string text); + ConstantExpression( std::string text); /** * Constructor which sets value to given value - * @param parent of the ConstantExpression node * @param value this->value will be set to value */ - ConstantExpression(ASTNode * parent, SenchaObject value); + ConstantExpression(SenchaObject value); /** Here's value of constant expression */ SenchaObject value; diff --git a/Sencha-lang/AST/DeclarationStatement.cpp b/Sencha-lang/AST/DeclarationStatement.cpp index c364175..406e5bf 100644 --- a/Sencha-lang/AST/DeclarationStatement.cpp +++ b/Sencha-lang/AST/DeclarationStatement.cpp @@ -27,7 +27,7 @@ void DeclarationStatement::add_right_value(ASTExpression * right) children[0] = right; } -DeclarationStatement::DeclarationStatement(ASTNode * parent, Context * context) +DeclarationStatement::DeclarationStatement(Context * context) { this->context = context; is_function = false; diff --git a/Sencha-lang/AST/DeclarationStatement.h b/Sencha-lang/AST/DeclarationStatement.h index d8b7061..50cbfb4 100644 --- a/Sencha-lang/AST/DeclarationStatement.h +++ b/Sencha-lang/AST/DeclarationStatement.h @@ -24,7 +24,7 @@ public: bool is_function; void add_right_value(ASTExpression * right); - DeclarationStatement(ASTNode * parent, Context * context); + DeclarationStatement(Context * context); void add_name(std::string); diff --git a/Sencha-lang/AST/IfNode.cpp b/Sencha-lang/AST/IfNode.cpp index bf84f7d..f654f43 100644 --- a/Sencha-lang/AST/IfNode.cpp +++ b/Sencha-lang/AST/IfNode.cpp @@ -8,8 +8,7 @@ #include "IfNode.h" -IfNode::IfNode(ASTNode * parent) { - this->parent = parent; +IfNode::IfNode() { is_else = false; this->type = "IfNode"; } diff --git a/Sencha-lang/AST/IfNode.h b/Sencha-lang/AST/IfNode.h index a8569bd..e035240 100644 --- a/Sencha-lang/AST/IfNode.h +++ b/Sencha-lang/AST/IfNode.h @@ -23,7 +23,7 @@ public: ASTNode * condition() { return children[0]; } ASTNode * then_block() { return children[1]; } ASTNode * else_block() { return children[2]; } - IfNode(ASTNode * parent); + IfNode(); virtual ~IfNode(); }; diff --git a/Sencha-lang/AST/IncorrectExpression.cpp b/Sencha-lang/AST/IncorrectExpression.cpp index 5d1fb71..376ca3f 100644 --- a/Sencha-lang/AST/IncorrectExpression.cpp +++ b/Sencha-lang/AST/IncorrectExpression.cpp @@ -7,9 +7,8 @@ #include "IncorrectExpression.h" -IncorrectExpression::IncorrectExpression(ASTNode * parent, std::string error_message) +IncorrectExpression::IncorrectExpression(std::string error_message) { - this->parent = parent; this->error_message = error_message; this->type = "IncorrectExpression"; } diff --git a/Sencha-lang/AST/IncorrectExpression.h b/Sencha-lang/AST/IncorrectExpression.h index cba11ae..eecf0bb 100644 --- a/Sencha-lang/AST/IncorrectExpression.h +++ b/Sencha-lang/AST/IncorrectExpression.h @@ -24,7 +24,7 @@ public: } std::string debug() { return "Incorrect Expression:\n" + error_message; } - IncorrectExpression(ASTNode * parent, std::string error_message); + IncorrectExpression( std::string error_message); virtual ~IncorrectExpression(); }; diff --git a/Sencha-lang/AST/PostfixExpression.cpp b/Sencha-lang/AST/PostfixExpression.cpp index bbee8e2..d277560 100644 --- a/Sencha-lang/AST/PostfixExpression.cpp +++ b/Sencha-lang/AST/PostfixExpression.cpp @@ -7,8 +7,7 @@ #include "PostfixExpression.h" -PostfixExpression::PostfixExpression(ASTNode * parent, Context * context) { - this->parent = parent; +PostfixExpression::PostfixExpression(Context * context) { this->context = context; name = ""; native = false; diff --git a/Sencha-lang/AST/PostfixExpression.h b/Sencha-lang/AST/PostfixExpression.h index 203d085..35bb00a 100644 --- a/Sencha-lang/AST/PostfixExpression.h +++ b/Sencha-lang/AST/PostfixExpression.h @@ -25,7 +25,7 @@ public: virtual void execute_quietly(){ execute(); }; - PostfixExpression(ASTNode * parent, Context * context); + PostfixExpression( Context * context); virtual ~PostfixExpression(); }; diff --git a/Sencha-lang/AST/RepeatStatement.cpp b/Sencha-lang/AST/RepeatStatement.cpp index f39851c..2b20780 100644 --- a/Sencha-lang/AST/RepeatStatement.cpp +++ b/Sencha-lang/AST/RepeatStatement.cpp @@ -7,9 +7,8 @@ #include "RepeatStatement.h" -RepeatStatement::RepeatStatement(ASTNode * parent) +RepeatStatement::RepeatStatement() { - this->parent = parent; how_many_times = 0; body = NULL; this->type = "RepeatStatement"; diff --git a/Sencha-lang/AST/RepeatStatement.h b/Sencha-lang/AST/RepeatStatement.h index 25cf150..a42b194 100644 --- a/Sencha-lang/AST/RepeatStatement.h +++ b/Sencha-lang/AST/RepeatStatement.h @@ -12,7 +12,7 @@ class RepeatStatement: public ASTStatement { public: - RepeatStatement(ASTNode * parent); + RepeatStatement(); int how_many_times; ASTStatement * body; void add_iteration_number(SenchaObject so); diff --git a/Sencha-lang/AST/VariableExpression.cpp b/Sencha-lang/AST/VariableExpression.cpp index db21663..6ebf0dd 100644 --- a/Sencha-lang/AST/VariableExpression.cpp +++ b/Sencha-lang/AST/VariableExpression.cpp @@ -7,10 +7,8 @@ #include "VariableExpression.h" -VariableExpression::VariableExpression(ASTNode * parent, Context * context, std::string name) { - +VariableExpression::VariableExpression(Context * context, std::string name) { this->name = name; - this->parent = parent; this->context = context; this->type = "VariableExpression"; } diff --git a/Sencha-lang/AST/VariableExpression.h b/Sencha-lang/AST/VariableExpression.h index 93df332..f89260c 100644 --- a/Sencha-lang/AST/VariableExpression.h +++ b/Sencha-lang/AST/VariableExpression.h @@ -15,7 +15,7 @@ class VariableExpression: public ASTExpression { public: VariableExpression(); - VariableExpression(ASTNode * parent, Context * context, std::string name); + VariableExpression(Context * context, std::string name); Context * context; std::string name; diff --git a/Sencha-lang/AST/WhileNode.cpp b/Sencha-lang/AST/WhileNode.cpp index 08dd763..11ebba8 100644 --- a/Sencha-lang/AST/WhileNode.cpp +++ b/Sencha-lang/AST/WhileNode.cpp @@ -7,9 +7,8 @@ #include "WhileNode.h" -WhileNode::WhileNode(ASTNode * parent) { +WhileNode::WhileNode() { body = NULL; - this->parent = parent; this->type = "WhileNode"; } diff --git a/Sencha-lang/AST/WhileNode.h b/Sencha-lang/AST/WhileNode.h index 136d976..131f152 100644 --- a/Sencha-lang/AST/WhileNode.h +++ b/Sencha-lang/AST/WhileNode.h @@ -12,7 +12,7 @@ #include "ASTExpression.h" class WhileNode: public ASTStatement { public: - WhileNode(ASTNode * parent); + WhileNode(); virtual ~WhileNode(); ASTStatement * body; void add_condition(ASTExpression * expression); diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp index 962bcb8..a6637ab 100644 --- a/Sencha-lang/Parser.cpp +++ b/Sencha-lang/Parser.cpp @@ -78,7 +78,7 @@ void Parser::interpret() read_next(); while(tok_value!= "") {
- program->add_statement(statement(program)); + program->add_statement(statement()); }
@@ -142,22 +142,22 @@ bool Parser::is_function_name() }
-ASTStatement * Parser::statement(ASTNode * parent) +ASTStatement * Parser::statement() {
- BasicStatement * stat = new BasicStatement(parent);
+ BasicStatement * stat = new BasicStatement();
if(accept("{")) { while(!accept("}")) { - stat->children.push_back( statement(parent)); + stat->children.push_back( statement()); } }
else if(is_type()) {
- DeclarationStatement * declaration = new DeclarationStatement(parent, context); + DeclarationStatement * declaration = new DeclarationStatement(context); std::string identifier = tok_value;
read_next();
@@ -166,7 +166,7 @@ ASTStatement * Parser::statement(ASTNode * parent) if(accept("="))
{
- ASTExpression * ae = expr(stat);
+ ASTExpression * ae = expr();
declaration->add_right_value(ae);
accept(";");
}
@@ -193,7 +193,7 @@ ASTStatement * Parser::statement(ASTNode * parent) if(!accept(";"))
{
- declaration->add_body(statement(stat));
+ declaration->add_body(statement());
}
@@ -205,12 +205,12 @@ ASTStatement * Parser::statement(ASTNode * parent) } else if(accept("if")) {
- IfNode * ifStatement = new IfNode(parent);
- ifStatement->add_condition(expr(ifStatement));
- ifStatement->add_body(statement(parent));
+ IfNode * ifStatement = new IfNode();
+ ifStatement->add_condition(expr());
+ ifStatement->add_body(statement());
if(accept("else"))
{
- ifStatement->add_else_block(statement(parent));
+ ifStatement->add_else_block(statement());
} delete stat;
@@ -218,9 +218,9 @@ ASTStatement * Parser::statement(ASTNode * parent) }
else if(accept("repeat"))
{
- RepeatStatement * repeat = new RepeatStatement(parent);
- repeat->add_iteration_number(expr(repeat)->evaluate());
- repeat->add_body(statement(repeat));
+ RepeatStatement * repeat = new RepeatStatement();
+ repeat->add_iteration_number(expr()->evaluate());
+ repeat->add_body(statement());
//similar stuff
delete stat;
@@ -228,9 +228,9 @@ ASTStatement * Parser::statement(ASTNode * parent) } else if(accept("while")) { - WhileNode * while_node = new WhileNode(parent);
- while_node->add_condition(expr(while_node));
- while_node->add_body(statement(while_node));
+ WhileNode * while_node = new WhileNode();
+ while_node->add_condition(expr());
+ while_node->add_body(statement());
delete stat;
return while_node; @@ -240,7 +240,7 @@ ASTStatement * Parser::statement(ASTNode * parent) if(!peek(";")) { - stat->add_expression(expr(stat)); + stat->add_expression(expr()); } expect(";"); @@ -250,7 +250,7 @@ ASTStatement * Parser::statement(ASTNode * parent) else {
- stat->add_expression(expr(stat)); + stat->add_expression(expr()); while(!expect(";") && tok_value != "") read_next();
return stat; @@ -259,27 +259,27 @@ ASTStatement * Parser::statement(ASTNode * parent) return stat; } -ASTExpression * Parser::prim_expr(ASTNode * expression) +ASTExpression * Parser::prim_expr() {
if(current_token.get_type() == t_integer) {
ConstantExpression * ce;
- ce = new ConstantExpression(expression, std::atoi(tok_value.c_str()));
+ ce = new ConstantExpression(std::atoi(tok_value.c_str()));
read_next();
return ce; }
else if(current_token.get_type() == t_float)
{
ConstantExpression * ce;
- ce = new ConstantExpression(expression, std::atof(tok_value.c_str()));
+ ce = new ConstantExpression(std::atof(tok_value.c_str()));
read_next();
return ce;
} else if(current_token.get_type() == t_literal) {
ConstantExpression * ce;
- ce = new ConstantExpression(expression, tok_value);
+ ce = new ConstantExpression(tok_value);
read_next();
return ce; }
@@ -289,13 +289,13 @@ ASTExpression * Parser::prim_expr(ASTNode * expression) if(tok_value == "true")
{
- ce = new ConstantExpression(expression, SenchaObject(true));
+ ce = new ConstantExpression( SenchaObject(true));
read_next();
}
else if (tok_value == "false")
{
- ce = new ConstantExpression(expression, SenchaObject(false));
+ ce = new ConstantExpression(SenchaObject(false));
read_next();
}
return ce;
@@ -305,14 +305,14 @@ ASTExpression * Parser::prim_expr(ASTNode * expression) string name = current_token.value;
VariableExpression * ve;
- ve = new VariableExpression(expression, context, name);
+ ve = new VariableExpression(context, name);
read_next();
return ve;
} else if(accept("(")) {
BasicExpression * be; - be = static_cast<BasicExpression *>(expr(expression));
+ be = static_cast<BasicExpression *>(expr());
expect(")");
return be; @@ -322,27 +322,27 @@ ASTExpression * Parser::prim_expr(ASTNode * expression) string error_message = "ERROR: unexpected primary expression " + tok_value + "\n"; error(error_message); read_next();
- return new IncorrectExpression(expression, error_message); + return new IncorrectExpression(error_message); }
} -ASTExpression * Parser::postfix_expr(ASTNode * expression) +ASTExpression * Parser::postfix_expr() {
auto name = tok_value;
if(is_function_name())
{
- PostfixExpression * function_call = new PostfixExpression(expression, context);
+ PostfixExpression * function_call = new PostfixExpression( context);
function_call->set_name(name);
if(accept("("))
{
if(!accept(")"))
{
- function_call->add_argument(expr(function_call));
+ function_call->add_argument(expr());
while(accept(","))
{
- function_call->add_argument(expr(function_call));
+ function_call->add_argument(expr());
}
expect(")");
@@ -351,13 +351,13 @@ ASTExpression * Parser::postfix_expr(ASTNode * expression) return function_call;
}
}
- return prim_expr(expression); + return prim_expr(); }
-ASTExpression * Parser::mul_expr(ASTNode * expression)
+ASTExpression * Parser::mul_expr()
{
- BasicExpression * be = new BasicExpression(expression);
- be->set_left_operand(postfix_expr(be));
+ BasicExpression * be = new BasicExpression();
+ be->set_left_operand(postfix_expr());
if(peek("*") || peek("/"))
{
if(accept("*"))
@@ -369,13 +369,12 @@ ASTExpression * Parser::mul_expr(ASTNode * expression) be->set_operator("/");
}
- be->set_right_operand(mul_expr(be));
+ be->set_right_operand(mul_expr());
}
else
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
- ae->parent = expression;
delete be;
return ae;
}
@@ -383,10 +382,10 @@ ASTExpression * Parser::mul_expr(ASTNode * expression) return be;
}
-ASTExpression * Parser::add_expr(ASTNode * expression) +ASTExpression * Parser::add_expr() {
- BasicExpression * be = new BasicExpression(expression); - be->set_left_operand(mul_expr(be)); + BasicExpression * be = new BasicExpression(); + be->set_left_operand(mul_expr()); if(peek("+") || peek("-")) { if(accept("+")) @@ -399,13 +398,12 @@ ASTExpression * Parser::add_expr(ASTNode * expression) be->set_operator("-"); }
- be->set_right_operand(add_expr(be)); + be->set_right_operand(add_expr()); }
else
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
- ae->parent = expression;
delete be;
return ae;
}
@@ -413,10 +411,10 @@ ASTExpression * Parser::add_expr(ASTNode * expression) return be; } -ASTExpression * Parser::rel_expr(ASTNode * expression) +ASTExpression * Parser::rel_expr() {
- BasicExpression * be = new BasicExpression(expression);
- be->set_left_operand(add_expr(be)); + BasicExpression * be = new BasicExpression();
+ be->set_left_operand(add_expr()); if(peek("<") || peek(">")) { if(accept("<"))
@@ -429,13 +427,12 @@ ASTExpression * Parser::rel_expr(ASTNode * expression) be->set_operator(">");
} - be->set_right_operand(rel_expr(be)); + be->set_right_operand(rel_expr()); }
else
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
- ae->parent = expression;
delete be;
return ae;
}
@@ -444,10 +441,10 @@ ASTExpression * Parser::rel_expr(ASTNode * expression) return be; } -ASTExpression * Parser::eq_expr(ASTNode * expression) +ASTExpression * Parser::eq_expr() {
- BasicExpression * be = new BasicExpression(expression);
- be->set_left_operand(rel_expr(be)); + BasicExpression * be = new BasicExpression();
+ be->set_left_operand(rel_expr()); if(peek("==") || peek("!=")) { if(accept("==")) @@ -460,13 +457,12 @@ ASTExpression * Parser::eq_expr(ASTNode * expression) be->set_operator("!="); }
- be->set_right_operand(eq_expr(be)); + be->set_right_operand(eq_expr()); }
else
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
- ae->parent = expression;
delete be;
return ae;
}
@@ -474,10 +470,10 @@ ASTExpression * Parser::eq_expr(ASTNode * expression) return be; }
-ASTExpression * Parser::log_expr(ASTNode * expression)
+ASTExpression * Parser::log_expr()
{
- BasicExpression * be = new BasicExpression(expression);
- be->set_left_operand(eq_expr(be));
+ BasicExpression * be = new BasicExpression();
+ be->set_left_operand(eq_expr());
if(peek("and") || peek("or"))
{
if(accept("and"))
@@ -490,13 +486,12 @@ ASTExpression * Parser::log_expr(ASTNode * expression) be->set_operator("||");
}
- be->set_right_operand(log_expr(be));
+ be->set_right_operand(log_expr());
}
else
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
- ae->parent = expression;
delete be;
return ae;
}
@@ -504,15 +499,15 @@ ASTExpression * Parser::log_expr(ASTNode * expression) return be;
} -ASTExpression * Parser::expr(ASTNode * expression) +ASTExpression * Parser::expr() {
- Assignment * assignment = new Assignment(expression, context);
+ Assignment * assignment = new Assignment( context);
auto name = tok_value;
- ASTExpression * left = log_expr(assignment);
+ ASTExpression * left = log_expr();
if(accept("=")) {
- ASTExpression * right = expr(assignment);
+ ASTExpression * right = expr();
assignment->add_lvalue(left);
assignment->add_rvalue(right);
@@ -523,7 +518,6 @@ ASTExpression * Parser::expr(ASTNode * expression) else
{
- left->parent = expression;
delete assignment;
return left;
}
diff --git a/Sencha-lang/Parser.h b/Sencha-lang/Parser.h index 80033b7..018095c 100644 --- a/Sencha-lang/Parser.h +++ b/Sencha-lang/Parser.h @@ -44,16 +44,16 @@ class Parser void error(string s); - ASTStatement * statement(ASTNode * node); + ASTStatement * statement(); - ASTExpression * log_expr(ASTNode * node);
- ASTExpression * mul_expr(ASTNode * node); - ASTExpression * add_expr(ASTNode * node); - ASTExpression * prim_expr(ASTNode * node); - ASTExpression * postfix_expr(ASTNode * node); - ASTExpression * rel_expr(ASTNode * node); - ASTExpression * eq_expr(ASTNode * node); - ASTExpression * expr(ASTNode * node);
+ ASTExpression * log_expr();
+ ASTExpression * mul_expr(); + ASTExpression * add_expr(); + ASTExpression * prim_expr(); + ASTExpression * postfix_expr(); + ASTExpression * rel_expr(); + ASTExpression * eq_expr(); + ASTExpression * expr();
};
#endif // PARSER_H
diff --git a/Sencha-lang/Tests/TestASTInspector.cpp b/Sencha-lang/Tests/TestASTInspector.cpp index 9469389..d5fbf42 100644 --- a/Sencha-lang/Tests/TestASTInspector.cpp +++ b/Sencha-lang/Tests/TestASTInspector.cpp @@ -28,12 +28,9 @@ std::string TestASTInspector::test_inspecting_basic_expression() muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("BasicExpression") == 1); muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("ConstantExpression") == 2); - delete be; inspector.forget_everything(); return test_report; - - } std::string TestASTInspector::test_inspecting_simple_AST() @@ -53,31 +50,29 @@ std::string TestASTInspector::test_inspecting_simple_AST() delete be; inspector.forget_everything(); return test_report; - - } std::string TestASTInspector::all_tests() { std::string test_report = ""; - mu_run_test(test_inspecting_basic_expression); - mu_run_test(test_inspecting_simple_AST); - return test_report; + mu_run_test(test_inspecting_basic_expression); + mu_run_test(test_inspecting_simple_AST); + return test_report; } BasicExpression * TestASTInspector::build_basic_expression(std::string oper, SenchaObject arg1, SenchaObject arg2) { - BasicExpression * be = new BasicExpression(NULL); + BasicExpression * be = new BasicExpression(); be->set_operator(oper); - be->set_left_operand(new ConstantExpression(be, arg1)); - be->set_right_operand(new ConstantExpression(be, arg2)); + be->set_left_operand(new ConstantExpression( arg1)); + be->set_right_operand(new ConstantExpression( arg2)); return be; } BasicExpression * TestASTInspector::build_simple_AST(std::string oper, BasicExpression * left, BasicExpression * right) { - BasicExpression * be = new BasicExpression(NULL); + BasicExpression * be = new BasicExpression(); be->set_operator(oper); be->set_left_operand(left); be->set_right_operand(right); diff --git a/Sencha-lang/sencha2 b/Sencha-lang/sencha2 index 437f346..a3c5e91 100644 --- a/Sencha-lang/sencha2 +++ b/Sencha-lang/sencha2 @@ -52,7 +52,7 @@ PROJECT_LOGO = # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. -OUTPUT_DIRECTORY = ../documentation +OUTPUT_DIRECTORY = ../../sencha-documentation # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output |