comparison python/c3/parser.py @ 222:c3f1ce8b638f

Fixup of parser
author Windel Bouwman
date Tue, 09 Jul 2013 17:36:31 +0200
parents 848c4b15fd0b
children 1c7364bd74c7
comparison
equal deleted inserted replaced
221:848c4b15fd0b 222:c3f1ce8b638f
233 # We enter assignment mode here. 233 # We enter assignment mode here.
234 loc = self.Consume('=').loc 234 loc = self.Consume('=').loc
235 rhs = self.Expression() 235 rhs = self.Expression()
236 return astnodes.Assignment(x, rhs, loc) 236 return astnodes.Assignment(x, rhs, loc)
237 else: 237 else:
238 return x 238 return astnodes.ExpressionStatement(x, x.loc)
239 239
240 # Expression section: 240 # Expression section:
241 # We not implement these C constructs: 241 # We not implement these C constructs:
242 # a(2), f = 2 242 # a(2), f = 2
243 # and this: 243 # and this:
300 return a 300 return a
301 301
302 # Domain of unary expressions: 302 # Domain of unary expressions:
303 303
304 def CastExpression(self): 304 def CastExpression(self):
305 # TODO: cast conflicts with '(' expr ')', so introduce extra keyword 'cast' 305 # type cast conflicts with '(' expr ')', so introduce extra keyword 'cast'
306 if self.Peak == 'cast': 306 if self.Peak == 'cast':
307 self.Consume('cast') 307 self.Consume('cast')
308 self.Consume('<') 308 self.Consume('<')
309 print('TODO: implement type cast')
310 t = self.parseTypeSpec() 309 t = self.parseTypeSpec()
311
312 # Type
313 self.Consume('>') 310 self.Consume('>')
314 self.Consume('(') 311 self.Consume('(')
315 ce = self.CastExpression() 312 ce = self.CastExpression()
316 self.Consume(')') 313 self.Consume(')')
317 # TODO: use type spec here 314 return astnodes.TypeCast(t, ce)
318 return ce
319 else: 315 else:
320 return self.UnaryExpression() 316 return self.UnaryExpression()
321 317
322 def UnaryExpression(self): 318 def UnaryExpression(self):
323 if self.Peak in ['&', '*']: 319 if self.Peak in ['&', '*']: