summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/AST
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-01 18:05:35 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-01 18:05:35 +0100
commitd65e408e5545963852df43cea93d9c82cd6b8f68 (patch)
tree33353b6c709b35322f127659cd21811ceea7279b /Sencha-lang/AST
parent4526de47cfbcc121e7bb09187b1641c060651322 (diff)
downloadsencha-lang-d65e408e5545963852df43cea93d9c82cd6b8f68.tar.gz
sencha-lang-d65e408e5545963852df43cea93d9c82cd6b8f68.tar.bz2
sencha-lang-d65e408e5545963852df43cea93d9c82cd6b8f68.tar.xz
sencha-lang-d65e408e5545963852df43cea93d9c82cd6b8f68.zip
Functions seem to work. Additionaly unary expressions :>.functions
Diffstat (limited to 'Sencha-lang/AST')
-rw-r--r--Sencha-lang/AST/AllTypesOfASTNodes.h1
-rw-r--r--Sencha-lang/AST/UnaryExpression.cpp31
-rw-r--r--Sencha-lang/AST/UnaryExpression.h28
3 files changed, 60 insertions, 0 deletions
diff --git a/Sencha-lang/AST/AllTypesOfASTNodes.h b/Sencha-lang/AST/AllTypesOfASTNodes.h
index 52cb8df..e926cd2 100644
--- a/Sencha-lang/AST/AllTypesOfASTNodes.h
+++ b/Sencha-lang/AST/AllTypesOfASTNodes.h
@@ -24,6 +24,7 @@
#include "WhileNode.h"
#include "RepeatStatement.h"
#include "VariableExpression.h"
+#include "UnaryExpression.h"
//And probably more
//TODO actualize it
diff --git a/Sencha-lang/AST/UnaryExpression.cpp b/Sencha-lang/AST/UnaryExpression.cpp
new file mode 100644
index 0000000..47ef287
--- /dev/null
+++ b/Sencha-lang/AST/UnaryExpression.cpp
@@ -0,0 +1,31 @@
+/*
+ * UnaryExpression.cpp
+ *
+ * Created on: Jan 1, 2013
+ * Author: att
+ */
+
+#include "UnaryExpression.h"
+
+UnaryExpression::UnaryExpression(ASTNode * argument, std::string oper) {
+ type = "UnaryExpression";
+ children.push_back(argument);
+ this->oper = oper;
+}
+
+UnaryExpression::~UnaryExpression() {
+ // TODO Auto-generated destructor stub
+}
+
+SenchaObject UnaryExpression::execute()
+{
+ auto argument = children[0];
+ if(oper == "-") return - argument->execute();
+ else if(oper == "!") return ! argument->execute();
+ else return SenchaObject();
+}
+
+SenchaObject UnaryExpression::evaluate()
+{
+ return execute();
+}
diff --git a/Sencha-lang/AST/UnaryExpression.h b/Sencha-lang/AST/UnaryExpression.h
new file mode 100644
index 0000000..7511d36
--- /dev/null
+++ b/Sencha-lang/AST/UnaryExpression.h
@@ -0,0 +1,28 @@
+/*
+ * UnaryExpression.h
+ *
+ * Created on: Jan 1, 2013
+ * Author: att
+ */
+
+#ifndef UNARYEXPRESSION_H_
+#define UNARYEXPRESSION_H_
+
+#include "ASTExpression.h"
+
+class UnaryExpression: public ASTExpression {
+public:
+
+ std::string oper;
+ std::string get_operator() { return oper; }
+ virtual void accept(Visitor * visitor) { visitor->visit(this); }
+
+ virtual SenchaObject execute();
+ virtual SenchaObject evaluate();
+
+ UnaryExpression(ASTNode * argument, std::string oper);
+ UnaryExpression();
+ virtual ~UnaryExpression();
+};
+
+#endif /* UNARYEXPRESSION_H_ */