diff python/c3/parser.py @ 272:e64bae57cda8

refactor ir
author Windel Bouwman
date Sat, 31 Aug 2013 17:58:54 +0200
parents bd26dc13f270
children 02385f62f250
line wrap: on
line diff
--- a/python/c3/parser.py	Tue Aug 20 18:56:02 2013 +0200
+++ b/python/c3/parser.py	Sat Aug 31 17:58:54 2013 +0200
@@ -124,19 +124,19 @@
 
     # Variable declarations:
     def parseVarDef(self):
-      self.Consume('var')
-      t = self.parseTypeSpec()
-      def parseVar():
-         name = self.Consume('ID')
-         v = astnodes.Variable(name.val, t)
-         v.loc = name.loc
-         if self.hasConsumed('='):
-            v.ival = self.Expression()
-         self.addDeclaration(v)
-      parseVar()
-      while self.hasConsumed(','):
-         parseVar()
-      self.Consume(';')
+        self.Consume('var')
+        t = self.parseTypeSpec()
+        def parseVar():
+            name = self.Consume('ID')
+            v = astnodes.Variable(name.val, t)
+            v.loc = name.loc
+            if self.hasConsumed('='):
+                v.ival = self.Expression()
+            self.addDeclaration(v)
+        parseVar()
+        while self.hasConsumed(','):
+            parseVar()
+        self.Consume(';')
 
     def parseConstDef(self):
       self.Consume('const')
@@ -164,17 +164,17 @@
       self.Consume('(')
       parameters = []
       if not self.hasConsumed(')'):
-         def parseParameter():
-            typ = self.parseTypeSpec()
-            name = self.Consume('ID')
-            param = astnodes.Variable(name.val, typ)
-            param.loc = name.loc
-            self.addDeclaration(param)
-            parameters.append(param)
-         parseParameter()
-         while self.hasConsumed(','):
+            def parseParameter():
+                typ = self.parseTypeSpec()
+                name = self.Consume('ID')
+                param = astnodes.FormalParameter(name.val, typ)
+                param.loc = name.loc
+                self.addDeclaration(param)
+                parameters.append(param)
             parseParameter()
-         self.Consume(')')
+            while self.hasConsumed(','):
+                parseParameter()
+            self.Consume(')')
       paramtypes = [p.typ for p in parameters]
       f.typ = astnodes.FunctionType(paramtypes, returntype)
       f.body = self.parseCompoundStatement()
@@ -183,16 +183,16 @@
     # Statements:
 
     def parseIfStatement(self):
-      loc = self.Consume('if').loc
-      self.Consume('(')
-      condition = self.Expression()
-      self.Consume(')')
-      yes = self.parseCompoundStatement()
-      if self.hasConsumed('else'):
-         no = self.parseCompoundStatement()
-      else:
-         no = None
-      return astnodes.IfStatement(condition, yes, no, loc)
+        loc = self.Consume('if').loc
+        self.Consume('(')
+        condition = self.Expression()
+        self.Consume(')')
+        yes = self.parseCompoundStatement()
+        if self.hasConsumed('else'):
+            no = self.parseCompoundStatement()
+        else:
+            no = None
+        return astnodes.IfStatement(condition, yes, no, loc)
 
     def parseWhileStatement(self):
         loc = self.Consume('while').loc