Пример #1
0
def create_AFND(re):
	deltas = []

	initial_node = ShuntingYard.create_tree(ShuntingYard.to_rpn(re))

	s = State('s')
	f = State('f')
	automaton = {s.name: s, f.name: f}
	#automaton = {s.name: s}

	s.add_transition(initial_node, f);
	deltas.append((s,initial_node))

	while len(deltas) > 0:
		(origin, simbol) = deltas.pop()
		
		if not origin in automaton.values():
			automaton.setdefault(origin.name, origin)

		if isinstance(simbol, ShuntingYard.Node):
			aux_deltas = Thompson.generic(origin, simbol)
			for t in aux_deltas:
				deltas.insert(0, t)

	for state_name in automaton:
		automaton[state_name].update_closure()

	return automaton
Пример #2
0
	def __create_AFND(self):
		deltas = []
		initial_node = ShuntingYard.create_tree(ShuntingYard.to_rpn(self.re))
		self.s.add_transition(initial_node, self.f);
		deltas.append((self.s,initial_node))

		while len(deltas) > 0:
			(origin, simbol) = deltas.pop()
			if not origin in self.states.values():
				self.states.setdefault(origin.name, origin)

			if isinstance(simbol, ShuntingYard.Node):
				aux_deltas = Thompson.generic(origin, simbol)
				for t in aux_deltas:
					deltas.insert(0, t)

		for state_name in self.states:
			self.states[state_name].update_closure()