comparison python/pyyacc.py @ 377:9667d78ba79e

Switched to xml for project description
author Windel Bouwman
date Fri, 11 Apr 2014 15:47:50 +0200
parents 3bb7dcfe5529
children 173e20a47fda
comparison
equal deleted inserted replaced
376:1e951e71d3f1 377:9667d78ba79e
355 stack = [0] 355 stack = [0]
356 r_data_stack = [] 356 r_data_stack = []
357 look_ahead = lexer.next_token() 357 look_ahead = lexer.next_token()
358 assert type(look_ahead) is Token 358 assert type(look_ahead) is Token
359 # TODO: exit on this condition: 359 # TODO: exit on this condition:
360 while stack != [0, self.start_symbol, 2222]: 360 while stack != [0, self.start_symbol, 0]:
361 state = stack[-1] # top of stack 361 state = stack[-1] # top of stack
362 key = (state, look_ahead.typ) 362 key = (state, look_ahead.typ)
363 if not key in self.action_table: 363 if not key in self.action_table:
364 raise ParserException('Error parsing at character {0}'.format(look_ahead)) 364 raise ParserException('Error parsing at character {0}'.format(look_ahead))
365 action = self.action_table[key] 365 action = self.action_table[key]
396 if param.f: 396 if param.f:
397 ret_val = param.f(*f_args) 397 ret_val = param.f(*f_args)
398 else: 398 else:
399 ret_val = None 399 ret_val = None
400 # Break out! 400 # Break out!
401 stack.append(param.name)
402 stack.append(0)
401 break 403 break
402 # At exit, the stack must be 1 long 404 # At exit, the stack must be 1 long
403 # TODO: fix that this holds: 405 # TODO: fix that this holds:
404 #assert len(stack) == 1, 'stack {0} not totally reduce'.format(stack) 406 #assert stack == [0, self.start_symbol, 0]
405 return ret_val 407 return ret_val
408