Mercurial > lcfOS
diff python/c3/parser.py @ 225:1c7364bd74c7
Fixed pointer deref
author | Windel Bouwman |
---|---|
date | Thu, 11 Jul 2013 07:42:30 +0200 |
parents | c3f1ce8b638f |
children | 240111e0456f |
line wrap: on
line diff
--- a/python/c3/parser.py Tue Jul 09 17:59:15 2013 +0200 +++ b/python/c3/parser.py Thu Jul 11 07:42:30 2013 +0200 @@ -75,10 +75,9 @@ self.Error('Expected function, var, const or type') def parseDesignator(self): - """ A designator designates an object """ - name = self.Consume('ID') - d = astnodes.Designator(name.val, name.loc) - return d + """ A designator designates an object """ + name = self.Consume('ID') + return astnodes.Designator(name.val, name.loc) # Type system def parseTypeSpec(self): @@ -109,9 +108,9 @@ self.Consume('type') newtype = self.parseTypeSpec() typename = self.Consume('ID') - # TODO: action here :) self.Consume(';') - return astnodes.DefinedType(typename, newtype) + df = astnodes.DefinedType(typename.val, newtype, typename.loc) + self.addDeclaration(df) # Variable declarations: def parseVarDef(self): @@ -319,7 +318,10 @@ if self.Peak in ['&', '*']: op = self.Consume(self.Peak) ce = self.CastExpression() - return astnodes.Unop(op.typ, ce, op.loc) + if op.val == '*': + return astnodes.Deref(ce, op.loc) + else: + return astnodes.Unop(op.typ, ce, op.loc) else: return self.PostFixExpression() @@ -337,8 +339,15 @@ args.append(self.Expression()) self.Consume(')') pfe = astnodes.FunctionCall(pfe, args, pfe.loc) + elif self.hasConsumed('->'): + field = self.Consume('ID') + pfe = astnodes.Deref(pfe, pfe.loc) + pfe = astnodes.FieldRef(pfe, field.val, field.loc) + elif self.hasConsumed('.'): + field = self.Consume('ID') + pfe = astnodes.FieldRef(pfe, field.val, field.loc) else: - rrrr + raise Exception() return pfe def PrimaryExpression(self):