summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/AST
diff options
context:
space:
mode:
Diffstat (limited to 'Sencha-lang/AST')
-rw-r--r--Sencha-lang/AST/ASTExpression.h1
-rw-r--r--Sencha-lang/AST/AllTypesOfASTNodes.h2
-rw-r--r--Sencha-lang/AST/Assignment.cpp14
-rw-r--r--Sencha-lang/AST/Assignment.h1
-rw-r--r--Sencha-lang/AST/BasicExpression.cpp4
-rw-r--r--Sencha-lang/AST/BasicExpression.h2
-rw-r--r--Sencha-lang/AST/ConstantExpression.cpp13
-rw-r--r--Sencha-lang/AST/ConstantExpression.h1
-rw-r--r--Sencha-lang/AST/DeclarationStatement.cpp9
-rw-r--r--Sencha-lang/AST/DeclarationStatement.h4
-rw-r--r--Sencha-lang/AST/IncorrectExpression.h2
-rw-r--r--Sencha-lang/AST/PostfixExpression.h2
12 files changed, 47 insertions, 8 deletions
diff --git a/Sencha-lang/AST/ASTExpression.h b/Sencha-lang/AST/ASTExpression.h
index eb56b19..13d1f48 100644
--- a/Sencha-lang/AST/ASTExpression.h
+++ b/Sencha-lang/AST/ASTExpression.h
@@ -15,6 +15,7 @@ public:
virtual SenchaObject evaluate() = 0;
virtual void execute() = 0;
+ virtual void execute_quietly() = 0;
ASTExpression();
virtual ~ASTExpression();
};
diff --git a/Sencha-lang/AST/AllTypesOfASTNodes.h b/Sencha-lang/AST/AllTypesOfASTNodes.h
index 09f7597..4d29993 100644
--- a/Sencha-lang/AST/AllTypesOfASTNodes.h
+++ b/Sencha-lang/AST/AllTypesOfASTNodes.h
@@ -19,7 +19,7 @@
#include "PostfixExpression.h"
#include "IncorrectExpression.h"
#include "Assignment.h"
-
+#include "DeclarationStatement.h"
//And probably more
//TODO actualize it
diff --git a/Sencha-lang/AST/Assignment.cpp b/Sencha-lang/AST/Assignment.cpp
index 9925475..05f5bc5 100644
--- a/Sencha-lang/AST/Assignment.cpp
+++ b/Sencha-lang/AST/Assignment.cpp
@@ -16,6 +16,7 @@ void Assignment::execute()
{
auto left_value = static_cast<ASTExpression *>(children[0])->evaluate();
auto right_value = static_cast<ASTExpression *>(children[1])->evaluate();
+ static_cast<ASTExpression *>(children[1])->execute_quietly();
if(left_value.name != "")
{
right_value.name = left_value.name;
@@ -24,6 +25,19 @@ void Assignment::execute()
std::cout << right_value.repr() << std::endl;
}
+void Assignment::execute_quietly()
+{
+ auto left_value = static_cast<ASTExpression *>(children[0])->evaluate();
+ auto right_value = static_cast<ASTExpression *>(children[1])->evaluate();
+ static_cast<ASTExpression *>(children[1])->execute_quietly();
+ if(left_value.name != "")
+ {
+ right_value.name = left_value.name;
+ context->set(left_value.name, right_value);
+ }
+
+}
+
void Assignment::add_lvalue(ASTExpression * left)
{
if(children.size()==0)
diff --git a/Sencha-lang/AST/Assignment.h b/Sencha-lang/AST/Assignment.h
index 6ef3a48..c851ccf 100644
--- a/Sencha-lang/AST/Assignment.h
+++ b/Sencha-lang/AST/Assignment.h
@@ -17,6 +17,7 @@ public:
SenchaObject evaluate();
void execute();
+ void execute_quietly();
void add_lvalue(ASTExpression *);
void add_rvalue(ASTExpression *);
virtual std::string debug() ;
diff --git a/Sencha-lang/AST/BasicExpression.cpp b/Sencha-lang/AST/BasicExpression.cpp
index a6f9136..2201950 100644
--- a/Sencha-lang/AST/BasicExpression.cpp
+++ b/Sencha-lang/AST/BasicExpression.cpp
@@ -49,6 +49,10 @@ void BasicExpression::execute()
std::cout << evaluate().repr() << std::endl;
}
+void BasicExpression::execute_quietly()
+{
+ evaluate();
+}
SenchaObject BasicExpression::evaluate()
{
//TODO refactor it ;)
diff --git a/Sencha-lang/AST/BasicExpression.h b/Sencha-lang/AST/BasicExpression.h
index 00dcac2..3984fb8 100644
--- a/Sencha-lang/AST/BasicExpression.h
+++ b/Sencha-lang/AST/BasicExpression.h
@@ -20,7 +20,7 @@ public:
void set_right_operand(ASTNode * right);
virtual SenchaObject evaluate();
virtual void execute();
-
+ virtual void execute_quietly();
std::string debug() ;
diff --git a/Sencha-lang/AST/ConstantExpression.cpp b/Sencha-lang/AST/ConstantExpression.cpp
index 78937ca..e913bea 100644
--- a/Sencha-lang/AST/ConstantExpression.cpp
+++ b/Sencha-lang/AST/ConstantExpression.cpp
@@ -28,9 +28,16 @@ SenchaObject ConstantExpression::evaluate()
return value;
}
-void ConstantExpression::execute() {
- std::cout << evaluate().repr() << std::endl;//Do nothing
- };
+void ConstantExpression::execute()
+{
+ std::cout << evaluate().repr() << std::endl;//Do nothing
+}
+
+void ConstantExpression::execute_quietly()
+{
+ evaluate();
+}
+
ConstantExpression::ConstantExpression(ASTNode * parent, int number)
{
diff --git a/Sencha-lang/AST/ConstantExpression.h b/Sencha-lang/AST/ConstantExpression.h
index e02392e..ad28956 100644
--- a/Sencha-lang/AST/ConstantExpression.h
+++ b/Sencha-lang/AST/ConstantExpression.h
@@ -26,6 +26,7 @@ public:
virtual SenchaObject evaluate();
virtual void execute() ;
+ virtual void execute_quietly() ;
};
#endif /* CONSTANTEXPRESSION_H_ */
diff --git a/Sencha-lang/AST/DeclarationStatement.cpp b/Sencha-lang/AST/DeclarationStatement.cpp
index 241120a..571c5e6 100644
--- a/Sencha-lang/AST/DeclarationStatement.cpp
+++ b/Sencha-lang/AST/DeclarationStatement.cpp
@@ -15,13 +15,17 @@ DeclarationStatement::~DeclarationStatement() {
void DeclarationStatement::add_right_value(ASTExpression * right)
{
-
+ right_value = right->evaluate();
+ children[0] = right;
}
DeclarationStatement::DeclarationStatement(ASTNode * parent, Context * context)
{
+ this->context = context;
is_function = false;
body = NULL;
+ right_value = SenchaObject();
+ children.push_back(new ConstantExpression(this));
}
std::string DeclarationStatement::debug()
@@ -50,7 +54,8 @@ void DeclarationStatement::execute()
}
else
{
-
+ context->add(name, right_value);
+ children[0]->execute() ;
}
}
diff --git a/Sencha-lang/AST/DeclarationStatement.h b/Sencha-lang/AST/DeclarationStatement.h
index cbadafe..573dc38 100644
--- a/Sencha-lang/AST/DeclarationStatement.h
+++ b/Sencha-lang/AST/DeclarationStatement.h
@@ -10,12 +10,14 @@
#include "ASTStatement.h"
#include "ASTExpression.h"
-
+#include "ConstantExpression.h"
#include "../Context.h"
+
class DeclarationStatement: public ASTStatement {
public:
std::string name;
+ Context * context;
SenchaObject right_value;
ASTStatement * body;
std::vector<std::string> arguments;
diff --git a/Sencha-lang/AST/IncorrectExpression.h b/Sencha-lang/AST/IncorrectExpression.h
index 58c8abd..cba11ae 100644
--- a/Sencha-lang/AST/IncorrectExpression.h
+++ b/Sencha-lang/AST/IncorrectExpression.h
@@ -19,7 +19,9 @@ public:
virtual SenchaObject evaluate() ;
void execute() { std::cout << debug(); }
+ void execute_quietly() { //do nothing
+ }
std::string debug() { return "Incorrect Expression:\n" + error_message; }
IncorrectExpression(ASTNode * parent, std::string error_message);
diff --git a/Sencha-lang/AST/PostfixExpression.h b/Sencha-lang/AST/PostfixExpression.h
index 124a0ad..1590123 100644
--- a/Sencha-lang/AST/PostfixExpression.h
+++ b/Sencha-lang/AST/PostfixExpression.h
@@ -21,6 +21,8 @@ public:
virtual SenchaObject evaluate();
virtual void execute();
+ virtual void execute_quietly(){//do nothing
+ };
std::string debug() ;