comparison src/luan/interp/LuanParser.java @ 106:1a29dd3888f6

support standard Lua numeric "for" statement git-svn-id: https://luan-java.googlecode.com/svn/trunk@107 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 19 May 2014 06:23:18 +0000
parents 754e6030c029
children dbf459397217
comparison
equal deleted inserted replaced
105:a9560839104d 106:1a29dd3888f6
325 return parser.failure(null); 325 return parser.failure(null);
326 String name = RequiredName(); 326 String name = RequiredName();
327 RequiredMatch( "=" ); 327 RequiredMatch( "=" );
328 Spaces(); 328 Spaces();
329 Expr from = RequiredExpr(); 329 Expr from = RequiredExpr();
330 RequiredKeyword("to"); 330 Expr to;
331 Expr to = RequiredExpr(); 331 Expr step;
332 Expr step = Keyword("step") ? RequiredExpr() : new ConstExpr(1); 332 if( parser.match(',') ) {
333 Spaces();
334 to = RequiredExpr();
335 if( parser.match(',') ) {
336 Spaces();
337 step = RequiredExpr();
338 } else {
339 step = new ConstExpr(1);
340 }
341 } else {
342 RequiredKeyword("to");
343 to = RequiredExpr();
344 step = Keyword("step") ? RequiredExpr() : new ConstExpr(1);
345 }
333 addSymbol(name); // add "for" var to symbols 346 addSymbol(name); // add "for" var to symbols
334 RequiredKeyword("do"); 347 RequiredKeyword("do");
335 Stmt loop = RequiredLoopBlock(); 348 Stmt loop = RequiredLoopBlock();
336 RequiredKeyword("end"); 349 RequiredKeyword("end");
337 Stmt stmt = new NumericForStmt( se(start), symbolsSize()-1, from, to, step, loop ); 350 Stmt stmt = new NumericForStmt( se(start), symbolsSize()-1, from, to, step, loop );