comparison python/c3/parser.py @ 221:848c4b15fd0b

pointers
author Windel Bouwman
date Mon, 08 Jul 2013 22:21:44 +0200
parents 3f6c30a5d234
children c3f1ce8b638f
comparison
equal deleted inserted replaced
220:3f6c30a5d234 221:848c4b15fd0b
274 e2 = self.Term() 274 e2 = self.Term()
275 e = astnodes.Binop(e, op.typ, e2, op.loc) 275 e = astnodes.Binop(e, op.typ, e2, op.loc)
276 return e 276 return e
277 277
278 def Term(self): 278 def Term(self):
279 t = self.Factor() 279 t = self.BitwiseOr()
280 while self.Peak in ['*', '/']: 280 while self.Peak in ['*', '/']:
281 op = self.Consume(self.Peak) 281 op = self.Consume(self.Peak)
282 t2 = self.Factor() 282 t2 = self.BitwiseOr()
283 t = astnodes.Binop(t, op.typ, t2, op.loc) 283 t = astnodes.Binop(t, op.typ, t2, op.loc)
284 return t 284 return t
285 285
286 def Factor(self): 286 def BitwiseOr(self):
287 # TODO: eliminate this step? 287 a = self.BitwiseAnd()
288 return self.CastExpression() 288 while self.Peak in ['|']:
289 op = self.Consume(self.Peak)
290 b = self.BitwiseAnd()
291 a = astnodes.Binop(a, op.typ, b, op.loc)
292 return a
293
294 def BitwiseAnd(self):
295 a = self.CastExpression()
296 while self.Peak in ['&']:
297 op = self.Consume(self.Peak)
298 b = self.CastExpression()
299 a = astnodes.Binop(a, op.typ, b, op.loc)
300 return a
289 301
290 # Domain of unary expressions: 302 # Domain of unary expressions:
291 303
292 def CastExpression(self): 304 def CastExpression(self):
293 # TODO: cast conflicts with '(' expr ')' 305 # TODO: cast conflicts with '(' expr ')', so introduce extra keyword 'cast'
294 if self.Peak == '(ii': 306 if self.Peak == 'cast':
307 self.Consume('cast')
308 self.Consume('<')
309 print('TODO: implement type cast')
310 t = self.parseTypeSpec()
311
312 # Type
313 self.Consume('>')
295 self.Consume('(') 314 self.Consume('(')
296 print('TODO: implement type cast') 315 ce = self.CastExpression()
297 #rrrrr
298 self.parseTypeSpec()
299
300 # Type
301 self.Consume(')') 316 self.Consume(')')
302 ce = self.CastExpression() 317 # TODO: use type spec here
303 return ce 318 return ce
304 else: 319 else:
305 return self.UnaryExpression() 320 return self.UnaryExpression()
306 321
307 def UnaryExpression(self): 322 def UnaryExpression(self):