Mercurial > lcfOS
diff python/ppci/c3/parser.py @ 315:084cccaa5deb
Added console and screen
author | Windel Bouwman |
---|---|
date | Sat, 21 Dec 2013 10:03:01 +0100 |
parents | 04cf4d26a3bc |
children | 6f4753202b9a |
line wrap: on
line diff
--- a/python/ppci/c3/parser.py Wed Dec 18 20:22:20 2013 +0100 +++ b/python/ppci/c3/parser.py Sat Dec 21 10:03:01 2013 +0100 @@ -2,7 +2,7 @@ from ppci import CompilerError from .astnodes import Member, Literal, TypeCast, Unop, Binop from .astnodes import Assignment, ExpressionStatement, Compound -from .astnodes import Return, While, If, Empty +from .astnodes import Return, While, If, Empty, For from .astnodes import FunctionType, Function, FormalParameter from .astnodes import StructureType, DefinedType, PointerType from .astnodes import Constant, Variable @@ -204,6 +204,18 @@ statements = self.Statement() return While(condition, statements, loc) + def parseFor(self): + loc = self.Consume('for').loc + self.Consume('(') + init = self.Statement() + self.Consume(';') + condition = self.Expression() + self.Consume(';') + final = self.Statement() + self.Consume(')') + statements = self.Statement() + return For(init, condition, final, statements, loc) + def parseReturn(self): loc = self.Consume('return').loc if self.Peak == ';': @@ -226,6 +238,8 @@ return self.parseIf() elif self.Peak == 'while': return self.parseWhile() + elif self.Peak == 'for': + return self.parseFor() elif self.Peak == '{': return self.parseCompound() elif self.hasConsumed(';'): @@ -347,7 +361,7 @@ def PostFixExpression(self): pfe = self.PrimaryExpression() - while self.Peak in ['[', '.', '->', '(']: + while self.Peak in ['[', '.', '->', '(', '++']: if self.hasConsumed('['): raise NotImplementedError('Array not yet implemented') elif self.hasConsumed('->'): @@ -357,6 +371,9 @@ elif self.hasConsumed('.'): field = self.Consume('ID') pfe = Member(pfe, field.val, field.loc) + elif self.Peak == '++': + loc = self.Consume('++').loc + pfe = Unop('++', pfe, loc) elif self.hasConsumed('('): # Function call args = []