Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / Expression.h
diff options
context:
space:
mode:
Commit560a585091f1948efb47d58c82dede281ebef54d (patch)
Author
 martin dobrev <martindobrev0@gmail.com>
2018-09-07 19:00:01 +0300
Committer
 martin dobrev <martindobrev0@gmail.com>
2018-09-07 19:00:01 +0300
Filese62ac68d4fe03881be70b7ce6f400fb0a63060a9 /JSImpl/src/Expression.h
IPL-560a585091f1948efb47d58c82dede281ebef54d.tar
IPL-560a585091f1948efb47d58c82dede281ebef54d.tar.gz
IPL-560a585091f1948efb47d58c82dede281ebef54d.zip
Parent23067c0e3a92d452c1f8f3519c64d970a27732e3 (diff)
Introduce Parser and Expression hierarchy.
1 files changed, 71 insertions, 0 deletions
-rw-r--r--JSImpl/src/Expression.h71
diff --git a/JSImpl/src/Expression.h b/JSImpl/src/Expression.h
new file mode 100644
index 0000000..f2ad3e6
--- /dev/null
+++ b/JSImpl/src/Expression.h
@@ -0,0 +1,71 @@
+#pragma once
+
+#include "CommonTypes.h"
+#include "Lexer.h"
+
+class Expression : public IPLEnableShared<Expression>
+{
+
+ public:
+ virtual ~Expression() {}
+ virtual void Print(std::ostream& os) {};
+};
+
+using ExpressionPtr = IPLSharedPtr<Expression>;
+
+// binary:= expression operator expression
+class BinaryExpression : public Expression
+{
+public:
+ virtual ~BinaryExpression() {}
+ BinaryExpression(IPLSharedPtr<Expression> exprLeft, IPLSharedPtr<Expression> exprRight, TokenType op);
+ virtual void Print(std::ostream& os);
+private:
+ IPLString GetBinaryTypeAsString();
+private:
+ IPLSharedPtr<Expression> m_Left;
+ IPLSharedPtr<Expression> m_Right;
+ TokenType m_Operator;
+};
+
+// binary:= expression operator |
+// operator expression
+class UnaryExpression : public Expression
+{
+public:
+ virtual ~UnaryExpression() {}
+ UnaryExpression(IPLSharedPtr<Expression> expr, TokenType op, bool suffix);
+ virtual void Print(std::ostream& os);
+private:
+ IPLString GetBinaryTypeAsString();
+private:
+ IPLSharedPtr<Expression> m_Expr;
+ TokenType m_Operator;
+ bool m_Suffix;
+};
+
+// literal:= number | string | true | false | null | undefined
+class LiteralExpression : public Expression
+{
+public:
+ enum LiteralType
+ {
+ Number,
+ String,
+ Boolean,
+ Null,
+ Undefined,
+ };
+ virtual ~LiteralExpression() {}
+ LiteralExpression(double);
+ LiteralExpression(IPLString&);
+ LiteralExpression(bool);
+ LiteralExpression(LiteralType type);
+ virtual void Print(std::ostream& os);
+private:
+ double m_NumValue;
+ IPLString m_StringValue;
+ bool m_BooleanValue;
+ LiteralType m_Type;
+};
+