changeset 161:82c5cfc7d6d3

- Started implementation of parsing statements. - Fix: was calling wrong method in parseDeclarationDefinitions(). - Added code for parsing LabeledStatement. - Added class stubs for all statements in the NonEmptyStatement rule.
author aziz
date Fri, 13 Jul 2007 20:49:01 +0000
parents c21192e8be2b
children c7b250662c74
files trunk/src/Declarations.d trunk/src/Parser.d trunk/src/Statements.d
diffstat 3 files changed, 191 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Declarations.d	Fri Jul 13 15:23:02 2007 +0000
+++ b/trunk/src/Declarations.d	Fri Jul 13 20:49:01 2007 +0000
@@ -124,8 +124,8 @@
 class ConstructorDeclaration : Declaration
 {
   Parameters parameters;
-  Statement[] statements;
-  this(Parameters parameters, Statement[] statements)
+  Statements statements;
+  this(Parameters parameters, Statements statements)
   {
     super(true);
     this.parameters = parameters;
@@ -135,8 +135,8 @@
 
 class StaticConstructorDeclaration : Declaration
 {
-  Statement[] statements;
-  this(Statement[] statements)
+  Statements statements;
+  this(Statements statements)
   {
     super(true);
     this.statements = statements;
@@ -145,8 +145,8 @@
 
 class DestructorDeclaration : Declaration
 {
-  Statement[] statements;
-  this(Statement[] statements)
+  Statements statements;
+  this(Statements statements)
   {
     super(true);
     this.statements = statements;
@@ -155,8 +155,8 @@
 
 class StaticDestructorDeclaration : Declaration
 {
-  Statement[] statements;
-  this(Statement[] statements)
+  Statements statements;
+  this(Statements statements)
   {
     super(true);
     this.statements = statements;
@@ -165,8 +165,8 @@
 
 class InvariantDeclaration : Declaration
 {
-  Statement[] statements;
-  this(Statement[] statements)
+  Statements statements;
+  this(Statements statements)
   {
     super(true);
     this.statements = statements;
@@ -175,8 +175,8 @@
 
 class UnittestDeclaration : Declaration
 {
-  Statement[] statements;
-  this(Statement[] statements)
+  Statements statements;
+  this(Statements statements)
   {
     super(true);
     this.statements = statements;
--- a/trunk/src/Parser.d	Fri Jul 13 15:23:02 2007 +0000
+++ b/trunk/src/Parser.d	Fri Jul 13 20:49:01 2007 +0000
@@ -84,7 +84,7 @@
   {
     Declaration[] decls;
     while (token.type != T.RBrace && token.type != T.EOF)
-      decls ~= parseDeclarationDefinitions();
+      decls ~= parseDeclarationDefinition();
     return decls;
   }
 
@@ -227,11 +227,6 @@
     return decls;
   }
 
-  Statement[] parseStatements()
-  {
-    return null;
-  }
-
   Declaration parseAttributeSpecifier()
   {
     Declaration decl;
@@ -1109,6 +1104,44 @@
   }
 
   /+++++++++++++++++++++++++++++
+  + Statement parsing methods  +
+  +++++++++++++++++++++++++++++/
+
+  Statements parseStatements()
+  {
+    Statements statements;
+    while (token.type != T.RBrace && token.type != T.EOF)
+      statements ~= parseStatement();
+    return statements;
+  }
+
+  Statement parseStatement()
+  {
+    Statement s;
+    switch (token.type)
+    {
+    case T.Identifier:
+      Token next;
+      lx.peek(next);
+      if (next.type == T.Colon)
+      {
+        string ident = token.identifier;
+        nT(); // Skip Identifier
+        nT(); // Skip :
+        s = parseStatements();
+        s = new LabeledStatement(ident, s);
+        break;
+      }
+      goto case_Declaration;
+    case_Declaration:
+      // TODO: parse Declaration
+      break;
+    default:
+    }
+    return s;
+  }
+
+  /+++++++++++++++++++++++++++++
   + Expression parsing methods +
   +++++++++++++++++++++++++++++/
 
--- a/trunk/src/Statements.d	Fri Jul 13 15:23:02 2007 +0000
+++ b/trunk/src/Statements.d	Fri Jul 13 20:49:01 2007 +0000
@@ -8,3 +8,143 @@
 {
 
 }
+
+class Statements : Statement
+{
+  Statement[] ss;
+  void opCatAssign(Statement s)
+  {
+    this.ss ~= s;
+  }
+}
+
+class LabeledStatement : Statement
+{
+  string label;
+  Statement s;
+  this(string label, Statement s)
+  {
+    this.label = label;
+    this.s = s;
+  }
+}
+
+class ExpressionStatement : Statement
+{
+
+}
+
+class DeclarationStatement : Statement
+{
+
+}
+
+class IfStatement : Statement
+{
+
+}
+
+class ConditionalStatement : Statement
+{
+
+}
+
+class WhileStatement : Statement
+{
+
+}
+
+class DoStatement : Statement
+{
+
+}
+
+class ForStatement : Statement
+{
+
+}
+
+class ForeachStatement : Statement
+{
+
+}
+
+class SwitchStatement : Statement
+{
+
+}
+
+class CaseStatement : Statement
+{
+
+}
+
+class DefaultStatement : Statement
+{
+
+}
+
+class ContinueStatement : Statement
+{
+
+}
+
+class BreakStatement : Statement
+{
+
+}
+
+class ReturnStatement : Statement
+{
+
+}
+
+class GotoStatement : Statement
+{
+
+}
+
+class WithStatement : Statement
+{
+
+}
+
+class SynchronizedStatement : Statement
+{
+
+}
+
+class TryStatement : Statement
+{
+
+}
+
+class ScopeGuardStatement : Statement
+{
+
+}
+
+class ThrowStatement : Statement
+{
+
+}
+
+class VolatileStatement : Statement
+{
+
+}
+
+class AsmStatement : Statement
+{
+
+}
+
+class PragmaStatement : Statement
+{
+
+}
+
+class MixinStatement : Statement
+{
+
+}