changeset 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 a9560839104d
children dbf459397217
files src/luan/interp/LuanParser.java
diffstat 1 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
diff -r a9560839104d -r 1a29dd3888f6 src/luan/interp/LuanParser.java
--- a/src/luan/interp/LuanParser.java	Tue May 13 06:03:09 2014 +0000
+++ b/src/luan/interp/LuanParser.java	Mon May 19 06:23:18 2014 +0000
@@ -327,9 +327,22 @@
 		RequiredMatch( "=" );
 		Spaces();
 		Expr from = RequiredExpr();
-		RequiredKeyword("to");
-		Expr to = RequiredExpr();
-		Expr step = Keyword("step") ? RequiredExpr() : new ConstExpr(1);
+		Expr to;
+		Expr step;
+		if( parser.match(',') ) {
+			Spaces();
+			to = RequiredExpr();
+			if( parser.match(',') ) {
+				Spaces();
+				step = RequiredExpr();
+			} else {
+				step = new ConstExpr(1);
+			}
+		} else {
+			RequiredKeyword("to");
+			to = RequiredExpr();
+			step = Keyword("step") ? RequiredExpr() : new ConstExpr(1);
+		}
 		addSymbol(name);  // add "for" var to symbols
 		RequiredKeyword("do");
 		Stmt loop = RequiredLoopBlock();