diff parser/Parser.d @ 146:8c09fdaa724e

Parsing for-loop.
author Anders Johnsen <skabet@gmail.com>
date Mon, 21 Jul 2008 18:16:50 +0200
parents 6e6355fb5f0f
children 6ec686d9c87d 6c5a3c0bb4fb
line wrap: on
line diff
--- a/parser/Parser.d	Mon Jul 21 17:56:33 2008 +0200
+++ b/parser/Parser.d	Mon Jul 21 18:16:50 2008 +0200
@@ -578,6 +578,35 @@
                The assignments should be handled as binary expressions?
              */
         }
+        else if (t.isFor)
+        {
+            Token _for = next;
+            require(Tok.OpenParentheses);
+            Stmt init = parseStatement();
+
+            Exp cond;
+            if ( !isa(Tok.Seperator))
+                cond = parseExpression();
+            require(Tok.Seperator);
+
+            Exp incre;
+            if ( !isa(Tok.CloseParentheses))
+                incre = parseExpression();
+            require(Tok.CloseParentheses);
+
+            Stmt bodyStmt = parseSingleOrCompoundStatement();
+            return action.actOnForStmt(_for, init, cond, incre, bodyStmt);
+
+            /*
+               One of four things:
+               A declaration of a function/variable `type id ...`
+               A direct assignment `id = exp;`
+               An indirect assignment `id.id = exp`
+               Some sort of free standing expression
+
+               The assignments should be handled as binary expressions?
+             */
+        }
         else if (t.isBasicType || t.isIdentifier)
         {
             Token iden = peek;