Charj: Fixed for loop parsing errors
authorAaron Becker <akbecker@gmail.com>
Fri, 21 May 2010 21:37:18 +0000 (16:37 -0500)
committerAaron Becker <akbecker@gmail.com>
Fri, 21 May 2010 21:37:18 +0000 (16:37 -0500)
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/Charj.stg
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g

index 44a3fa4d5f5c21d348020fd344110b776bb9a320..7b329e8f1438ddabb8e30734cb162ba5c7a68a51 100644 (file)
@@ -69,6 +69,8 @@ tokens {
     EXTENDS_BOUND_LIST;
     EXTENDS_CLAUSE;
     FOR_EACH;
+    FOR_EXPR;
+    FOR_UPDATE;
     FORMAL_PARAM_LIST;
     FORMAL_PARAM_STD_DECL;
     FORMAL_PARAM_VARARG_DECL;
@@ -441,7 +443,7 @@ statement
         )   
     |   f='for' '('
         (   forInit? ';' expression? ';' expressionList? ')' statement
-            -> ^($f forInit expression? expressionList statement)
+            -> ^($f forInit? FOR_EXPR expression? FOR_UPDATE expressionList? statement)
         |   localModifierList? type IDENT ':' expression ')' statement
             -> ^(FOR_EACH[$f, "FOR_EACH"] localModifierList? type IDENT expression statement)
         )
index bb21a6e78618c00f4f4945508d78937411fa0415..4eb16f65f89175d47c58434795e687dbfd427f8a 100644 (file)
@@ -333,7 +333,7 @@ if <cond> {
 
 for(initializer, cond, update, body) ::=
 <<
-for (<initializer> <cond> <update>) {
+for (<if(initializer)><initializer><else>;<endif> <cond>; <update; separator=", ">) {
     <body>
 }
 >>
@@ -375,16 +375,6 @@ case(expr, block) ::=
 case <expr>: <block>
 >>
 
-for_cond(expr) ::=
-<<
-<expr>
->>
-
-for_update(exprs) ::=
-<<
-<exprs; separator=", ">
->>
-
 method_call(primary, generic_types, args) ::=
 <<
 <if(generic_types)>
index c313e26c5a4a540567584b0d75057d9347a93bed..ae115765020196eb4f885101f1e61b305a33733f 100644 (file)
@@ -505,7 +505,7 @@ statement
         -> assert(cond={$cond.st}, msg={$msg.st})
     |   ^('if' parenthesizedExpression then=statement else_=statement?)
         -> if(cond={$parenthesizedExpression.st}, then={$then.st}, else_={$else_.st})
-    |   ^('for' forInit cond=expression? (update+=expression)* s=statement)
+    |   ^('for' forInit? FOR_EXPR cond=expression? FOR_UPDATE (update+=expression)* s=statement)
         -> for(initializer={$forInit.st}, cond={$cond.st}, update={$update}, body={$s.st})
     |   ^(FOR_EACH localModifierList? type IDENT expression statement) 
         -> template(t={$text}) "/* foreach not implemented */ <t>"
index 4220abe1855d011030100bb5c3fe9d440d0f9e0e..8b25e131aaad7ced46c62e9127ed75e85f0956cc 100644 (file)
@@ -309,7 +309,7 @@ statement
     :   block
     |   ^('assert' expression expression?)
     |   ^('if' parenthesizedExpression statement statement?)
-    |   ^('for' forInit expression? expression* statement)
+    |   ^('for' forInit? FOR_EXPR expression? FOR_UPDATE expression* statement)
     |   ^(FOR_EACH localModifierList? type IDENT expression statement) 
     |   ^('while' parenthesizedExpression statement)
     |   ^('do' statement parenthesizedExpression)