summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-12-08 22:33:34 +0100
committerJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-12-08 22:33:34 +0100
commit01614b2bf42d3e0140b90b213b8168759f2113da (patch)
tree0e89f4bd0b13f7a15dae636a0da8ca5f54461639
parentbdd319ecb8081146f19a40294c9bf4b7fa0010c5 (diff)
downloadsencha-lang-01614b2bf42d3e0140b90b213b8168759f2113da.tar.gz
sencha-lang-01614b2bf42d3e0140b90b213b8168759f2113da.tar.bz2
sencha-lang-01614b2bf42d3e0140b90b213b8168759f2113da.tar.xz
sencha-lang-01614b2bf42d3e0140b90b213b8168759f2113da.zip
handles variables, doing calculations and adding strings
-rw-r--r--Sencha-lang/AST/BasicExpression.cpp4
-rw-r--r--Sencha-lang/AST/ConstantExpression.cpp4
-rw-r--r--Sencha-lang/AST/ConstantExpression.h5
-rw-r--r--Sencha-lang/AST/LogicalExpression.cpp18
-rw-r--r--Sencha-lang/AST/LogicalExpression.h19
-rw-r--r--Sencha-lang/AST/SenchaObject.cpp2
-rw-r--r--Sencha-lang/AST/SenchaObject.h17
-rwxr-xr-xSencha-lang/Debug/Sencha-langbin1199842 -> 1207961 bytes
-rw-r--r--Sencha-lang/Parser.cpp1
9 files changed, 63 insertions, 7 deletions
diff --git a/Sencha-lang/AST/BasicExpression.cpp b/Sencha-lang/AST/BasicExpression.cpp
index 76f4be8..a6f9136 100644
--- a/Sencha-lang/AST/BasicExpression.cpp
+++ b/Sencha-lang/AST/BasicExpression.cpp
@@ -44,8 +44,8 @@ void BasicExpression::set_right_operand(ASTNode * right)
}
void BasicExpression::execute()
{
- children[0]->execute();
- children[1]->execute();
+ //children[0]->execute();
+ //children[1]->execute();
std::cout << evaluate().repr() << std::endl;
}
diff --git a/Sencha-lang/AST/ConstantExpression.cpp b/Sencha-lang/AST/ConstantExpression.cpp
index c151688..78937ca 100644
--- a/Sencha-lang/AST/ConstantExpression.cpp
+++ b/Sencha-lang/AST/ConstantExpression.cpp
@@ -28,6 +28,10 @@ SenchaObject ConstantExpression::evaluate()
return value;
}
+void ConstantExpression::execute() {
+ std::cout << evaluate().repr() << std::endl;//Do nothing
+ };
+
ConstantExpression::ConstantExpression(ASTNode * parent, int number)
{
this->parent = parent; value = SenchaObject(number);
diff --git a/Sencha-lang/AST/ConstantExpression.h b/Sencha-lang/AST/ConstantExpression.h
index 4078e24..e02392e 100644
--- a/Sencha-lang/AST/ConstantExpression.h
+++ b/Sencha-lang/AST/ConstantExpression.h
@@ -8,6 +8,7 @@
#ifndef CONSTANTEXPRESSION_H_
#define CONSTANTEXPRESSION_H_
#include "ASTExpression.h"
+#include <iostream>
class ConstantExpression : public ASTExpression {
public:
@@ -20,11 +21,11 @@ public:
std::string debug();
- virtual void execute() { //Do nothing
- };
virtual ~ConstantExpression();
virtual SenchaObject evaluate();
+
+ virtual void execute() ;
};
#endif /* CONSTANTEXPRESSION_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/SenchaObject.cpp b/Sencha-lang/AST/SenchaObject.cpp
index 0ccfd6a..89990b9 100644
--- a/Sencha-lang/AST/SenchaObject.cpp
+++ b/Sencha-lang/AST/SenchaObject.cpp
@@ -55,7 +55,7 @@ SenchaObject SenchaObject::operator+(const SenchaObject& right)const
{
switch(type){
case string_literal:
- result.set_value(this->text + right.text);
+ result.set_new_string(this->text + right.text);
break;
case integer_number:
result.set_value(this->integer + right.integer);
diff --git a/Sencha-lang/AST/SenchaObject.h b/Sencha-lang/AST/SenchaObject.h
index 350ff43..f3db9c0 100644
--- a/Sencha-lang/AST/SenchaObject.h
+++ b/Sencha-lang/AST/SenchaObject.h
@@ -8,6 +8,7 @@
#ifndef SENCHAOBJECT_H_
#define SENCHAOBJECT_H_
#include <string>
+#include <iostream>
#include "to_string.h"
class SenchaObject {
@@ -18,6 +19,7 @@ public:
float_number,
null,
symbol,
+ boolean,
invalid
} Type;
@@ -27,6 +29,7 @@ public:
std::string text;
std::string name;
+ bool truthy;
int integer;
double number;
@@ -39,6 +42,12 @@ public:
}
}
+ void set_new_string(std::string text)
+ {
+ this->text = text;
+ type = string_literal;
+ }
+
void set_null_value()
{
this->type = null;
@@ -59,11 +68,17 @@ public:
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); }
- //SenchaObject(std::string name, int i) {this->name = name; type = symbol;}
//TODO overload operators as it should be done
diff --git a/Sencha-lang/Debug/Sencha-lang b/Sencha-lang/Debug/Sencha-lang
index fb7d9be..da85945 100755
--- a/Sencha-lang/Debug/Sencha-lang
+++ b/Sencha-lang/Debug/Sencha-lang
Binary files differ
diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp
index 302706c..143cc1c 100644
--- a/Sencha-lang/Parser.cpp
+++ b/Sencha-lang/Parser.cpp
@@ -169,7 +169,6 @@ ASTStatement * Parser::statement(ASTNode * parent)
if(accept(";"))
{
- cout << "dupa blada" << endl;
context->add(identifier, SenchaObject());
report("Variable definition\n");
stat->add_expression(new ConstantExpression(stat, SenchaObject(), identifier));