diff trunk/src/Parser.d @ 162:c7b250662c74

- Added class ScopeStatement. - Fix: didn't creat class instance in parseStatements(). - Implemented parseIfStatement().
author aziz
date Fri, 13 Jul 2007 22:31:02 +0000
parents 82c5cfc7d6d3
children f27a98bb17c7
line wrap: on
line diff
--- a/trunk/src/Parser.d	Fri Jul 13 20:49:01 2007 +0000
+++ b/trunk/src/Parser.d	Fri Jul 13 22:31:02 2007 +0000
@@ -1109,7 +1109,7 @@
 
   Statements parseStatements()
   {
-    Statements statements;
+    auto statements = new Statements();
     while (token.type != T.RBrace && token.type != T.EOF)
       statements ~= parseStatement();
     return statements;
@@ -1136,11 +1136,78 @@
     case_Declaration:
       // TODO: parse Declaration
       break;
+    case T.If:
+      s = parseIfStatement();
+      break;
     default:
     }
     return s;
   }
 
+  /+
+    ScopeStatement:
+        NonEmptyStatement
+        BlockStatement
+    BlockStatement:
+        { }
+        { StatementList }
+  +/
+  Statement parseScopeBlockStatement()
+  {
+    Statement s;
+    if (token.type == T.LBrace)
+    {
+      nT();
+      auto ss = new Statements();
+      while (token.type != T.RBrace && token.type != T.EOF)
+        ss ~= parseStatement();
+      require(T.RBrace);
+      s = ss;
+    }
+    else
+      s = parseStatement();
+    return new ScopeStatement(s);
+  }
+
+  Statement parseIfStatement()
+  {
+    assert(token.type == T.If);
+    nT();
+
+    Type type;
+    string ident;
+    Expression condition;
+    Statement ifBody, elseBody;
+
+    require(T.LParen);
+    // auto Identifier = Expression
+    if (token.type == T.Auto)
+    {
+      nT();
+      ident = requireIdentifier();
+      require(T.Assign);
+    }
+    else
+    {
+      // Declarator = Expression
+      bool failed;
+      type = try_(parseDeclarator(ident), failed);
+      if (!failed)
+      {
+        require(T.Assign);
+      }
+    }
+    condition = parseExpression();
+    require(T.RParen);
+    ifBody = parseScopeBlockStatement();
+    if (token.type == T.Else)
+    {
+      nT();
+      elseBody = parseScopeBlockStatement();
+    }
+    return new IfStatement(type, ident, condition, ifBody, elseBody);
+  }
+
   /+++++++++++++++++++++++++++++
   + Expression parsing methods +
   +++++++++++++++++++++++++++++/