diff options
author | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-22 15:43:51 +0100 |
---|---|---|
committer | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-22 15:43:51 +0100 |
commit | eed99251607f90025d6d11c2077fcd09d0ade8b9 (patch) | |
tree | eab0b6454382d3616a76ab98d409ad304b1caa10 | |
parent | c6e3678f15338085d737c58c2057dcd1891f4310 (diff) | |
download | sencha-lang-eed99251607f90025d6d11c2077fcd09d0ade8b9.tar.gz sencha-lang-eed99251607f90025d6d11c2077fcd09d0ade8b9.tar.bz2 sencha-lang-eed99251607f90025d6d11c2077fcd09d0ade8b9.tar.xz sencha-lang-eed99251607f90025d6d11c2077fcd09d0ade8b9.zip |
Operators like <=, > work now. Only logical are left know.
-rw-r--r-- | Sencha-lang/AST/BasicExpression.cpp | 16 | ||||
-rw-r--r-- | Sencha-lang/AST/SenchaObject.cpp | 93 | ||||
-rw-r--r-- | Sencha-lang/AST/SenchaObject.h | 6 | ||||
-rw-r--r-- | Sencha-lang/ASTInspector.cpp | 2 |
4 files changed, 112 insertions, 5 deletions
diff --git a/Sencha-lang/AST/BasicExpression.cpp b/Sencha-lang/AST/BasicExpression.cpp index 3787a72..b67ab5f 100644 --- a/Sencha-lang/AST/BasicExpression.cpp +++ b/Sencha-lang/AST/BasicExpression.cpp @@ -90,6 +90,22 @@ SenchaObject BasicExpression::evaluate() { so = SenchaObject(right != left); } + 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(left < right); + } return so; } diff --git a/Sencha-lang/AST/SenchaObject.cpp b/Sencha-lang/AST/SenchaObject.cpp index 81d859a..61930dc 100644 --- a/Sencha-lang/AST/SenchaObject.cpp +++ b/Sencha-lang/AST/SenchaObject.cpp @@ -223,7 +223,7 @@ SenchaObject SenchaObject::operator/(const SenchaObject& right)const } SenchaObject SenchaObject::operator==(const SenchaObject& right)const - { + { SenchaObject result; bool value = false; result.type = boolean; @@ -254,10 +254,10 @@ SenchaObject SenchaObject::operator==(const SenchaObject& right)const result.truthy = value; return result; - } + } -SenchaObject SenchaObject::operator!=(const SenchaObject& right)const - { +SenchaObject SenchaObject::operator!=(const SenchaObject& right) const +{ SenchaObject result; result.type = boolean; @@ -267,6 +267,91 @@ SenchaObject SenchaObject::operator!=(const SenchaObject& right)const else result.truthy = true; return result; +} + + +SenchaObject SenchaObject::operator>(const SenchaObject& right) const +{ + SenchaObject result; + bool value = false; + result.type = boolean; + + if(type == right.type) + { + switch(type){ + case string_literal: + if(this->text > right.text) + { + value = true; + } + break; + case integer_number: + if(this->integer > right.integer) + { + value = true; + } + break; + case float_number: + if(this->number > right.number) + { + value = true; + } + 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); + } + + result.truthy = value; + return result; +} + +SenchaObject SenchaObject::operator>= (const SenchaObject& right) const +{ + SenchaObject result; + bool value = false; + result.type = boolean; + + if((*this == right).truthy || ((*this) > right).truthy) + { + value = true; + } + result.truthy = value; + return result; +} + +SenchaObject SenchaObject::operator< (const SenchaObject& right) const +{ + SenchaObject result; + bool value = false; + result.type = boolean; + + if(!((*this) >= right).truthy) + { + value = true; + } + result.truthy = value; + return result; +} + +SenchaObject SenchaObject::operator<= (const SenchaObject& right) const +{ + SenchaObject result; + bool value = false; + result.type = boolean; + + if(!((*this) > right).truthy) + { + value = true; + } + result.truthy = value; + return result; +} //TODO change code above to something more generic diff --git a/Sencha-lang/AST/SenchaObject.h b/Sencha-lang/AST/SenchaObject.h index 3d5eec2..96cef58 100644 --- a/Sencha-lang/AST/SenchaObject.h +++ b/Sencha-lang/AST/SenchaObject.h @@ -82,8 +82,11 @@ public: 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 operator+(const SenchaObject& right)const; virtual SenchaObject operator-(const SenchaObject& right)const; virtual SenchaObject operator*(const SenchaObject& right)const; @@ -92,6 +95,7 @@ public: virtual SenchaObject operator!=(const SenchaObject& right)const; + virtual ~SenchaObject(); }; diff --git a/Sencha-lang/ASTInspector.cpp b/Sencha-lang/ASTInspector.cpp index 6c92c48..5dd32da 100644 --- a/Sencha-lang/ASTInspector.cpp +++ b/Sencha-lang/ASTInspector.cpp @@ -289,6 +289,8 @@ void ASTInspector::visit(VariableExpression * variable) visit_notes += "VariableExpression:\n"; visit_notes += "Name: " + variable->name + "\n"; + visit_notes += "Currently has a value:\n"; + visit_notes += variable->evaluate().repr(); write_report(visit_notes); write_report("End of VariableExpression\n"); |