Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src
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
IPL-3cc222dbe45296ba81fb4a6dc6c8df7075ddbee7.tar
IPL-3cc222dbe45296ba81fb4a6dc6c8df7075ddbee7.tar.gz
IPL-3cc222dbe45296ba81fb4a6dc6c8df7075ddbee7.zip
Parentb91b7d3820deb7e0aed536141cd79e7a8c4ca8c9 (diff)
Implement List and Identifier expressions.
2 files changed, 65 insertions, 6 deletions
-rw-r--r--JSImpl/src/Expression.cpp47
-rw-r--r--JSImpl/src/Expression.h24
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
diff --git a/JSImpl/src/Expression.h b/JSImpl/src/Expression.h
index c16157a..3b68522 100644
--- a/JSImpl/src/Expression.h
+++ b/JSImpl/src/Expression.h
@@ -60,7 +60,7 @@ public:
LiteralExpression(double);
LiteralExpression(IPLString&);
LiteralExpression(bool);
- LiteralExpression(LiteralType type);
+ LiteralExpression(TokenType type);
virtual void Print(std::ostream& os);
private:
double m_NumValue;
@@ -69,3 +69,25 @@ private:
LiteralType m_Type;
};
+
+class IdentifierExpression : public Expression
+{
+public:
+ IdentifierExpression(IPLString name, ExpressionPtr value);
+ virtual ~IdentifierExpression() {}
+ virtual void Print(std::ostream& os);
+private:
+ IPLString m_Name;
+ ExpressionPtr m_Value;
+};
+
+class ListExpression : public Expression
+{
+public:
+ ListExpression() {};
+ void Push(ExpressionPtr value) { m_Values.push_back(value); };
+ virtual ~ListExpression() {}
+ virtual void Print(std::ostream& os);
+private:
+ IPLVector<ExpressionPtr> m_Values;
+};