54 }; |
54 }; |
55 |
55 |
56 // ============================================================================ |
56 // ============================================================================ |
57 // Mark types |
57 // Mark types |
58 // |
58 // |
59 enum eMarkType |
59 named_enum MarkType |
60 { |
60 { |
61 eLabelMark, |
61 MARK_Label, |
62 eIfMark, |
62 MARK_If, |
63 eInternalMark, // internal structures |
63 MARK_Internal, // internal structures |
64 }; |
64 }; |
65 |
65 |
66 // ============================================================================ |
66 // ============================================================================ |
67 // Scope types |
67 // Scope types |
68 // |
68 // |
69 enum EScopeType |
69 named_enum ScopeType |
70 { |
70 { |
71 eUnknownScope, |
71 SCOPE_Unknown, |
72 eIfScope, |
72 SCOPE_If, |
73 eWhileScope, |
73 SCOPE_While, |
74 eForScope, |
74 SCOPE_For, |
75 eDoScope, |
75 SCOPE_Do, |
76 eSwitchScope, |
76 SCOPE_Switch, |
77 eElseScope, |
77 SCOPE_Else, |
78 }; |
78 }; |
79 |
79 |
80 enum EAssignmentOperator |
80 named_enum AssignmentOperator |
81 { |
81 { |
82 EAssign, |
82 ASSIGNOP_Assign, |
83 EAssignAdd, |
83 ASSIGNOP_Add, |
84 EAssignSub, |
84 ASSIGNOP_Subtract, |
85 EAssignMul, |
85 ASSIGNOP_Multiply, |
86 EAssignDiv, |
86 ASSIGNOP_Divide, |
87 EAssignMod, |
87 ASSIGNOP_Modulus, |
88 EAssignIncrement, |
88 ASSIGNOP_Increase, |
89 EAssignDecrement, |
89 ASSIGNOP_Decrease, |
|
90 }; |
|
91 |
|
92 named_enum Writability |
|
93 { |
|
94 WRITE_Mutable, // normal read-many-write-many variable |
|
95 WRITE_Const, // write-once const variable |
|
96 WRITE_Constexpr, // const variable whose value is known to compiler |
|
97 }; |
|
98 |
|
99 // ============================================================================= |
|
100 // |
|
101 // Parser mode: where is the parser at? |
|
102 // |
|
103 named_enum ParserMode |
|
104 { |
|
105 PARSERMODE_TopLevel, // at top level |
|
106 PARSERMODE_Event, // inside event definition |
|
107 PARSERMODE_MainLoop, // inside mainloop |
|
108 PARSERMODE_Onenter, // inside onenter |
|
109 PARSERMODE_Onexit, // inside onexit |
90 }; |
110 }; |
91 |
111 |
92 // ============================================================================ |
112 // ============================================================================ |
93 // |
113 // |
94 struct Variable |
114 struct Variable |
95 { |
115 { |
96 enum EWritability |
|
97 { |
|
98 WRITE_Mutable, // normal read-many-write-many variable |
|
99 WRITE_Const, // write-once const variable |
|
100 WRITE_Constexpr, // const variable whose value is known to compiler |
|
101 }; |
|
102 |
|
103 String name; |
116 String name; |
104 String statename; |
117 String statename; |
105 EType type; |
118 DataType type; |
106 int index; |
119 int index; |
107 EWritability writelevel; |
120 Writability writelevel; |
108 int value; |
121 int value; |
109 String origin; |
122 String origin; |
110 bool isarray; |
123 bool isarray; |
111 |
124 |
112 inline bool IsGlobal() const |
125 inline bool IsGlobal() const |
154 |
167 |
155 public: |
168 public: |
156 enum EReset |
169 enum EReset |
157 { |
170 { |
158 eNoReset, |
171 eNoReset, |
159 eResetScope, |
172 SCOPE_Reset, |
160 }; |
173 }; |
161 |
174 |
162 BotscriptParser(); |
175 BotscriptParser(); |
163 ~BotscriptParser(); |
176 ~BotscriptParser(); |
164 void ParseBotscript (String fileName); |
177 void ParseBotscript (String fileName); |
165 DataBuffer* ParseCommand (CommandInfo* comm); |
178 DataBuffer* ParseCommand (CommandInfo* comm); |
166 DataBuffer* ParseAssignment (Variable* var); |
179 DataBuffer* ParseAssignment (Variable* var); |
167 EAssignmentOperator ParseAssignmentOperator (); |
180 AssignmentOperator ParseAssignmentOperator(); |
168 String ParseFloat(); |
181 String ParseFloat(); |
169 void PushScope (EReset reset = eResetScope); |
182 void PushScope (EReset reset = SCOPE_Reset); |
170 DataBuffer* ParseStatement(); |
183 DataBuffer* ParseStatement(); |
171 void AddSwitchCase (DataBuffer* b); |
184 void AddSwitchCase (DataBuffer* b); |
172 void CheckToplevel(); |
185 void CheckToplevel(); |
173 void CheckNotToplevel(); |
186 void CheckNotToplevel(); |
174 bool TokenIs (EToken a); |
187 bool TokenIs (EToken a); |
178 Variable* FindVariable (const String& name); |
191 Variable* FindVariable (const String& name); |
179 bool IsInGlobalState() const; |
192 bool IsInGlobalState() const; |
180 void SuggestHighestVarIndex (bool global, int index); |
193 void SuggestHighestVarIndex (bool global, int index); |
181 int GetHighestVarIndex (bool global); |
194 int GetHighestVarIndex (bool global); |
182 |
195 |
183 inline ScopeInfo& GetScope (int offset) |
196 inline ScopeInfo& GSCOPE_t (int offset) |
184 { |
197 { |
185 return mScopeStack[mScopeCursor - offset]; |
198 return mScopeStack[mScopeCursor - offset]; |
186 } |
199 } |
187 |
200 |
188 inline int GetNumEvents() const |
201 inline int GetNumEvents() const |
252 void ParseLabel(); |
265 void ParseLabel(); |
253 void ParseEventdef(); |
266 void ParseEventdef(); |
254 void ParseFuncdef(); |
267 void ParseFuncdef(); |
255 void writeMemberBuffers(); |
268 void writeMemberBuffers(); |
256 void WriteStringTable(); |
269 void WriteStringTable(); |
257 DataBuffer* ParseExpression (EType reqtype, bool fromhere = false); |
270 DataBuffer* ParseExpression (DataType reqtype, bool fromhere = false); |
258 EDataHeader GetAssigmentDataHeader (EAssignmentOperator op, Variable* var); |
271 DataHeader GetAssigmentDataHeader (AssignmentOperator op, Variable* var); |
259 }; |
272 }; |
260 |
273 |
261 #endif // BOTC_PARSER_H |
274 #endif // BOTC_PARSER_H |