Mercurial Hosting > luan
comparison src/luan/interp/LuanParser.java @ 109:219e05867366
remove NumericForStmt;
add BasicLib.range();
git-svn-id: https://luan-java.googlecode.com/svn/trunk@110 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 23 May 2014 04:30:29 +0000 |
parents | 3c404a296995 |
children | 7afa6df829f3 |
comparison
equal
deleted
inserted
replaced
108:3c404a296995 | 109:219e05867366 |
---|---|
221 || (stmt=FunctionStmt()) != null | 221 || (stmt=FunctionStmt()) != null |
222 || (stmt=LocalFunctionStmt()) != null | 222 || (stmt=LocalFunctionStmt()) != null |
223 || (stmt=ImportStmt()) != null | 223 || (stmt=ImportStmt()) != null |
224 || (stmt=BreakStmt()) != null | 224 || (stmt=BreakStmt()) != null |
225 || (stmt=GenericForStmt()) != null | 225 || (stmt=GenericForStmt()) != null |
226 || (stmt=NumericForStmt()) != null | |
227 || (stmt=TryStmt()) != null | 226 || (stmt=TryStmt()) != null |
228 || (stmt=DoStmt()) != null | 227 || (stmt=DoStmt()) != null |
229 || (stmt=WhileStmt()) != null | 228 || (stmt=WhileStmt()) != null |
230 || (stmt=FunctionStmt()) != null | 229 || (stmt=FunctionStmt()) != null |
231 || (stmt=RepeatStmt()) != null | 230 || (stmt=RepeatStmt()) != null |
345 addSymbols(names); | 344 addSymbols(names); |
346 Stmt loop = RequiredLoopBlock(); | 345 Stmt loop = RequiredLoopBlock(); |
347 RequiredKeyword("end"); | 346 RequiredKeyword("end"); |
348 Stmt stmt = new GenericForStmt( se(start), stackStart, symbolsSize() - stackStart, expr, loop ); | 347 Stmt stmt = new GenericForStmt( se(start), stackStart, symbolsSize() - stackStart, expr, loop ); |
349 popSymbols( symbolsSize() - stackStart ); | 348 popSymbols( symbolsSize() - stackStart ); |
350 return parser.success(stmt); | |
351 } | |
352 | |
353 private Stmt NumericForStmt() throws ParseException { | |
354 int start = parser.begin(); | |
355 if( !Keyword("for") ) | |
356 return parser.failure(null); | |
357 String name = RequiredName(); | |
358 RequiredMatch( "=" ); | |
359 Spaces(); | |
360 Expr from = expr(RequiredExpr()); | |
361 Expr to; | |
362 Expr step; | |
363 if( parser.match(',') ) { | |
364 Spaces(); | |
365 to = expr(RequiredExpr()); | |
366 if( parser.match(',') ) { | |
367 Spaces(); | |
368 step = expr(RequiredExpr()); | |
369 } else { | |
370 step = new ConstExpr(1); | |
371 } | |
372 } else { | |
373 RequiredKeyword("to"); | |
374 to = expr(RequiredExpr()); | |
375 step = Keyword("step") ? expr(RequiredExpr()) : new ConstExpr(1); | |
376 } | |
377 addSymbol(name); // add "for" var to symbols | |
378 RequiredKeyword("do"); | |
379 Stmt loop = RequiredLoopBlock(); | |
380 RequiredKeyword("end"); | |
381 Stmt stmt = new NumericForStmt( se(start), symbolsSize()-1, from, to, step, loop ); | |
382 popSymbols(1); | |
383 return parser.success(stmt); | 349 return parser.success(stmt); |
384 } | 350 } |
385 | 351 |
386 private Stmt TryStmt() throws ParseException { | 352 private Stmt TryStmt() throws ParseException { |
387 parser.begin(); | 353 parser.begin(); |