pycl/Code/TDAParser.py
def tdparse(input, goal, grammar, agenda):
	"""Recursive top-down parse function with weak generative capacity."""

	#print "Got : %s\tinput: %s\nwith agenda:\n%s" % (goal, input, agenda)
	print "Got : %s\tinput: %s" % (goal, input)

	if goal == input == []:  print "Success"
	elif goal == [] or input == []:
		if agenda == []:  print "Fail: Agenda empty!"
		else:
			entry = agenda.pop(strategy)
			print "Backing up to: %s with %s" % (entry[0], entry[1])
			tdparse(entry[1], entry[0], grammar, agenda)
	else: # there is something in goal and input
		if goal[0] == input[0]: # if initial symbols match, reduce lists, parse
			tdparse(input[1:], goal[1:], grammar, agenda)
		else:
			for i in grammar.LHS.get(goal[0], []):
				if [list(i) + goal[1:], input] not in agenda:
					agenda.append([list(i) + goal[1:], input])
			if len(agenda) > 0:
				entry = agenda.pop(strategy)
				tdparse(entry[1], entry[0], grammar, agenda)
			else:  print "Fail: Agenda empty!"
Recursive top-down parse function with weak generative capacity.
Recursive top-down parse function with weak generative capacity.
Recursive top - down parse function with weak generative capacity .
def tdparse(input, goal, grammar, agenda):
	print "Got : %s\tinput: %s" % (goal, input)
	if goal == input == []:  print "Success"
	elif goal == [] or input == []:
		if agenda == []:  print "Fail: Agenda empty!"
		else:
			entry = agenda.pop(strategy)
			print "Backing up to: %s with %s" % (entry[0], entry[1])
			tdparse(entry[1], entry[0], grammar, agenda)
	else: 
		if goal[0] == input[0]: 
			tdparse(input[1:], goal[1:], grammar, agenda)
		else:
			for i in grammar.LHS.get(goal[0], []):
				if [list(i) + goal[1:], input] not in agenda:
					agenda.append([list(i) + goal[1:], input])
			if len(agenda) > 0:
				entry = agenda.pop(strategy)
				tdparse(entry[1], entry[0], grammar, agenda)
			else:  print "Fail: Agenda empty!"
def tdparse ( input , goal , grammar , agenda ) : print "Got : %s\tinput: %s" % ( goal , input ) if goal == input == [ ] : print "Success" elif goal == [ ] or input == [ ] : if agenda == [ ] : print "Fail: Agenda empty!" else : entry = agenda . pop ( strategy ) print "Backing up to: %s with %s" % ( entry [ 0 ] , entry [ 1 ] ) tdparse ( entry [ 1 ] , entry [ 0 ] , grammar , agenda ) else : if goal [ 0 ] == input [ 0 ] : tdparse ( input [ 1 : ] , goal [ 1 : ] , grammar , agenda ) else : for i in grammar . LHS . get ( goal [ 0 ] , [ ] ) : if [ list ( i ) + goal [ 1 : ] , input ] not in agenda : agenda . append ( [ list ( i ) + goal [ 1 : ] , input ] ) if len ( agenda ) > 0 : entry = agenda . pop ( strategy ) tdparse ( entry [ 1 ] , entry [ 0 ] , grammar , agenda ) else : print "Fail: Agenda empty!"
Recursive top-down parse function with weak generative capacity.
Recursive top - down parse function with weak generative capacity .
"""Recursive top-down parse function with weak generative capacity.""" #print "Got : %s\tinput: %s\nwith agenda:\n%s" % (goal, input, agenda) # there is something in goal and input # if initial symbols match, reduce lists, parse
input
goal
grammar
agenda