diff --git a/.gitignore b/.gitignore
index fd2f740..14a8851 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
Sencha-lang/Debug/*
Sencha-lang/Release/*
+*.o
diff --git a/Sencha-lang/.cproject b/Sencha-lang/.cproject
index ef991be..a4fe393 100644
--- a/Sencha-lang/.cproject
+++ b/Sencha-lang/.cproject
@@ -27,6 +27,7 @@
+
diff --git a/Sencha-lang/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree b/Sencha-lang/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree
deleted file mode 100644
index 284ff48..0000000
Binary files a/Sencha-lang/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree and /dev/null differ
diff --git a/Sencha-lang/AST.cpp b/Sencha-lang/AST.cpp
deleted file mode 100644
index d31be57..0000000
--- a/Sencha-lang/AST.cpp
+++ /dev/null
@@ -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() {
-}
-
diff --git a/Sencha-lang/AST.h b/Sencha-lang/AST.h
deleted file mode 100644
index c29207e..0000000
--- a/Sencha-lang/AST.h
+++ /dev/null
@@ -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_ */
diff --git a/Sencha-lang/AST/AST.cpp b/Sencha-lang/AST/AST.cpp
index 5fcf37e..8c36289 100644
--- a/Sencha-lang/AST/AST.cpp
+++ b/Sencha-lang/AST/AST.cpp
@@ -14,6 +14,11 @@ AST::AST() {
level_of_depth = 0;
}
+void AST::delete_all_children()
+{
+ //TODO perform deleting
+}
+
AST::~AST() {
}
diff --git a/Sencha-lang/AST/AST.h b/Sencha-lang/AST/AST.h
index c29207e..113ec4c 100644
--- a/Sencha-lang/AST/AST.h
+++ b/Sencha-lang/AST/AST.h
@@ -16,6 +16,7 @@ public:
ASTNode * current_node;
int number_of_nodes;
int level_of_depth;
+ void delete_all_children();
ASTNode * add_node(ASTNode * node);
virtual ~AST();
};
diff --git a/Sencha-lang/AST/ASTExpression.cpp b/Sencha-lang/AST/ASTExpression.cpp
index 32a47d8..72ba75b 100644
--- a/Sencha-lang/AST/ASTExpression.cpp
+++ b/Sencha-lang/AST/ASTExpression.cpp
@@ -7,12 +7,13 @@
#include "ASTExpression.h"
+
ASTExpression::ASTExpression() {
- // TODO Auto-generated constructor stub
+ this->parent = parent;
}
ASTExpression::~ASTExpression() {
- // TODO Auto-generated destructor stub
+
}
diff --git a/Sencha-lang/AST/ASTExpression.h b/Sencha-lang/AST/ASTExpression.h
index 69010ae..13d1f48 100644
--- a/Sencha-lang/AST/ASTExpression.h
+++ b/Sencha-lang/AST/ASTExpression.h
@@ -7,10 +7,15 @@
#ifndef ASTEXPRESSION_H_
#define ASTEXPRESSION_H_
+#include
#include "ASTNode.h"
class ASTExpression : public ASTNode {
public:
+
+ virtual SenchaObject evaluate() = 0;
+ virtual void execute() = 0;
+ virtual void execute_quietly() = 0;
ASTExpression();
virtual ~ASTExpression();
};
diff --git a/Sencha-lang/AST/ASTNode.cpp b/Sencha-lang/AST/ASTNode.cpp
index 80429c2..6ee2df0 100644
--- a/Sencha-lang/AST/ASTNode.cpp
+++ b/Sencha-lang/AST/ASTNode.cpp
@@ -8,7 +8,6 @@
#include "ASTNode.h"
ASTNode::ASTNode() {
- // TODO Auto-generated constructor stub
parent = 0;
}
diff --git a/Sencha-lang/AST/ASTNode.h b/Sencha-lang/AST/ASTNode.h
index b0145a3..b5d0355 100644
--- a/Sencha-lang/AST/ASTNode.h
+++ b/Sencha-lang/AST/ASTNode.h
@@ -8,6 +8,8 @@
#ifndef ASTNODE_H_
#define ASTNODE_H_
#include
+#include
+#include "SenchaObject.h"
class ASTNode {
public:
@@ -17,6 +19,8 @@ public:
void add_children(ASTNode *);
void remove_most_right_children();
void set_parent(ASTNode *);
+
+ virtual std::string debug() = 0;
virtual void execute() = 0;
virtual ~ASTNode();
};
diff --git a/Sencha-lang/AST/ASTProgram.cpp b/Sencha-lang/AST/ASTProgram.cpp
deleted file mode 100644
index 8b74923..0000000
--- a/Sencha-lang/AST/ASTProgram.cpp
+++ /dev/null
@@ -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";
-}
diff --git a/Sencha-lang/AST/ASTProgram.h b/Sencha-lang/AST/ASTProgram.h
deleted file mode 100644
index f83bbf3..0000000
--- a/Sencha-lang/AST/ASTProgram.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * ASTProgram.h
- *
- * Created on: Nov 5, 2012
- * Author: attero
- */
-
-#ifndef ASTPROGRAM_H_
-#define ASTPROGRAM_H_
-#include
-#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_ */
diff --git a/Sencha-lang/AST/ASTStatement.h b/Sencha-lang/AST/ASTStatement.h
index b2bfd84..f1e9451 100644
--- a/Sencha-lang/AST/ASTStatement.h
+++ b/Sencha-lang/AST/ASTStatement.h
@@ -12,6 +12,7 @@
class ASTStatement : public ASTNode {
public:
ASTStatement();
+ virtual void execute() = 0;
virtual ~ASTStatement();
};
diff --git a/Sencha-lang/AST/AllTypesOfASTNodes.h b/Sencha-lang/AST/AllTypesOfASTNodes.h
index b5f30ee..4d29993 100644
--- a/Sencha-lang/AST/AllTypesOfASTNodes.h
+++ b/Sencha-lang/AST/AllTypesOfASTNodes.h
@@ -12,8 +12,14 @@
#include "ProgramNode.h"
#include "ASTStatement.h"
#include "ASTExpression.h"
-#include "ASTPrimary.h"
+#include "BasicStatement.h"
+#include "BasicExpression.h"
+#include "ConstantExpression.h"
+#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
new file mode 100644
index 0000000..05f5bc5
--- /dev/null
+++ b/Sencha-lang/AST/Assignment.cpp
@@ -0,0 +1,76 @@
+/*
+ * Assignment.cpp
+ *
+ * Created on: Dec 7, 2012
+ * Author: attero
+ */
+
+#include "Assignment.h"
+
+SenchaObject Assignment::evaluate()
+{
+ return static_cast(children[1])->evaluate();
+}
+
+void Assignment::execute()
+{
+ auto left_value = static_cast(children[0])->evaluate();
+ auto right_value = static_cast(children[1])->evaluate();
+ static_cast(children[1])->execute_quietly();
+ if(left_value.name != "")
+ {
+ right_value.name = left_value.name;
+ context->set(left_value.name, right_value);
+ }
+ std::cout << right_value.repr() << std::endl;
+}
+
+void Assignment::execute_quietly()
+{
+ auto left_value = static_cast(children[0])->evaluate();
+ auto right_value = static_cast(children[1])->evaluate();
+ static_cast(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)
+ children.push_back(left);
+ else
+ children[0] = left;
+}
+
+void Assignment::add_rvalue(ASTExpression * right)
+{
+ //TODO should note something if it doesn't look like that. Other possibilities like
+ if(children.size()==1)
+ children.push_back(right);
+ else if(children.size()>1)
+ children[1] = right;
+
+}
+
+std::string Assignment::debug()
+{
+ std::string debug_note = static_cast(children[0])->evaluate().repr();
+ debug_note += " = " + static_cast(children[1])->evaluate().repr() + "\n";
+ return debug_note;
+}
+
+Assignment::Assignment(ASTNode * parent, Context * context)
+{
+ this->parent = parent;
+ this->context = context;
+}
+
+
+Assignment::~Assignment() {
+ // TODO Auto-generated destructor stub
+}
+
diff --git a/Sencha-lang/AST/Assignment.h b/Sencha-lang/AST/Assignment.h
new file mode 100644
index 0000000..c851ccf
--- /dev/null
+++ b/Sencha-lang/AST/Assignment.h
@@ -0,0 +1,28 @@
+/*
+ * Assignment.h
+ *
+ * Created on: Dec 7, 2012
+ * Author: attero
+ */
+
+#ifndef ASSIGNMENT_H_
+#define ASSIGNMENT_H_
+#include
+#include "ASTExpression.h"
+#include "../Context.h"
+
+class Assignment : public ASTExpression {
+public:
+ Context * context;
+
+ SenchaObject evaluate();
+ void execute();
+ void execute_quietly();
+ void add_lvalue(ASTExpression *);
+ void add_rvalue(ASTExpression *);
+ virtual std::string debug() ;
+ Assignment(ASTNode * parent, Context * context);
+ virtual ~Assignment();
+};
+
+#endif /* ASSIGNMENT_H_ */
diff --git a/Sencha-lang/AST/BasicExpression.cpp b/Sencha-lang/AST/BasicExpression.cpp
new file mode 100644
index 0000000..2201950
--- /dev/null
+++ b/Sencha-lang/AST/BasicExpression.cpp
@@ -0,0 +1,107 @@
+/*
+ * 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)
+{
+ if(!this->children_set)
+ {
+ children.push_back(left);
+ }
+ else
+ {
+ this->children[0] = left;
+ }
+
+ if(children.size() == 2)
+ children_set = true;
+}
+
+void BasicExpression::set_right_operand(ASTNode * right)
+{
+ if(!this->children_set)
+ {
+ children.push_back(right);
+
+ }
+ else
+ {
+ this->children[1] = right;
+ }
+
+ if(children.size() == 2)
+ children_set = true;
+}
+void BasicExpression::execute()
+{
+ //children[0]->execute();
+ //children[1]->execute();
+ std::cout << evaluate().repr() << std::endl;
+}
+
+void BasicExpression::execute_quietly()
+{
+ evaluate();
+}
+SenchaObject BasicExpression::evaluate()
+{
+ //TODO refactor it ;)
+
+ SenchaObject left = static_cast(children[0])->evaluate();
+ SenchaObject right = static_cast(children[1])->evaluate();
+
+
+ SenchaObject so;
+ if(oper == "+")
+ {
+ so = SenchaObject(left + right);
+ }
+ else if(oper == "-")
+ {
+ so = SenchaObject(left - right);
+ }
+ else if(oper == "*")
+ {
+ so = SenchaObject(left * right);
+ }
+ else if(oper == "/")
+ {
+ so = SenchaObject(left / right);
+ }
+ else if(oper == "=")
+ {
+ so = SenchaObject(right);
+ }
+ return so;
+}
+
+BasicExpression::BasicExpression(ASTNode * parent) {
+ this->parent = parent;
+ children_set = false;
+}
+
+BasicExpression::~BasicExpression() {
+ // TODO Auto-generated destructor stub
+ // TODO free children memory
+}
+
+
+std::string BasicExpression::debug()
+{
+ std::string debug_note = "Basic expression:\n";
+ debug_note += "left operand: \n";
+ debug_note += this->children[0]->debug();
+ debug_note += "\nright operand:\n" + this->children[1]->debug();
+ debug_note += "\nOperator: " + this->oper +"\n###\n";
+ return debug_note;
+}
diff --git a/Sencha-lang/AST/BasicExpression.h b/Sencha-lang/AST/BasicExpression.h
new file mode 100644
index 0000000..3984fb8
--- /dev/null
+++ b/Sencha-lang/AST/BasicExpression.h
@@ -0,0 +1,32 @@
+/*
+ * BasicExpression.h
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#ifndef BASICEXPRESSION_H_
+#define BASICEXPRESSION_H_
+#include "ASTExpression.h"
+#include
+class BasicExpression : public ASTExpression {
+public:
+
+ std::string oper;
+
+ bool children_set;
+ void set_operator(std::string op);
+ void set_left_operand(ASTNode * left);
+ void set_right_operand(ASTNode * right);
+ virtual SenchaObject evaluate();
+ virtual void execute();
+ virtual void execute_quietly();
+
+
+ std::string debug() ;
+
+ BasicExpression(ASTNode * parent);
+ virtual ~BasicExpression();
+};
+
+#endif /* BASICEXPRESSION_H_ */
diff --git a/Sencha-lang/AST/BasicStatement.cpp b/Sencha-lang/AST/BasicStatement.cpp
new file mode 100644
index 0000000..ffdfe1f
--- /dev/null
+++ b/Sencha-lang/AST/BasicStatement.cpp
@@ -0,0 +1,31 @@
+/*
+ * BasicStatement.cpp
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#include "BasicStatement.h"
+
+BasicStatement::BasicStatement(ASTNode * parent) {
+ this->parent = parent;
+}
+
+BasicStatement::~BasicStatement() {
+ // TODO Auto-generated destructor stub
+}
+
+void BasicStatement::add_expression(ASTExpression * expr)
+{
+ children.push_back(expr);
+}
+
+std::string BasicStatement::debug()
+{
+ return "Basic statement with expression:\n" + children[0]->debug() + "\n;\n";
+}
+
+void BasicStatement::execute()
+{
+ children[0]->execute() ;
+}
diff --git a/Sencha-lang/AST/BasicStatement.h b/Sencha-lang/AST/BasicStatement.h
new file mode 100644
index 0000000..a34c4e7
--- /dev/null
+++ b/Sencha-lang/AST/BasicStatement.h
@@ -0,0 +1,23 @@
+/*
+ * BasicStatement.h
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#ifndef BASICSTATEMENT_H_
+#define BASICSTATEMENT_H_
+#include
+#include "ASTExpression.h"
+#include "ASTStatement.h"
+
+class BasicStatement : public ASTStatement {
+public:
+ BasicStatement(ASTNode * parent);
+ virtual std::string debug();
+ void add_expression(ASTExpression * expr);
+ virtual void execute();
+ virtual ~BasicStatement();
+};
+
+#endif /* BASICSTATEMENT_H_ */
diff --git a/Sencha-lang/AST/ConstantExpression.cpp b/Sencha-lang/AST/ConstantExpression.cpp
new file mode 100644
index 0000000..e913bea
--- /dev/null
+++ b/Sencha-lang/AST/ConstantExpression.cpp
@@ -0,0 +1,58 @@
+/*
+ * ConstantExpression.cpp
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#include "ConstantExpression.h"
+
+ConstantExpression::ConstantExpression(ASTNode * parent) {
+ this->parent = parent;
+ value = SenchaObject();
+}
+
+ConstantExpression::~ConstantExpression() {
+ // TODO Auto-generated destructor stub
+}
+
+ConstantExpression::ConstantExpression(ASTNode * parent, SenchaObject value, std::string name)
+{
+ this->parent = parent;
+ this->value = value;
+ this->value.name = name;
+}
+
+SenchaObject ConstantExpression::evaluate()
+{
+ return value;
+}
+
+void ConstantExpression::execute()
+{
+ std::cout << evaluate().repr() << std::endl;//Do nothing
+}
+
+void ConstantExpression::execute_quietly()
+{
+ evaluate();
+}
+
+
+ConstantExpression::ConstantExpression(ASTNode * parent, int number)
+{
+ this->parent = parent; value = SenchaObject(number);
+}
+
+ConstantExpression::ConstantExpression(ASTNode * parent, double number)
+{
+ this->parent = parent;
+ value = SenchaObject(number);
+}
+
+ConstantExpression::ConstantExpression(ASTNode * parent, std::string text)
+{
+ this->parent = parent; value = SenchaObject(text);
+}
+
+std::string ConstantExpression::debug() { return "Constant expression:\n" + value.repr() + "\n"; }
diff --git a/Sencha-lang/AST/ConstantExpression.h b/Sencha-lang/AST/ConstantExpression.h
new file mode 100644
index 0000000..ad28956
--- /dev/null
+++ b/Sencha-lang/AST/ConstantExpression.h
@@ -0,0 +1,32 @@
+/*
+ * ConstantExpression.h
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#ifndef CONSTANTEXPRESSION_H_
+#define CONSTANTEXPRESSION_H_
+#include "ASTExpression.h"
+#include
+
+class ConstantExpression : public ASTExpression {
+public:
+ ConstantExpression(ASTNode * parent);
+ ConstantExpression(ASTNode * parent, int number) ;
+ ConstantExpression(ASTNode * parent, double number) ;
+ ConstantExpression(ASTNode * parent, std::string text);
+ ConstantExpression(ASTNode * parent, SenchaObject value, std::string name);
+ SenchaObject value;
+
+ std::string debug();
+
+
+ virtual ~ConstantExpression();
+ 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
new file mode 100644
index 0000000..571c5e6
--- /dev/null
+++ b/Sencha-lang/AST/DeclarationStatement.cpp
@@ -0,0 +1,66 @@
+/*
+ * DeclarationStatement.cpp
+ *
+ * Created on: Dec 9, 2012
+ * Author: attero
+ */
+
+#include "DeclarationStatement.h"
+
+
+
+DeclarationStatement::~DeclarationStatement() {
+ // TODO Auto-generated destructor stub
+}
+
+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()
+{
+ std::string debug_note = "Declaration";
+ return debug_note;
+}
+
+void DeclarationStatement::add_name(std::string name)
+{
+ this->name = name;
+}
+
+
+void DeclarationStatement::add_argument(std::string name)
+{
+ arguments.push_back(name);
+}
+
+void DeclarationStatement::execute()
+{
+ if(is_function)
+ {
+ //TODO implement
+ //do function registering stuff
+ }
+ else
+ {
+ context->add(name, right_value);
+ children[0]->execute() ;
+ }
+}
+
+void DeclarationStatement::add_body(ASTStatement * statement)
+{
+ is_function = true;
+ body = statement;
+}
diff --git a/Sencha-lang/AST/DeclarationStatement.h b/Sencha-lang/AST/DeclarationStatement.h
new file mode 100644
index 0000000..573dc38
--- /dev/null
+++ b/Sencha-lang/AST/DeclarationStatement.h
@@ -0,0 +1,39 @@
+/*
+ * DeclarationStatement.h
+ *
+ * Created on: Dec 9, 2012
+ * Author: attero
+ */
+
+#ifndef DECLARATIONSTATEMENT_H_
+#define DECLARATIONSTATEMENT_H_
+
+#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 arguments;
+ bool is_function;
+
+ void add_right_value(ASTExpression * right);
+ DeclarationStatement(ASTNode * parent, Context * context);
+ virtual std::string debug();
+ void add_name(std::string);
+
+
+ void add_argument(std::string name);
+ void add_body(ASTStatement * statement);
+
+ virtual void execute();
+ virtual ~DeclarationStatement();
+};
+
+#endif /* DECLARATIONSTATEMENT_H_ */
diff --git a/Sencha-lang/AST/IncorrectExpression.cpp b/Sencha-lang/AST/IncorrectExpression.cpp
new file mode 100644
index 0000000..42d4411
--- /dev/null
+++ b/Sencha-lang/AST/IncorrectExpression.cpp
@@ -0,0 +1,24 @@
+/*
+ * IncorrectExpression.cpp
+ *
+ * Created on: Dec 6, 2012
+ * Author: attero
+ */
+
+#include "IncorrectExpression.h"
+
+IncorrectExpression::IncorrectExpression(ASTNode * parent, std::string error_message)
+{
+ this->parent = parent;
+ this->error_message = error_message;
+}
+
+IncorrectExpression::~IncorrectExpression() {
+ // TODO Auto-generated destructor stub
+}
+
+SenchaObject IncorrectExpression::evaluate()
+{
+ SenchaObject null_object;
+ return null_object;
+}
diff --git a/Sencha-lang/AST/IncorrectExpression.h b/Sencha-lang/AST/IncorrectExpression.h
new file mode 100644
index 0000000..cba11ae
--- /dev/null
+++ b/Sencha-lang/AST/IncorrectExpression.h
@@ -0,0 +1,31 @@
+/*
+ * IncorrectExpression.h
+ *
+ * Created on: Dec 6, 2012
+ * Author: attero
+ */
+
+#ifndef INCORRECTEXPRESSION_H_
+#define INCORRECTEXPRESSION_H_
+
+#include "ASTExpression.h"
+#include
+
+class IncorrectExpression: public ASTExpression {
+public:
+
+ std::string error_message;
+
+ 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);
+ virtual ~IncorrectExpression();
+};
+
+#endif /* INCORRECTEXPRESSION_H_ */
diff --git a/Sencha-lang/AST/LogicalExpression.cpp b/Sencha-lang/AST/LogicalExpression.cpp
new file mode 100644
index 0000000..554c696
--- /dev/null
+++ b/Sencha-lang/AST/LogicalExpression.cpp
@@ -0,0 +1,18 @@
+/*
+ * 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
+}
+
diff --git a/Sencha-lang/AST/LogicalExpression.h b/Sencha-lang/AST/LogicalExpression.h
new file mode 100644
index 0000000..816e560
--- /dev/null
+++ b/Sencha-lang/AST/LogicalExpression.h
@@ -0,0 +1,19 @@
+/*
+ * 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_ */
diff --git a/Sencha-lang/AST/PostfixExpression.cpp b/Sencha-lang/AST/PostfixExpression.cpp
new file mode 100644
index 0000000..dd0d27c
--- /dev/null
+++ b/Sencha-lang/AST/PostfixExpression.cpp
@@ -0,0 +1,46 @@
+/*
+ * PostfixExpression.cpp
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#include "PostfixExpression.h"
+
+PostfixExpression::PostfixExpression(ASTNode * parent) {
+ this->parent = parent;
+ head_set = false;
+ body_set = false;
+
+}
+
+PostfixExpression::~PostfixExpression() {
+ // TODO Auto-generated destructor stub
+}
+
+
+void PostfixExpression::set_head(ASTExpression * expression)
+{
+ //How should it look like?
+ head_set = true;
+}
+
+void PostfixExpression::add_argument(ASTExpression * expression)
+{
+ arguments.push_back(expression);
+}
+
+
+SenchaObject PostfixExpression::evaluate()
+{
+ return SenchaObject();
+}
+
+void PostfixExpression::execute() { evaluate(); }
+
+
+
+std::string PostfixExpression::debug()
+{
+ return "Postfix expression tadadah!";
+}
diff --git a/Sencha-lang/AST/PostfixExpression.h b/Sencha-lang/AST/PostfixExpression.h
new file mode 100644
index 0000000..1590123
--- /dev/null
+++ b/Sencha-lang/AST/PostfixExpression.h
@@ -0,0 +1,34 @@
+/*
+ * PostfixExpression.h
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#ifndef POSTFIXEXPRESSION_H_
+#define POSTFIXEXPRESSION_H_
+#include "ASTExpression.h"
+#include "ASTStatement.h"
+
+class PostfixExpression : public ASTExpression {
+public:
+
+ bool body_set;
+ bool head_set;
+ std::vector arguments;
+ void set_head(ASTExpression * expression);
+ void add_argument(ASTExpression * expression);
+
+ virtual SenchaObject evaluate();
+ virtual void execute();
+ virtual void execute_quietly(){//do nothing
+ };
+
+
+ std::string debug() ;
+
+ PostfixExpression(ASTNode * parent);
+ virtual ~PostfixExpression();
+};
+
+#endif /* POSTFIXEXPRESSION_H_ */
diff --git a/Sencha-lang/AST/ProgramNode.cpp b/Sencha-lang/AST/ProgramNode.cpp
index 3a7c316..8240529 100644
--- a/Sencha-lang/AST/ProgramNode.cpp
+++ b/Sencha-lang/AST/ProgramNode.cpp
@@ -17,5 +17,28 @@ ProgramNode::~ProgramNode() {
}
void ProgramNode::execute() {
- std::cout << "Program started!\n";
+ for (std::vector::iterator it = children.begin(); it!=children.end(); ++it) {
+ (*it)->execute();
+ }
}
+
+void ProgramNode::execute_last()
+{
+ children[children.size() -1]->execute();
+}
+
+std::string ProgramNode::debug()
+{
+ std::string debug_note = "Program started debugging\n";
+
+ for (std::vector::iterator it = children.begin(); it!=children.end(); ++it) {
+ debug_note += (*it)->debug() + "\n";
+ }
+ debug_note += "END\n";
+ return debug_note;
+}
+void ProgramNode::add_statement(ASTStatement * statement)
+{
+ children.push_back(statement);
+}
+
diff --git a/Sencha-lang/AST/ProgramNode.h b/Sencha-lang/AST/ProgramNode.h
index dec8bff..1232699 100644
--- a/Sencha-lang/AST/ProgramNode.h
+++ b/Sencha-lang/AST/ProgramNode.h
@@ -14,9 +14,11 @@
class ProgramNode : public ASTNode {
public:
ProgramNode();
- ASTStatement * add_child(ASTStatement * node);
+ std::string debug();
+ void add_statement(ASTStatement * statement);
virtual ~ProgramNode();
virtual void execute();
+ virtual void execute_last();
};
#endif /* PROGRAMNODE_H_ */
diff --git a/Sencha-lang/AST/SenchaObject.cpp b/Sencha-lang/AST/SenchaObject.cpp
new file mode 100644
index 0000000..89990b9
--- /dev/null
+++ b/Sencha-lang/AST/SenchaObject.cpp
@@ -0,0 +1,152 @@
+/*
+ * SenchaObject.cpp
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#include "SenchaObject.h"
+
+SenchaObject::SenchaObject() {
+ set_null_value();
+}
+
+SenchaObject::~SenchaObject() {
+ // TODO Auto-generated destructor stub
+}
+
+
+std::string SenchaObject::repr()
+{
+ std::string representation = "";
+ switch(type){
+ case string_literal:
+ representation = "type: string\n";
+ representation += this->text;
+ break;
+ case integer_number:
+ representation = "type: integer\n";
+ representation += to_string(this->integer);
+ break;
+ case float_number:
+ representation = "type: float\n";
+ representation += to_string(this->number);
+ break;
+ case null:
+ representation = "type: null\n";
+ representation += "null";
+ break;
+ case symbol:
+ representation = "type: symbol\n";
+ representation += this->text;
+ break;
+ case invalid:
+ representation = "type: invalid\n";
+ representation += "some crap";
+ break;
+ }
+ return representation;
+}
+
+SenchaObject SenchaObject::operator+(const SenchaObject& right)const
+{
+ SenchaObject result;
+ if(type == right.type)
+ {
+ switch(type){
+ case string_literal:
+ result.set_new_string(this->text + right.text);
+ break;
+ case integer_number:
+ result.set_value(this->integer + right.integer);
+ break;
+ case float_number:
+ result.set_value(this->number + right.number);
+ break;
+ }
+ }
+ else
+ {
+ result.type = invalid;
+ }
+
+ return result;
+
+}
+
+SenchaObject SenchaObject::operator-(const SenchaObject& right)const
+{
+ SenchaObject result;
+ if(type == right.type)
+ {
+ switch(type){
+ case string_literal:
+ result.type = invalid;
+ break;
+ case integer_number:
+ result.set_value(this->integer - right.integer);
+ break;
+ case float_number:
+ result.set_value(this->number - right.number);
+ break;
+ }
+ }
+ else
+ {
+ result.type = invalid;
+ }
+
+ return result;
+}
+
+SenchaObject SenchaObject::operator*(const SenchaObject& right)const
+{
+ SenchaObject result;
+ if(type == right.type)
+ {
+ switch(type){
+ case string_literal:
+ result.type = invalid;
+ break;
+ case integer_number:
+ result.set_value(this->integer * right.integer);
+ break;
+ case float_number:
+ result.set_value(this->number * right.number);
+ break;
+ }
+ }
+ else
+ {
+ result.type = invalid;
+ }
+
+ return result;
+}
+
+SenchaObject SenchaObject::operator/(const SenchaObject& right)const
+{
+ SenchaObject result;
+ if(type == right.type)
+ {
+ switch(type){
+ case string_literal:
+ result.type = invalid;
+ break;
+ case integer_number:
+ result.set_value(this->integer / right.integer);
+ break;
+ case float_number:
+ result.set_value(this->number / right.number);
+ break;
+ }
+ }
+ else
+ {
+ result.type = invalid;
+ }
+
+ return result;
+}
+
+//TODO change code above to something more generic
diff --git a/Sencha-lang/AST/SenchaObject.h b/Sencha-lang/AST/SenchaObject.h
new file mode 100644
index 0000000..f3db9c0
--- /dev/null
+++ b/Sencha-lang/AST/SenchaObject.h
@@ -0,0 +1,93 @@
+/*
+ * SenchaObject.h
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#ifndef SENCHAOBJECT_H_
+#define SENCHAOBJECT_H_
+#include
+#include
+#include "to_string.h"
+class SenchaObject {
+
+public:
+ typedef enum {
+ string_literal,
+ integer_number,
+ float_number,
+ null,
+ symbol,
+ boolean,
+ invalid
+ } Type;
+
+ Type type;
+
+ virtual std::string repr();
+
+ std::string text;
+ std::string name;
+ bool truthy;
+ int integer;
+ double number;
+
+ void set_value(std::string text)
+ {
+ if(text[0] == '\"' && text[text.size()-1] == '\"')
+ {
+ this->text = text.substr(1, text.size()-2);
+ type = string_literal;
+ }
+ }
+
+ void set_new_string(std::string text)
+ {
+ this->text = text;
+ type = string_literal;
+ }
+
+ void set_null_value()
+ {
+ this->type = null;
+ this->integer = 0;
+ this->number = 0;
+ this->text = "";
+ }
+
+ void set_value(int integer)
+ {
+ this->integer = integer;
+ type = integer_number;
+ }
+
+ void set_value(double number)
+ {
+ this->number = number;
+ type = float_number;
+ }
+
+ void set_value(bool logic)
+ {
+ this->truthy = logic;
+ type = boolean;
+ }
+
+ SenchaObject();
+ SenchaObject(int integer) { set_value(integer); }
+ SenchaObject(bool truthy) {set_value(truthy); }
+ SenchaObject(double number) { set_value(number); }
+ SenchaObject(std::string text) { set_value(text); }
+
+ //TODO overload operators as it should be done
+
+ virtual SenchaObject operator+(const SenchaObject& right)const;
+ virtual SenchaObject operator-(const SenchaObject& right)const;
+ virtual SenchaObject operator*(const SenchaObject& right)const;
+ virtual SenchaObject operator/(const SenchaObject& right)const;
+
+ virtual ~SenchaObject();
+};
+
+#endif /* SENCHAOBJECT_H_ */
diff --git a/Sencha-lang/AST/to_string.h b/Sencha-lang/AST/to_string.h
new file mode 100644
index 0000000..62f0639
--- /dev/null
+++ b/Sencha-lang/AST/to_string.h
@@ -0,0 +1,24 @@
+/*
+ * to_string.h
+ *
+ * Created on: Dec 5, 2012
+ * Author: attero
+ */
+
+#ifndef TO_STRING_H_
+#define TO_STRING_H_
+
+#include
+
+
+
+template
+inline std::string to_string (const T& t)
+{
+std::stringstream ss;
+ss << t;
+return ss.str();
+}
+
+
+#endif /* TO_STRING_H_ */
diff --git a/Sencha-lang/ASTExpression.cpp b/Sencha-lang/ASTExpression.cpp
deleted file mode 100644
index 32a47d8..0000000
--- a/Sencha-lang/ASTExpression.cpp
+++ /dev/null
@@ -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
-}
-
diff --git a/Sencha-lang/ASTExpression.h b/Sencha-lang/ASTExpression.h
deleted file mode 100644
index 69010ae..0000000
--- a/Sencha-lang/ASTExpression.h
+++ /dev/null
@@ -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_ */
diff --git a/Sencha-lang/ASTNode.cpp b/Sencha-lang/ASTNode.cpp
deleted file mode 100644
index 80429c2..0000000
--- a/Sencha-lang/ASTNode.cpp
+++ /dev/null
@@ -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
-}
-
diff --git a/Sencha-lang/ASTNode.h b/Sencha-lang/ASTNode.h
deleted file mode 100644
index b0145a3..0000000
--- a/Sencha-lang/ASTNode.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ASTNode.h
- *
- * Created on: Nov 4, 2012
- * Author: attero
- */
-
-#ifndef ASTNODE_H_
-#define ASTNODE_H_
-#include
-
-class ASTNode {
-public:
- ASTNode();
- ASTNode * parent;
- std::vector children;
- void add_children(ASTNode *);
- void remove_most_right_children();
- void set_parent(ASTNode *);
- virtual void execute() = 0;
- virtual ~ASTNode();
-};
-
-#endif /* ASTNODE_H_ */
diff --git a/Sencha-lang/ASTPrimary.cpp b/Sencha-lang/ASTPrimary.cpp
deleted file mode 100644
index c442ec5..0000000
--- a/Sencha-lang/ASTPrimary.cpp
+++ /dev/null
@@ -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
-}
-
-
diff --git a/Sencha-lang/ASTPrimary.h b/Sencha-lang/ASTPrimary.h
deleted file mode 100644
index 9387a0a..0000000
--- a/Sencha-lang/ASTPrimary.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * ASTPrimary.h
- *
- * Created on: Nov 4, 2012
- * Author: attero
- */
-
-#ifndef ASTPRIMARY_H_
-#define ASTPRIMARY_H_
-#include "ASTNode.h"
-#include
-
-class ASTPrimary : public ASTNode {
-public:
- ASTPrimary(ASTNode * parent);
-
- virtual ~ASTPrimary();
- virtual void execute() {};
- std::string value;
-
-};
-
-#endif /* ASTPRIMARY_H_ */
diff --git a/Sencha-lang/ASTProgram.cpp b/Sencha-lang/ASTProgram.cpp
deleted file mode 100644
index 8b74923..0000000
--- a/Sencha-lang/ASTProgram.cpp
+++ /dev/null
@@ -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";
-}
diff --git a/Sencha-lang/ASTProgram.h b/Sencha-lang/ASTProgram.h
deleted file mode 100644
index f83bbf3..0000000
--- a/Sencha-lang/ASTProgram.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * ASTProgram.h
- *
- * Created on: Nov 5, 2012
- * Author: attero
- */
-
-#ifndef ASTPROGRAM_H_
-#define ASTPROGRAM_H_
-#include
-#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_ */
diff --git a/Sencha-lang/ASTStatement.cpp b/Sencha-lang/ASTStatement.cpp
deleted file mode 100644
index 52c5526..0000000
--- a/Sencha-lang/ASTStatement.cpp
+++ /dev/null
@@ -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
-}
-
diff --git a/Sencha-lang/ASTStatement.h b/Sencha-lang/ASTStatement.h
deleted file mode 100644
index b2bfd84..0000000
--- a/Sencha-lang/ASTStatement.h
+++ /dev/null
@@ -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_ */
diff --git a/Sencha-lang/AllTypesOfASTNodes.h b/Sencha-lang/AllTypesOfASTNodes.h
deleted file mode 100644
index 61051e6..0000000
--- a/Sencha-lang/AllTypesOfASTNodes.h
+++ /dev/null
@@ -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_ */
diff --git a/Sencha-lang/Context.cpp b/Sencha-lang/Context.cpp
new file mode 100644
index 0000000..24802f7
--- /dev/null
+++ b/Sencha-lang/Context.cpp
@@ -0,0 +1,65 @@
+/*
+ * Context.cpp
+ *
+ * Created on: Dec 7, 2012
+ * Author: attero
+ */
+
+#include "Context.h"
+
+Context::Context() {
+ // TODO Auto-generated constructor stub
+ index = 0;
+}
+
+Context::~Context() {
+ // TODO Auto-generated destructor stub
+}
+
+ObjectIndex Context::add_to_store(SenchaObject & object)
+{
+ index++;
+ object_store[index] = object;
+
+ return index;
+}
+
+SenchaObject Context::get_from_store(ObjectIndex index)
+{
+ return object_store[index];
+}
+
+void Context::add(std::string name, SenchaObject object)
+{
+ interpreter_context[name] = add_to_store(object);
+}
+
+void Context::set(std::string name, SenchaObject object)
+{
+ if(interpreter_context[name] != 0)
+ {
+ object_store[interpreter_context[name]] = object;
+ }
+ else
+ {
+ add(name, object);
+
+ }
+}
+
+SenchaObject Context::get(std::string name)
+{
+ return get_from_store(interpreter_context[name]);
+}
+
+std::string Context::debug() {
+ std::string debug_note = "";
+
+ for( auto iter = this->interpreter_context.begin(); iter != this->interpreter_context.end(); iter++)
+ {
+ debug_note += "Context: " + to_string((*iter).second) + ": " + (*iter).first + " " + object_store[(*iter).second].repr() + "\n";
+ }
+ return debug_note;
+
+
+ }
diff --git a/Sencha-lang/Context.h b/Sencha-lang/Context.h
new file mode 100644
index 0000000..be21e92
--- /dev/null
+++ b/Sencha-lang/Context.h
@@ -0,0 +1,44 @@
+/*
+ * Context.h
+ *
+ * Created on: Dec 7, 2012
+ * Author: attero
+ */
+
+#ifndef CONTEXT_H_
+#define CONTEXT_H_
+#include