From 560a585091f1948efb47d58c82dede281ebef54d Mon Sep 17 00:00:00 2001 From: martin dobrev Date: Fri, 7 Sep 2018 19:00:01 +0300 Subject: Introduce Parser and Expression hierarchy. --- JSImpl/src/Expression.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 JSImpl/src/Expression.h (limited to 'JSImpl/src/Expression.h') 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 +{ + + public: + virtual ~Expression() {} + virtual void Print(std::ostream& os) {}; +}; + +using ExpressionPtr = IPLSharedPtr; + +// binary:= expression operator expression +class BinaryExpression : public Expression +{ +public: + virtual ~BinaryExpression() {} + BinaryExpression(IPLSharedPtr exprLeft, IPLSharedPtr exprRight, TokenType op); + virtual void Print(std::ostream& os); +private: + IPLString GetBinaryTypeAsString(); +private: + IPLSharedPtr m_Left; + IPLSharedPtr m_Right; + TokenType m_Operator; +}; + +// binary:= expression operator | +// operator expression +class UnaryExpression : public Expression +{ +public: + virtual ~UnaryExpression() {} + UnaryExpression(IPLSharedPtr expr, TokenType op, bool suffix); + virtual void Print(std::ostream& os); +private: + IPLString GetBinaryTypeAsString(); +private: + IPLSharedPtr 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; +}; + -- cgit v1.3.1-23-gd82d