src/Parser.h

changeset 115
9be16e1c1e44
parent 112
def56932f938
child 116
56ff19947607
equal deleted inserted replaced
114:6cbeb9f8350f 115:9be16e1c1e44
108 String origin; 108 String origin;
109 bool isarray; 109 bool isarray;
110 110
111 inline bool IsGlobal() const 111 inline bool IsGlobal() const
112 { 112 {
113 return statename.IsEmpty(); 113 return statename.isEmpty();
114 } 114 }
115 }; 115 };
116 116
117 // ============================================================================ 117 // ============================================================================
118 // 118 //
147 147
148 // ============================================================================ 148 // ============================================================================
149 // 149 //
150 class BotscriptParser 150 class BotscriptParser
151 { 151 {
152 PROPERTY (public, bool, IsReadOnly, SetReadOnly, STOCK_WRITE) 152 PROPERTY (public, bool, isReadOnly, setReadOnly, STOCK_WRITE)
153 153
154 public: 154 public:
155 enum EReset 155 enum EReset
156 { 156 {
157 eNoReset, 157 eNoReset,
158 SCOPE_Reset, 158 SCOPE_Reset,
159 }; 159 };
160 160
161 BotscriptParser(); 161 BotscriptParser();
162 ~BotscriptParser(); 162 ~BotscriptParser();
163 void ParseBotscript (String fileName); 163 void parseBotscript (String fileName);
164 DataBuffer* ParseCommand (CommandInfo* comm); 164 DataBuffer* parseCommand (CommandInfo* comm);
165 DataBuffer* ParseAssignment (Variable* var); 165 DataBuffer* parseAssignment (Variable* var);
166 AssignmentOperator ParseAssignmentOperator(); 166 AssignmentOperator parseAssignmentOperator();
167 String ParseFloat(); 167 String parseFloat();
168 void PushScope (EReset reset = SCOPE_Reset); 168 void pushScope (EReset reset = SCOPE_Reset);
169 DataBuffer* ParseStatement(); 169 DataBuffer* parseStatement();
170 void AddSwitchCase (DataBuffer* b); 170 void addSwitchCase (DataBuffer* b);
171 void CheckToplevel(); 171 void checkToplevel();
172 void CheckNotToplevel(); 172 void checkNotToplevel();
173 bool TokenIs (ETokenType a); 173 bool tokenIs (ETokenType a);
174 String GetTokenString(); 174 String getTokenString();
175 String DescribePosition() const; 175 String describePosition() const;
176 void WriteToFile (String outfile); 176 void writeToFile (String outfile);
177 Variable* FindVariable (const String& name); 177 Variable* findVariable (const String& name);
178 bool IsInGlobalState() const; 178 bool isInGlobalState() const;
179 void SuggestHighestVarIndex (bool global, int index); 179 void suggestHighestVarIndex (bool global, int index);
180 int GetHighestVarIndex (bool global); 180 int getHighestVarIndex (bool global);
181 181
182 inline ScopeInfo& GSCOPE_t (int offset) 182 inline ScopeInfo& scope (int offset)
183 { 183 {
184 return mScopeStack[mScopeCursor - offset]; 184 return m_scopeStack[m_scopeCursor - offset];
185 } 185 }
186 186
187 inline int GetNumEvents() const 187 inline int numEvents() const
188 { 188 {
189 return mNumEvents; 189 return m_numEvents;
190 } 190 }
191 191
192 inline int GetNumStates() const 192 inline int numStates() const
193 { 193 {
194 return mNumStates; 194 return m_numStates;
195 } 195 }
196 196
197 private: 197 private:
198 // The main buffer - the contents of this is what we 198 // The main buffer - the contents of this is what we
199 // write to file after parsing is complete 199 // write to file after parsing is complete
200 DataBuffer* mMainBuffer; 200 DataBuffer* m_mainBuffer;
201 201
202 // onenter buffer - the contents of the onenter{} block 202 // onenter buffer - the contents of the onenter {} block
203 // is buffered here and is merged further at the end of state 203 // is buffered here and is merged further at the end of state
204 DataBuffer* mOnEnterBuffer; 204 DataBuffer* m_onenterBuffer;
205 205
206 // Mainloop buffer - the contents of the mainloop{} block 206 // Mainloop buffer - the contents of the mainloop {} block
207 // is buffered here and is merged further at the end of state 207 // is buffered here and is merged further at the end of state
208 DataBuffer* mMainLoopBuffer; 208 DataBuffer* m_mainLoopBuffer;
209 209
210 // Switch buffer - switch case data is recorded to this 210 // Switch buffer - switch case data is recorded to this
211 // buffer initially, instead of into main buffer. 211 // buffer initially, instead of into main buffer.
212 DataBuffer* mSwitchBuffer; 212 DataBuffer* m_switchBuffer;
213 213
214 Lexer* mLexer; 214 Lexer* m_lexer;
215 int mNumStates; 215 int m_numStates;
216 int mNumEvents; 216 int m_numEvents;
217 ParserMode mCurrentMode; 217 ParserMode m_currentMode;
218 String mCurrentState; 218 String m_currentState;
219 bool mStateSpawnDefined; 219 bool m_isStateSpawnDefined;
220 bool mGotMainLoop; 220 bool m_gotMainLoop;
221 int mScopeCursor; 221 int m_scopeCursor;
222 bool mCanElse; 222 bool m_isElseAllowed;
223 int mHighestGlobalVarIndex; 223 int m_highestGlobalVarIndex;
224 int mHighestStateVarIndex; 224 int m_highestStateVarIndex;
225 225 int m_numWrittenBytes;
226 // How many bytes have we written to file? 226 List<ScopeInfo> m_scopeStack;
227 int mNumWrittenBytes; 227
228 228 DataBuffer* currentBuffer();
229 // Scope data 229 void parseStateBlock();
230 List<ScopeInfo> mScopeStack; 230 void parseEventBlock();
231 231 void parseMainloop();
232 DataBuffer* buffer(); 232 void parseOnEnterExit();
233 void ParseStateBlock(); 233 void parseVar();
234 void ParseEventBlock(); 234 void parseGoto();
235 void ParseMainloop(); 235 void parseIf();
236 void ParseOnEnterExit(); 236 void parseElse();
237 void ParseVar(); 237 void parseWhileBlock();
238 void ParseGoto(); 238 void parseForBlock();
239 void ParseIf(); 239 void parseDoBlock();
240 void ParseElse(); 240 void parseSwitchBlock();
241 void ParseWhileBlock(); 241 void parseSwitchCase();
242 void ParseForBlock(); 242 void parseSwitchDefault();
243 void ParseDoBlock(); 243 void parseBreak();
244 void ParseSwitchBlock(); 244 void parseContinue();
245 void ParseSwitchCase(); 245 void parseBlockEnd();
246 void ParseSwitchDefault(); 246 void parseLabel();
247 void ParseBreak(); 247 void parseEventdef();
248 void ParseContinue(); 248 void parseFuncdef();
249 void ParseBlockEnd();
250 void ParseLabel();
251 void ParseEventdef();
252 void ParseFuncdef();
253 void writeMemberBuffers(); 249 void writeMemberBuffers();
254 void WriteStringTable(); 250 void writeStringTable();
255 DataBuffer* ParseExpression (DataType reqtype, bool fromhere = false); 251 DataBuffer* parseExpression (DataType reqtype, bool fromhere = false);
256 DataHeader GetAssigmentDataHeader (AssignmentOperator op, Variable* var); 252 DataHeader getAssigmentDataHeader (AssignmentOperator op, Variable* var);
257 }; 253 };
258 254
259 #endif // BOTC_PARSER_H 255 #endif // BOTC_PARSER_H

mercurial