Mercurial > lcfOS
diff python/c3/parser.py @ 221:848c4b15fd0b
pointers
author | Windel Bouwman |
---|---|
date | Mon, 08 Jul 2013 22:21:44 +0200 |
parents | 3f6c30a5d234 |
children | c3f1ce8b638f |
line wrap: on
line diff
--- a/python/c3/parser.py Sat Jul 06 21:32:20 2013 +0200 +++ b/python/c3/parser.py Mon Jul 08 22:21:44 2013 +0200 @@ -276,30 +276,45 @@ return e def Term(self): - t = self.Factor() + t = self.BitwiseOr() while self.Peak in ['*', '/']: op = self.Consume(self.Peak) - t2 = self.Factor() + t2 = self.BitwiseOr() t = astnodes.Binop(t, op.typ, t2, op.loc) return t - - def Factor(self): - # TODO: eliminate this step? - return self.CastExpression() + + def BitwiseOr(self): + a = self.BitwiseAnd() + while self.Peak in ['|']: + op = self.Consume(self.Peak) + b = self.BitwiseAnd() + a = astnodes.Binop(a, op.typ, b, op.loc) + return a + + def BitwiseAnd(self): + a = self.CastExpression() + while self.Peak in ['&']: + op = self.Consume(self.Peak) + b = self.CastExpression() + a = astnodes.Binop(a, op.typ, b, op.loc) + return a # Domain of unary expressions: def CastExpression(self): - # TODO: cast conflicts with '(' expr ')' - if self.Peak == '(ii': - self.Consume('(') + # TODO: cast conflicts with '(' expr ')', so introduce extra keyword 'cast' + if self.Peak == 'cast': + self.Consume('cast') + self.Consume('<') print('TODO: implement type cast') - #rrrrr - self.parseTypeSpec() + t = self.parseTypeSpec() # Type + self.Consume('>') + self.Consume('(') + ce = self.CastExpression() self.Consume(')') - ce = self.CastExpression() + # TODO: use type spec here return ce else: return self.UnaryExpression()