pycl/Code/BUAParser.py
def parse(input, grammar, rootsymbol):
	"""Simple non-recursive bottom up parser."""
	agenda = []
	while True:
		print "Input: %s" % (input,)
		if input == rootsymbol:
			print "Success!"
			break
		else:
			for i in range(1, len(input) + 1):     # window
				for j in range(len(input) - i + 1): # movement
					for lhs in grammar.RHS.get(tuple(input[j:i + j]), []):
						newhyp = input[:j] + [lhs] + input[i + j:]
						if newhyp not in agenda:
							agenda.append(newhyp)
			if len(agenda) > 0:
				input = agenda.pop(strategy)
				print "Backing up to: ", input
			else:
				if input == rootsymbol:  print "Success!"
				else:  print "Failure! No more backtracking!"
				break
Simple non-recursive bottom up parser.
Simple non-recursive bottom up parser.
Simple non - recursive bottom up parser .
def parse(input, grammar, rootsymbol):
	agenda = []
	while True:
		print "Input: %s" % (input,)
		if input == rootsymbol:
			print "Success!"
			break
		else:
			for i in range(1, len(input) + 1):     
				for j in range(len(input) - i + 1): 
					for lhs in grammar.RHS.get(tuple(input[j:i + j]), []):
						newhyp = input[:j] + [lhs] + input[i + j:]
						if newhyp not in agenda:
							agenda.append(newhyp)
			if len(agenda) > 0:
				input = agenda.pop(strategy)
				print "Backing up to: ", input
			else:
				if input == rootsymbol:  print "Success!"
				else:  print "Failure! No more backtracking!"
				break
def parse ( input , grammar , rootsymbol ) : agenda = [ ] while True : print "Input: %s" % ( input , ) if input == rootsymbol : print "Success!" break else : for i in range ( 1 , len ( input ) + 1 ) : for j in range ( len ( input ) - i + 1 ) : for lhs in grammar . RHS . get ( tuple ( input [ j : i + j ] ) , [ ] ) : newhyp = input [ : j ] + [ lhs ] + input [ i + j : ] if newhyp not in agenda : agenda . append ( newhyp ) if len ( agenda ) > 0 : input = agenda . pop ( strategy ) print "Backing up to: " , input else : if input == rootsymbol : print "Success!" else : print "Failure! No more backtracking!" break
Simple non-recursive bottom up parser.
Simple non - recursive bottom up parser .
"""Simple non-recursive bottom up parser.""" # window # movement
input
grammar
rootsymbol