parser.cxx

changeset 25
2a600af97c6b
parent 24
7dcc8419dbdb
child 26
54eaea6dc27c
equal deleted inserted replaced
24:7dcc8419dbdb 25:2a600af97c6b
214 w->Write<long> (DH_INCGLOBALVAR); 214 w->Write<long> (DH_INCGLOBALVAR);
215 w->Write<long> (g->index); 215 w->Write<long> (g->index);
216 } else if (!oper.compare ("--")) { 216 } else if (!oper.compare ("--")) {
217 w->Write<long> (DH_DECGLOBALVAR); 217 w->Write<long> (DH_DECGLOBALVAR);
218 w->Write<long> (g->index); 218 w->Write<long> (g->index);
219 } else {
220 // Binary operators
221 // And only with numbers for now too.
222 // TODO: make a proper expression parser!
223 MustNumber();
224
225 int val = atoi (token.chars());
226 w->Write<long> (DH_PUSHNUMBER);
227 w->Write<long> (val);
228
229 int h = !oper.compare("=") ? DH_ASSIGNGLOBALVAR :
230 !oper.compare("+=") ? DH_ADDGLOBALVAR :
231 !oper.compare("-=") ? DH_SUBGLOBALVAR :
232 !oper.compare("*=") ? DH_MULGLOBALVAR :
233 !oper.compare("/=") ? DH_DIVGLOBALVAR :
234 !oper.compare("%=") ? DH_MODGLOBALVAR : -1;
235
236 if (h == -1)
237 ParserError ("bad operator `%s`!", oper.chars());
238
239 w->Write<long> (h);
240 w->Write<long> (g->index);
219 } 241 }
220 242
221 // And only with numbers for now too.
222 // TODO: make a proper expression parser!
223 MustNumber();
224
225 int val = atoi (token.chars());
226 w->Write<long> (DH_PUSHNUMBER);
227 w->Write<long> (val);
228
229 int dataheader = !oper.compare("=") ? DH_ASSIGNGLOBALVAR :
230 !oper.compare("+=") ? DH_ADDGLOBALVAR :
231 !oper.compare("-=") ? DH_SUBGLOBALVAR :
232 !oper.compare("*=") ? DH_MULGLOBALVAR :
233 !oper.compare("/=") ? DH_DIVGLOBALVAR :
234 !oper.compare("%=") ? DH_MODGLOBALVAR : -1;
235
236 if (dataheader == -1)
237 ParserError ("bad operator `%s`!", oper.chars());
238
239 w->Write<long> (dataheader);
240 w->Write<long> (g->index);
241
242 MustNext (";"); 243 MustNext (";");
243 continue; 244 continue;
244 } 245 }
245 246
246 // Check if it's a command. 247 // Check if it's a command.

mercurial