src/Expression.h

changeset 91
427eb377d53e
child 92
3a00d396bce2
equal deleted inserted replaced
90:90ab2f2b3dc0 91:427eb377d53e
1 #ifndef BOTC_EXPRESSION_H
2 #define BOTC_EXPRESSION_H
3 #include "Parser.h"
4
5 class DataBuffer;
6 class ExpressionSymbol;
7 class ExpressionValue;
8
9 // =============================================================================
10 //
11 class Expression final
12 {
13 public:
14 Expression (BotscriptParser* parser, EType reqtype, Lexer* lx);
15 ~Expression();
16 ExpressionValue* GetResult();
17
18 private:
19 Lexer* mLexer;
20 List<ExpressionSymbol*> mSymbols;
21 EType mType;
22 ExpressionValue* mResult;
23 BotscriptParser* mParser;
24
25 ExpressionValue* Evaluate(); // Process the expression and yield a result
26 ExpressionSymbol* ParseSymbol();
27 String GetTokenString();
28 void Verify(); // Ensure the expr is valid
29 };
30
31 // =============================================================================
32 //
33 class ExpressionSymbol
34 {
35 public:
36 enum EExpressionSymbolType
37 {
38 eOperator,
39 eOperand,
40 eColon,
41 };
42
43 PROPERTY (private, EExpressionSymbolType, Type, NO_OPS, STOCK_WRITE)
44 };
45
46 // =============================================================================
47 //
48 class ExpressionOperator final : public ExpressionSymbol
49 {
50 PROPERTY (public, int, ID, NO_OPS, STOCK_WRITE)
51
52 public:
53 ExpressionOperator (int id);
54 };
55
56 // =============================================================================
57 //
58 class ExpressionValue final : public ExpressionSymbol
59 {
60 PROPERTY (public, int, Value, BOOL_OPS, STOCK_WRITE)
61 PROPERTY (public, DataBuffer*, Buffer, NO_OPS, STOCK_WRITE)
62 PROPERTY (public, EType, ValueType, NO_OPS, STOCK_WRITE)
63
64 public:
65 ExpressionValue (EType valuetype);
66
67 void ConvertToBuffer();
68
69 inline bool IsConstexpr() const
70 {
71 return GetBuffer() == null;
72 }
73 };
74
75 // =============================================================================
76 //
77 // This class represents a ":" in the expression. It serves as the colon for the
78 // ternary ?: operator. It's not an operand nor is an operator, nor can we just
79 // skip it so it is its own thing here.
80 //
81 class ExpressionColon final : public ExpressionSymbol
82 {
83 public:
84 ExpressionColon() :
85 mType (eColon) {}
86 };
87
88 #endif // BOTC_EXPRESSION_H

mercurial