summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Elements
diff options
context:
space:
mode:
Diffstat (limited to 'Sencha-lang/Elements')
-rw-r--r--Sencha-lang/Elements/Element.h4
-rw-r--r--Sencha-lang/Elements/SenchaArray.h23
-rw-r--r--Sencha-lang/Elements/SenchaFunction.h14
-rw-r--r--Sencha-lang/Elements/SenchaObject.cpp84
-rw-r--r--Sencha-lang/Elements/SenchaObject.h13
5 files changed, 108 insertions, 30 deletions
diff --git a/Sencha-lang/Elements/Element.h b/Sencha-lang/Elements/Element.h
index 3377c9a..8805a71 100644
--- a/Sencha-lang/Elements/Element.h
+++ b/Sencha-lang/Elements/Element.h
@@ -8,6 +8,10 @@
#ifndef ELEMENT_H_
#define ELEMENT_H_
+/**
+ * Basic element in sencha language design. Actually now it does nothing.
+ * It'd be changed in further versions.
+ */
class Element
{
public:
diff --git a/Sencha-lang/Elements/SenchaArray.h b/Sencha-lang/Elements/SenchaArray.h
index d100553..9632536 100644
--- a/Sencha-lang/Elements/SenchaArray.h
+++ b/Sencha-lang/Elements/SenchaArray.h
@@ -11,20 +11,35 @@
#include "Element.h"
#include "../ContextManager.h"
+/**
+ * SenchaArray is an abstraction of array element in a language.
+ * It provides access to its elements and some basic methods.
+ * It uses context_manager to evaluate its elements. SenchaArray is created on the go and stored nowhere.
+ */
class SenchaArray: public Element {
public:
+ /**
+ * Basic, universal constructor.
+ */
SenchaArray(std::string name, ContextManager * context_manager);
+
+ /**
+ * Special constructor, used to deal with strings
+ */
SenchaArray(std::string name, ContextManager * context_manager, std::string);
- ContextManager * context_manager;
- std::string name;
+
typedef int IndexNumber;
IndexNumber add(SenchaObject value);
void set(IndexNumber index, SenchaObject value);
- IndexNumber max_index;
SenchaObject get(IndexNumber index);
- //lots of stuff
virtual ~SenchaArray();
+private:
+ ContextManager * context_manager;
+ std::string name;
+ IndexNumber max_index;
+
+
};
#endif /* SENCHAARRAY_H_ */
diff --git a/Sencha-lang/Elements/SenchaFunction.h b/Sencha-lang/Elements/SenchaFunction.h
index 184f84c..e009df2 100644
--- a/Sencha-lang/Elements/SenchaFunction.h
+++ b/Sencha-lang/Elements/SenchaFunction.h
@@ -15,19 +15,23 @@
#include "../Utils/to_string.h"
#include "../AST/ASTNode.h"
-
+/**
+ * SenchaFunction is a class which is an abstraction of function written in SenchaLang.
+ * It stores name of the function, its body, and provides () call operator.
+ */
class SenchaFunction : public Element
{
public:
+ SenchaFunction(std::string name, std::vector<std::string> names_of_arguments, ASTNode * body);
+ SenchaObject operator()();
std::string name;
std::vector<std::string> names_of_arguments;
+ virtual ~SenchaFunction();
+private:
- ASTNode * body;
- SenchaFunction(std::string name, std::vector<std::string> names_of_arguments, ASTNode * body);
- SenchaObject operator()();
- virtual ~SenchaFunction();
+ ASTNode * body;
};
#endif /* SENCHAFUNCTION_H_ */
diff --git a/Sencha-lang/Elements/SenchaObject.cpp b/Sencha-lang/Elements/SenchaObject.cpp
index 5a22bb1..5031171 100644
--- a/Sencha-lang/Elements/SenchaObject.cpp
+++ b/Sencha-lang/Elements/SenchaObject.cpp
@@ -91,10 +91,6 @@ std::string SenchaObject::repr()
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";
@@ -122,9 +118,6 @@ std::string SenchaObject::str()
case null:
representation += "null";
break;
- case symbol:
- representation += this->text;
- break;
case invalid:
representation += "some crap";
break;
@@ -150,6 +143,15 @@ SenchaObject SenchaObject::operator+(const SenchaObject& right)const
case float_number:
result.set_value(this->number + right.number);
break;
+ case boolean:
+ result.type = invalid;
+ break;
+ case invalid:
+ result.type = invalid;
+ break;
+ case null:
+ result.type = invalid;
+ break;
}
}
else if(type == float_number && right.type == integer_number )
@@ -184,6 +186,15 @@ SenchaObject SenchaObject::operator-(const SenchaObject& right)const
case float_number:
result.set_value(this->number - right.number);
break;
+ case boolean:
+ result.type = invalid;
+ break;
+ case invalid:
+ result.type = invalid;
+ break;
+ case null:
+ result.type = invalid;
+ break;
}
}
else if(type == float_number && right.type == integer_number )
@@ -217,6 +228,15 @@ SenchaObject SenchaObject::operator*(const SenchaObject& right)const
case float_number:
result.set_value(this->number * right.number);
break;
+ case boolean:
+ result.type = invalid;
+ break;
+ case invalid:
+ result.type = invalid;
+ break;
+ case null:
+ result.type = invalid;
+ break;
}
}
else if(type == float_number && right.type == integer_number )
@@ -250,6 +270,15 @@ SenchaObject SenchaObject::operator/(const SenchaObject& right)const
case float_number:
result.set_value(this->number / right.number);
break;
+ case boolean:
+ result.type = invalid;
+ break;
+ case invalid:
+ result.type = invalid;
+ break;
+ case null:
+ result.type = invalid;
+ break;
}
}
else if(type == float_number && right.type == integer_number )
@@ -269,7 +298,7 @@ SenchaObject SenchaObject::operator/(const SenchaObject& right)const
}
SenchaObject SenchaObject::operator==(const SenchaObject& right)const
- {
+ {
SenchaObject result;
bool value = false;
result.type = boolean;
@@ -301,15 +330,21 @@ SenchaObject SenchaObject::operator==(const SenchaObject& right)const
value = true;
}
break;
+ case invalid:
+ result.type = invalid;
+ break;
+ case null:
+ result.type = invalid;
+ break;
}
}
result.truthy = value;
return result;
- }
+ }
SenchaObject SenchaObject::operator!=(const SenchaObject& right) const
-{
+ {
SenchaObject result;
result.type = boolean;
@@ -319,7 +354,7 @@ SenchaObject SenchaObject::operator!=(const SenchaObject& right) const
else result.truthy = true;
return result;
-}
+ }
SenchaObject SenchaObject::operator>(const SenchaObject& right) const
@@ -349,23 +384,32 @@ SenchaObject SenchaObject::operator>(const SenchaObject& right) const
value = true;
}
break;
+ case invalid:
+ result.type = invalid;
+ break;
+ case boolean:
+ result.type = invalid;
+ break;
+ case null:
+ result.type = invalid;
+ break;
}
}
else if(type == float_number && right.type == integer_number )
- {
- value = (this->number > right.integer);
- }
- else if(type == integer_number && right.type == float_number)
- {
- value = (this->integer > right.number);
- }
+ {
+ value = (this->number > right.integer);
+ }
+ else if(type == integer_number && right.type == float_number)
+ {
+ value = (this->integer > right.number);
+ }
result.truthy = value;
return result;
}
SenchaObject SenchaObject::operator>= (const SenchaObject& right) const
-{
+ {
SenchaObject result;
bool value = false;
result.type = boolean;
@@ -376,7 +420,7 @@ SenchaObject SenchaObject::operator>= (const SenchaObject& right) const
}
result.truthy = value;
return result;
-}
+ }
SenchaObject SenchaObject::operator< (const SenchaObject& right) const
{
diff --git a/Sencha-lang/Elements/SenchaObject.h b/Sencha-lang/Elements/SenchaObject.h
index 55d8501..6b062a9 100644
--- a/Sencha-lang/Elements/SenchaObject.h
+++ b/Sencha-lang/Elements/SenchaObject.h
@@ -12,21 +12,31 @@
#include "../Utils/to_string.h"
#include "Element.h"
+
+/**
+ * SenchaObject stores values in SenchaLang. It handles operations on them, thanks to defined, overloaded operators.
+ * Also provides representation of values.
+ */
class SenchaObject : public Element {
public:
+ /**
+ * Possible types of SenchaObject
+ */
typedef enum {
string_literal,
integer_number,
float_number,
null,
- symbol,
boolean,
invalid
} Type;
Type type;
+ /**
+ * repr() returns representation of value as a string
+ */
virtual std::string repr();
virtual std::string str();
virtual bool is_true();
@@ -51,6 +61,7 @@ public:
SenchaObject(std::string text) { set_value(text); }
+ //Operators used in expressions
virtual SenchaObject operator< (const SenchaObject& right)const;
virtual SenchaObject operator> (const SenchaObject& right)const;
virtual SenchaObject operator<= (const SenchaObject& right)const;