Mercurial > lcfOS
diff python/ppci/c3/parser.py @ 301:6753763d3bec
merge codegen into ppci package
author | Windel Bouwman |
---|---|
date | Thu, 05 Dec 2013 17:02:38 +0100 |
parents | 158068af716c |
children | b145f8e6050b |
line wrap: on
line diff
--- a/python/ppci/c3/parser.py Tue Dec 03 18:00:22 2013 +0100 +++ b/python/ppci/c3/parser.py Thu Dec 05 17:02:38 2013 +0100 @@ -1,4 +1,5 @@ import logging +from ppci import CompilerError from .lexer import Lexer from .astnodes import FieldRef, Literal, TypeCast, Unop, Binop from .astnodes import Assignment, ExpressionStatement, CompoundStatement @@ -9,7 +10,6 @@ from .astnodes import StructField, Deref from .astnodes import Package, ImportDesignator from .astnodes import Designator, VariableUse, FunctionCall -from ppci import CompilerError class Parser: @@ -96,7 +96,7 @@ self.Error('Expected function, var, const or type') def parseDesignator(self): - """ A designator designates an object """ + """ A designator designates an object with a name. """ name = self.Consume('ID') if self.hasConsumed(':'): name2 = self.Consume('ID') @@ -107,7 +107,6 @@ # Type system def parseTypeSpec(self): # For now, do simple type spec, just parse an ID: - #return self.parseDesignator() if self.Peak == 'struct': self.Consume('struct') self.Consume('{') @@ -368,27 +367,28 @@ def PostFixExpression(self): pfe = self.PrimaryExpression() - while self.Peak in ['[', '(', '.', '->']: - if self.hasConsumed('['): - pass - elif self.hasConsumed('('): - # Function call - args = [] - if not self.hasConsumed(')'): + if self.hasConsumed('('): + # Function call + args = [] + if not self.hasConsumed(')'): + args.append(self.Expression()) + while self.hasConsumed(','): args.append(self.Expression()) - while self.hasConsumed(','): - args.append(self.Expression()) - self.Consume(')') - pfe = FunctionCall(pfe, args, pfe.loc) - elif self.hasConsumed('->'): - field = self.Consume('ID') - pfe = Deref(pfe, pfe.loc) - pfe = FieldRef(pfe, field.val, field.loc) - elif self.hasConsumed('.'): - field = self.Consume('ID') - pfe = FieldRef(pfe, field.val, field.loc) - else: - raise Exception() + self.Consume(')') + pfe = FunctionCall(pfe, args, pfe.loc) + else: + while self.Peak in ['[', '.', '->']: + if self.hasConsumed('['): + raise NotImplementedError('Array not yet implemented') + elif self.hasConsumed('->'): + field = self.Consume('ID') + pfe = Deref(pfe, pfe.loc) + pfe = FieldRef(pfe, field.val, field.loc) + elif self.hasConsumed('.'): + field = self.Consume('ID') + pfe = FieldRef(pfe, field.val, field.loc) + else: + raise Exception() return pfe def PrimaryExpression(self):