src/parser.h

changeset 134
eca2fc0acaa2
parent 133
dbbdb870c835
child 135
8b9132fea327
equal deleted inserted replaced
133:dbbdb870c835 134:eca2fc0acaa2
106 Writability writelevel; 106 Writability writelevel;
107 int value; 107 int value;
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
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 BotscriptParser();
156 { 156 ~BotscriptParser();
157 eNoReset, 157 void parseBotscript (String fileName);
158 SCOPE_Reset, 158 DataBuffer* parseCommand (CommandInfo* comm);
159 }; 159 DataBuffer* parseAssignment (Variable* var);
160 160 AssignmentOperator parseAssignmentOperator();
161 BotscriptParser(); 161 String parseFloat();
162 ~BotscriptParser(); 162 void pushScope (bool noreset = false);
163 void parseBotscript (String fileName); 163 DataBuffer* parseStatement();
164 DataBuffer* parseCommand (CommandInfo* comm); 164 void addSwitchCase (DataBuffer* b);
165 DataBuffer* parseAssignment (Variable* var); 165 void checkToplevel();
166 AssignmentOperator parseAssignmentOperator(); 166 void checkNotToplevel();
167 String parseFloat(); 167 bool tokenIs (Token a);
168 void pushScope (EReset reset = SCOPE_Reset); 168 String getTokenString();
169 DataBuffer* parseStatement(); 169 String describePosition() const;
170 void addSwitchCase (DataBuffer* b); 170 void writeToFile (String outfile);
171 void checkToplevel(); 171 Variable* findVariable (const String& name);
172 void checkNotToplevel(); 172 bool isInGlobalState() const;
173 bool tokenIs (ETokenType a); 173 void suggestHighestVarIndex (bool global, int index);
174 String getTokenString(); 174 int getHighestVarIndex (bool global);
175 String describePosition() const; 175
176 void writeToFile (String outfile); 176 inline ScopeInfo& scope (int offset)
177 Variable* findVariable (const String& name); 177 {
178 bool isInGlobalState() const; 178 return m_scopeStack[m_scopeCursor - offset];
179 void suggestHighestVarIndex (bool global, int index); 179 }
180 int getHighestVarIndex (bool global); 180
181 181 inline int numEvents() const
182 inline ScopeInfo& scope (int offset) 182 {
183 { 183 return m_numEvents;
184 return m_scopeStack[m_scopeCursor - offset]; 184 }
185 } 185
186 186 inline int numStates() const
187 inline int numEvents() const 187 {
188 { 188 return m_numStates;
189 return m_numEvents; 189 }
190 } 190
191 191 private:
192 inline int numStates() const 192 // The main buffer - the contents of this is what we
193 { 193 // write to file after parsing is complete
194 return m_numStates; 194 DataBuffer* m_mainBuffer;
195 } 195
196 196 // onenter buffer - the contents of the onenter {} block
197 private: 197 // is buffered here and is merged further at the end of state
198 // The main buffer - the contents of this is what we 198 DataBuffer* m_onenterBuffer;
199 // write to file after parsing is complete 199
200 DataBuffer* m_mainBuffer; 200 // Mainloop buffer - the contents of the mainloop {} block
201 201 // is buffered here and is merged further at the end of state
202 // onenter buffer - the contents of the onenter {} block 202 DataBuffer* m_mainLoopBuffer;
203 // is buffered here and is merged further at the end of state 203
204 DataBuffer* m_onenterBuffer; 204 // Switch buffer - switch case data is recorded to this
205 205 // buffer initially, instead of into main buffer.
206 // Mainloop buffer - the contents of the mainloop {} block 206 DataBuffer* m_switchBuffer;
207 // is buffered here and is merged further at the end of state 207
208 DataBuffer* m_mainLoopBuffer; 208 Lexer* m_lexer;
209 209 int m_numStates;
210 // Switch buffer - switch case data is recorded to this 210 int m_numEvents;
211 // buffer initially, instead of into main buffer. 211 ParserMode m_currentMode;
212 DataBuffer* m_switchBuffer; 212 String m_currentState;
213 213 bool m_isStateSpawnDefined;
214 Lexer* m_lexer; 214 bool m_gotMainLoop;
215 int m_numStates; 215 int m_scopeCursor;
216 int m_numEvents; 216 bool m_isElseAllowed;
217 ParserMode m_currentMode; 217 int m_highestGlobalVarIndex;
218 String m_currentState; 218 int m_highestStateVarIndex;
219 bool m_isStateSpawnDefined; 219 int m_numWrittenBytes;
220 bool m_gotMainLoop; 220 List<ScopeInfo> m_scopeStack;
221 int m_scopeCursor; 221 int m_zandronumVersion;
222 bool m_isElseAllowed; 222 bool m_defaultZandronumVersion;
223 int m_highestGlobalVarIndex; 223
224 int m_highestStateVarIndex; 224 DataBuffer* currentBuffer();
225 int m_numWrittenBytes; 225 void parseStateBlock();
226 List<ScopeInfo> m_scopeStack; 226 void parseEventBlock();
227 int m_zandronumVersion; 227 void parseMainloop();
228 bool m_defaultZandronumVersion; 228 void parseOnEnterExit();
229 229 void parseVar();
230 DataBuffer* currentBuffer(); 230 void parseGoto();
231 void parseStateBlock(); 231 void parseIf();
232 void parseEventBlock(); 232 void parseElse();
233 void parseMainloop(); 233 void parseWhileBlock();
234 void parseOnEnterExit(); 234 void parseForBlock();
235 void parseVar(); 235 void parseDoBlock();
236 void parseGoto(); 236 void parseSwitchBlock();
237 void parseIf(); 237 void parseSwitchCase();
238 void parseElse(); 238 void parseSwitchDefault();
239 void parseWhileBlock(); 239 void parseBreak();
240 void parseForBlock(); 240 void parseContinue();
241 void parseDoBlock(); 241 void parseBlockEnd();
242 void parseSwitchBlock(); 242 void parseLabel();
243 void parseSwitchCase(); 243 void parseEventdef();
244 void parseSwitchDefault(); 244 void parseFuncdef();
245 void parseBreak(); 245 void parseUsing();
246 void parseContinue(); 246 void writeMemberBuffers();
247 void parseBlockEnd(); 247 void writeStringTable();
248 void parseLabel(); 248 DataBuffer* parseExpression (DataType reqtype, bool fromhere = false);
249 void parseEventdef(); 249 DataHeader getAssigmentDataHeader (AssignmentOperator op, Variable* var);
250 void parseFuncdef();
251 void parseUsing();
252 void writeMemberBuffers();
253 void writeStringTable();
254 DataBuffer* parseExpression (DataType reqtype, bool fromhere = false);
255 DataHeader getAssigmentDataHeader (AssignmentOperator op, Variable* var);
256 }; 250 };
257 251
258 #endif // BOTC_PARSER_H 252 #endif // BOTC_PARSER_H

mercurial