src/Expression.h

changeset 108
6409ece8297c
parent 106
9174be9ac686
child 112
def56932f938
equal deleted inserted replaced
107:55c2bcd8ed5c 108:6409ece8297c
7 class ExpressionValue; 7 class ExpressionValue;
8 class ExpressionOperator; 8 class ExpressionOperator;
9 9
10 // ============================================================================= 10 // =============================================================================
11 // 11 //
12 enum EOperator 12 named_enum ExpressionOperatorType
13 { 13 {
14 opNegateLogical, 14 OPER_NegateLogical,
15 opUnaryMinus, 15 OPER_UnaryMinus,
16 opMultiplication, 16 OPER_Multiplication,
17 opDivision, 17 OPER_Division,
18 opModulus, 18 OPER_Modulus,
19 opAddition, 19 OPER_Addition,
20 opSubtraction, 20 OPER_Subtraction,
21 opLeftShift, 21 OPER_LeftShift,
22 opRightShift, 22 OPER_RightShift,
23 opCompareLesser, 23 OPER_CompareLesser,
24 opCompareGreater, 24 OPER_CompareGreater,
25 opCompareAtLeast, 25 OPER_CompareAtLeast,
26 opCompareAtMost, 26 OPER_CompareAtMost,
27 opCompareEquals, 27 OPER_CompareEquals,
28 opCompareNotEquals, 28 OPER_CompareNotEquals,
29 opBitwiseAnd, 29 OPER_BitwiseAnd,
30 opBitwiseXOr, 30 OPER_BitwiseXOr,
31 opBitwiseOr, 31 OPER_BitwiseOr,
32 opLogicalAnd, 32 OPER_LogicalAnd,
33 opLogicalOr, 33 OPER_LogicalOr,
34 opTernary, 34 OPER_Ternary,
35 }; 35 };
36 36
37 // ============================================================================= 37 // =============================================================================
38 // 38 //
39 enum ExpressionSymbolType
40 {
41 EXPRSYM_Operator,
42 EXPRSYM_Value,
43 EXPRSYM_Colon,
44 };
45
39 class Expression final 46 class Expression final
40 { 47 {
41 public: 48 public:
42 enum ESymbolType
43 {
44 eOperatorSymbol,
45 eValueSymbol,
46 eColonSymbol,
47 };
48
49 using SymbolList = List<ExpressionSymbol*>; 49 using SymbolList = List<ExpressionSymbol*>;
50 50
51 Expression (BotscriptParser* parser, Lexer* lx, EType reqtype); 51 Expression (BotscriptParser* parser, Lexer* lx, DataType reqtype);
52 ~Expression(); 52 ~Expression();
53 ExpressionValue* GetResult(); 53 ExpressionValue* GetResult();
54 54
55 private: 55 private:
56 BotscriptParser* mParser; 56 BotscriptParser* mParser;
57 Lexer* mLexer; 57 Lexer* mLexer;
58 SymbolList mSymbols; 58 SymbolList mSymbols;
59 EType mType; 59 DataType mType;
60 String mBadTokenText; 60 String mBadTokenText;
61 61
62 ExpressionValue* Evaluate(); // Process the expression and yield a result 62 ExpressionValue* Evaluate(); // Process the expression and yield a result
63 ExpressionSymbol* ParseSymbol(); 63 ExpressionSymbol* ParseSymbol();
64 String GetTokenString(); 64 String GetTokenString();
73 // ============================================================================= 73 // =============================================================================
74 // 74 //
75 class ExpressionSymbol 75 class ExpressionSymbol
76 { 76 {
77 public: 77 public:
78 ExpressionSymbol (Expression::ESymbolType type) : 78 ExpressionSymbol (ExpressionSymbolType type) :
79 mType (type) {} 79 mType (type) {}
80 80
81 PROPERTY (private, Expression::ESymbolType, Type, NO_OPS, STOCK_WRITE) 81 PROPERTY (private, ExpressionSymbolType, Type, NO_OPS, STOCK_WRITE)
82 }; 82 };
83 83
84 // ============================================================================= 84 // =============================================================================
85 // 85 //
86 class ExpressionOperator final : public ExpressionSymbol 86 class ExpressionOperator final : public ExpressionSymbol
87 { 87 {
88 PROPERTY (public, EOperator, ID, NO_OPS, STOCK_WRITE) 88 PROPERTY (public, ExpressionOperatorType, ID, NO_OPS, STOCK_WRITE)
89 89
90 public: 90 public:
91 ExpressionOperator (EOperator id); 91 ExpressionOperator (ExpressionOperatorType id);
92 }; 92 };
93 93
94 // ============================================================================= 94 // =============================================================================
95 // 95 //
96 class ExpressionValue final : public ExpressionSymbol 96 class ExpressionValue final : public ExpressionSymbol
97 { 97 {
98 PROPERTY (public, int, Value, NUM_OPS, STOCK_WRITE) 98 PROPERTY (public, int, Value, NUM_OPS, STOCK_WRITE)
99 PROPERTY (public, DataBuffer*, Buffer, NO_OPS, STOCK_WRITE) 99 PROPERTY (public, DataBuffer*, Buffer, NO_OPS, STOCK_WRITE)
100 PROPERTY (public, EType, ValueType, NO_OPS, STOCK_WRITE) 100 PROPERTY (public, DataType, ValueType, NO_OPS, STOCK_WRITE)
101 101
102 public: 102 public:
103 ExpressionValue (EType valuetype); 103 ExpressionValue (DataType valuetype);
104 ~ExpressionValue(); 104 ~ExpressionValue();
105 105
106 void ConvertToBuffer(); 106 void ConvertToBuffer();
107 107
108 inline ExpressionValue* Clone() const 108 inline ExpressionValue* Clone() const
117 }; 117 };
118 118
119 // ============================================================================= 119 // =============================================================================
120 // 120 //
121 // This class represents a ":" in the expression. It serves as the colon for the 121 // This class represents a ":" in the expression. It serves as the colon for the
122 // ternary ?: operator. It's not an operand nor is an operator, nor can we just 122 // ternary ?: OPER_erator. It's not an OPER_erand nor is an OPER_erator, nor can we just
123 // skip it so it is its own thing here. 123 // skip it so it is its own thing here.
124 // 124 //
125 class ExpressionColon final : public ExpressionSymbol 125 class ExpressionColon final : public ExpressionSymbol
126 { 126 {
127 public: 127 public:
128 ExpressionColon() : 128 ExpressionColon() :
129 ExpressionSymbol (Expression::eColonSymbol) {} 129 ExpressionSymbol (EXPRSYM_Colon) {}
130 }; 130 };
131 131
132 #endif // BOTC_EXPRESSION_H 132 #endif // BOTC_EXPRESSION_H

mercurial