diff python/c3/parser.py @ 150:4ae0e02599de

Added type check start and analyze phase
author Windel Bouwman
date Fri, 01 Mar 2013 16:53:22 +0100
parents 74241ca312cc
children b73bc14a3aa3
line wrap: on
line diff
--- a/python/c3/parser.py	Fri Mar 01 11:43:52 2013 +0100
+++ b/python/c3/parser.py	Fri Mar 01 16:53:22 2013 +0100
@@ -19,9 +19,6 @@
          self.diag.diag(e)
    def Error(self, msg):
       raise CompilerException(msg, self.token.loc)
-   def skipToSemiCol(self):
-      while not (self.Peak == ';' or self.Peak == 'END'):
-         self.NextToken()
    # Lexer helpers:
    def Consume(self, typ):
       if self.Peak == typ:
@@ -43,8 +40,7 @@
       return False
    def NextToken(self):
       t = self.token
-      if t.typ != 'END':
-         self.token = self.tokens.__next__()
+      if t.typ != 'END': self.token = self.tokens.__next__()
       return t
    def initLex(self, source):
       self.tokens = lexer.tokenize(source) # Lexical stage
@@ -72,7 +68,7 @@
    def parseDesignator(self):
       """ A designator designates an object """
       name = self.Consume('ID')
-      return name.val
+      return self.sema.actOnDesignator(name.val, name.loc)
 
    # Type system
    def parseType(self):
@@ -102,19 +98,20 @@
       self.Consume('(')
       parameters = []
       if not self.hasConsumed(')'):
-         typ = self.parseType()
-         name = self.Consume('ID')
-         parameters.append(astnodes.Parameter(name, typ))
-         while self.hasConsumed(','):
+         def parseParameter():
             typ = self.parseType()
             name = self.Consume('ID')
-            parameters.append(astnodes.Parameter(name, typ))
+            parameters.append(self.sema.actOnParameter(name.val, name.loc, typ))
+         parseParameter()
+         while self.hasConsumed(','):
+            parseParameter()
          self.Consume(')')
       body = self.parseCompoundStatement()
       self.sema.actOnFuncDef2(parameters, returntype, body)
 
    # Statements:
    def parseAssignment(self, lval):
+      lval = astnodes.VariableUse(lval)
       self.Consume('=')
       rval = self.parseExpression()
       return astnodes.Assignment(lval, rval)
@@ -194,7 +191,7 @@
          return self.sema.actOnNumber(val.val, val.loc)
       elif self.Peak == 'ID':
          d = self.parseDesignator()
-         return d
+         return self.sema.actOnVariableUse(d)
       self.Error('Expected NUM, ID or (expr), got {0}'.format(self.Peak))
 
    def parseBinopRhs(self, lhs, min_prec):