diff python/c3/parser.py @ 157:8f3924b6076e

Added some code generator things
author Windel Bouwman
date Sun, 03 Mar 2013 18:14:35 +0100
parents b28a11c01dbe
children 9683a4cd848f
line wrap: on
line diff
--- a/python/c3/parser.py	Sun Mar 03 15:50:34 2013 +0100
+++ b/python/c3/parser.py	Sun Mar 03 18:14:35 2013 +0100
@@ -61,7 +61,6 @@
          self.parseFunctionDefinition()
       elif self.Peak == 'var':
          self.parseVarDef()
-         self.Consume(';')
       else:
          self.Error('Expected function or variable')
 
@@ -88,6 +87,7 @@
       parseVar()
       while self.hasConsumed(','):
          parseVar()
+      self.Consume(';')
 
    # Procedures
    def parseFunctionDefinition(self):
@@ -114,6 +114,7 @@
       lval = astnodes.VariableUse(lval)
       self.Consume('=')
       rval = self.parseExpression()
+      self.Consume(';')
       return astnodes.Assignment(lval, rval)
 
    def parseProcedureCall(self, procedure):
@@ -148,15 +149,14 @@
    def parseReturnStatement(self):
       self.Consume('return')
       expr = self.parseExpression()
+      self.Consume(';')
       return astnodes.ReturnStatement(expr)
 
    def parseCompoundStatement(self):
       self.Consume('{')
-      statements = [self.parseStatement()]
-      while self.hasConsumed(';'):
-         if self.Peak == '}': break # Permit last ';'
+      statements = []
+      while not self.hasConsumed('}'):
          statements.append(self.parseStatement())
-      self.Consume('}')
       return astnodes.CompoundStatement(statements)
 
    def parseStatement(self):
@@ -168,6 +168,7 @@
       elif self.Peak == '{':
          return self.parseCompoundStatement()
       elif self.Peak == ';':
+         self.Consume(';')
          return astnodes.EmptyStatement()
       elif self.Peak == 'var':
          return self.parseVarDef()