Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / Expression.cpp
diff options
context:
space:
mode:
Commit3cc222dbe45296ba81fb4a6dc6c8df7075ddbee7 (patch)
Author
 martin dobrev <martindobrev0@gmail.com>
2018-09-08 12:24:03 +0300
Committer
 martin dobrev <martindobrev0@gmail.com>
2018-09-08 12:24:03 +0300
Filesb5989bc293c6a7a99debb50562d9714d71e651a3 /JSImpl/src/Expression.cpp
IPL-3cc222dbe45296ba81fb4a6dc6c8df7075ddbee7.tar
IPL-3cc222dbe45296ba81fb4a6dc6c8df7075ddbee7.tar.gz
IPL-3cc222dbe45296ba81fb4a6dc6c8df7075ddbee7.zip
Parentb91b7d3820deb7e0aed536141cd79e7a8c4ca8c9 (diff)
Implement List and Identifier expressions.
1 files changed, 42 insertions, 5 deletions
-rw-r--r--JSImpl/src/Expression.cpp47
diff --git a/JSImpl/src/Expression.cpp b/JSImpl/src/Expression.cpp
index 522f896..3bd6612 100644
--- a/JSImpl/src/Expression.cpp
+++ b/JSImpl/src/Expression.cpp
@@ -1,4 +1,5 @@
#include "Expression.h"
+#include <assert.h>
BinaryExpression::BinaryExpression(IPLSharedPtr<Expression> exprLeft, IPLSharedPtr<Expression> exprRight, TokenType op)
: m_Left(exprLeft)
@@ -26,8 +27,6 @@ void BinaryExpression::Print(std::ostream& os)
os << "\n}\n";
}
-
-
UnaryExpression::UnaryExpression(IPLSharedPtr<Expression> expr, TokenType op, bool suffix)
: m_Expr(expr)
, m_Operator(op)
@@ -82,9 +81,21 @@ LiteralExpression::LiteralExpression(bool v)
, m_BooleanValue(v)
{}
-LiteralExpression::LiteralExpression(LiteralType type)
- : m_Type(type)
-{}
+LiteralExpression::LiteralExpression(TokenType type)
+{
+ if (type == TokenType::Null)
+ {
+ m_Type = LiteralType::Null;
+ }
+ else if (type == TokenType::Undefined)
+ {
+ m_Type = LiteralType::Undefined;
+ }
+ else
+ {
+ assert(false);
+ }
+}
void LiteralExpression::Print(std::ostream& os)
{
@@ -117,3 +128,29 @@ void LiteralExpression::Print(std::ostream& os)
os << "\n}\n";
}
+
+IdentifierExpression::IdentifierExpression(IPLString name, ExpressionPtr value)
+ : m_Name(name)
+ , m_Value(value)
+{
+}
+
+void IdentifierExpression::Print(std::ostream& os)
+{
+ os << "{ \n";
+ os << " Expression Type: Identifier" << std::endl;
+ os << "Identifier name: " << m_Name << std::endl;
+ m_Value->Print(os);
+ os << "\n}\n";
+}
+
+void ListExpression::Print(std::ostream& os)
+{
+ os << "{ \n";
+ os << " Expression Type: List" << std::endl;
+ for (auto& e : m_Values)
+ {
+ e->Print(os);
+ }
+ os << "\n}\n";
+} \ No newline at end of file