changeset 76:9171f04dd9ee new_gen

Now parsing varDecls a lot nicer!
author Anders Johnsen <skabet@gmail.com>
date Fri, 02 May 2008 15:48:57 +0200
parents 86aec2160221
children 13eea2c4e60d ad956143dcdc
files parser/Parser.d
diffstat 1 files changed, 23 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/parser/Parser.d	Fri May 02 15:05:02 2008 +0200
+++ b/parser/Parser.d	Fri May 02 15:48:57 2008 +0200
@@ -39,7 +39,7 @@
 
         if (t.isBasicType || t.isIdentifier)
         {
-            Id type = parseType;//Id(lexer.next);
+            Id type = Id(lexer.next);
             Id iden = Id(require(Tok.Identifier));
             Token next = lexer.peek();
             if (next.type == Tok.Seperator)
@@ -182,26 +182,18 @@
                 // identifiers in a row
                 if (iden.isBasicType() || iden.isIdentifier())
                 {
-                    // manually hardcoded to only support "type id [= exp];"
-                    // as that is the only thing the codegen understands
-                    Id type = parseType;
-                    n = lexer.peek();
-                    Id id = Id(lexer.next);
-                    Exp init;
-                    if (skip(Tok.Assign))
-                        init = parseExpression();
-                    require(Tok.Seperator);
-                    Decl d = action.actOnDeclarator(type, id, init);
-                    return action.actOnDeclStmt(d);
-                }
-                // Expression: a.b, a = b, a(b) etc.
-                else
-                {
+                    if ( n.type == Tok.Star)
+                        return action.actOnDeclStmt(parseVarDecl());
+                        
+                    if ( n.isIdentifier())
+                        return action.actOnDeclStmt(parseVarDecl());
+
+                    // Expression: a.b, a = b, a(b) etc.
                     Exp exp = parseExpression();
                     require(Tok.Seperator);
                     return action.actOnExprStmt(exp);
+                    break;
                 }
-                break;
 
             case Tok.Switch:
                 throw error(__LINE__, ":(").tok(lexer.peek);
@@ -216,6 +208,20 @@
         return null;
     }
 
+    Decl parseVarDecl()
+    {
+        // manually hardcoded to only support "type id [= exp];"
+        // as that is the only thing the codegen understands
+        Id type = parseType;
+        Id id = Id(lexer.next);
+        Exp init;
+        if (skip(Tok.Assign))
+            init = parseExpression();
+        require(Tok.Seperator);
+        Decl d = action.actOnDeclarator(type, id, init);
+        return d;
+    }
+
     /**
       Parses a function/method given the already parsed return type and name
      */