From 3cc222dbe45296ba81fb4a6dc6c8df7075ddbee7 Mon Sep 17 00:00:00 2001 From: martin dobrev Date: Sat, 8 Sep 2018 12:24:03 +0300 Subject: Implement List and Identifier expressions. --- JSImpl/src/Expression.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'JSImpl/src/Expression.cpp') 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 BinaryExpression::BinaryExpression(IPLSharedPtr exprLeft, IPLSharedPtr exprRight, TokenType op) : m_Left(exprLeft) @@ -26,8 +27,6 @@ void BinaryExpression::Print(std::ostream& os) os << "\n}\n"; } - - UnaryExpression::UnaryExpression(IPLSharedPtr 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 -- cgit v1.3.1-23-gd82d