text
stringlengths
0
828
state.sym = destination_and_symbol
state.trans = {}
state.trans[destination_and_symbol] = [0]
statenumber_identifier = len(self.statediag) + 1
for state in self.toadd:
self.statediag[statenumber_identifier] = state
statenumber_identifier = statenumber_identifier + 1
return self.statediag"
1781,"def insert_self_to_empty_and_insert_all_intemediate(self, optimized):
""""""
For each state qi of the PDA, we add the rule Aii -> e
For each triplet of states qi, qj and qk, we add the rule Aij -> Aik Akj.
Args:
optimized (bool): Enable or Disable optimization - Do not produce O(n^3)
""""""
for state_a in self.statediag:
self.rules.append('A' +repr(state_a.id) +',' + repr(state_a.id) + ': @empty_set')
# If CFG is not requested, avoid the following O(n^3) rule.
# It can be solved and a string can be generated faster with BFS of DFS
if optimized == 0:
for state_b in self.statediag:
if state_b.id != state_a.id:
for state_c in self.statediag:
if state_c.id != state_a.id \
and state_b.id != state_c.id:
self.rules.append('A' + repr(state_a.id)
+ ',' + repr(state_c.id)
+ ': A' + repr(state_a.id)
+ ',' + repr(state_b.id)
+ ' A' + repr(state_b.id)
+ ',' + repr(state_c.id)
+ '')"
1782,"def insert_symbol_pushpop(self):
""""""
For each stack symbol t E G, we look for a pair of states, qi and qj,
such that the PDA in state qi can read some input a E S and push t
on the stack and in state state qj can read some input b E S and pop t
off the stack. In that case, we add the rule Aik -> a Alj b
where (ql,t) E d(qi,a,e) and (qk,e) E d(qj,b,t).
""""""
for state_a in self.statediag:
if state_a.type == 1:
found = 0
for state_b in self.statediag:
if state_b.type == 2 and state_b.sym == state_a.sym:
found = 1
for j in state_a.trans:
if state_a.trans[j] == [0]:
read_a = ''
else:
new = []
for selected_transition in state_a.trans[j]:
if selected_transition == ' ':
new.append('&')
else:
new.append(selected_transition)
read_a = "" | "".join(new)
for i in state_b.trans:
if state_b.trans[i] == [0]:
read_b = ''
else:
new = []
for selected_transition in state_b.trans[i]:
if selected_transition == ' ':
new.append('&')
else:
new.append(selected_transition)
read_b = "" | "".join(new)
self.rules.append(
'A' + repr(state_a.id)
+ ',' + repr(i)
+ ':' + read_a
+ ' A' + repr(j)
+ ',' + repr(state_b.id)
+ ' ' + read_b)
if found == 0:
# A special case is required for State 2, where the POPed symbols
# are part of the transitions array and not defined for ""sym"" variable.
for state_b in self.statediag:
if state_b.type == 2 and state_b.sym == 0:
for i in state_b.trans:
if state_a.sym in state_b.trans[i]:
for j in state_a.trans:
if state_a.trans[j] == [0]:
read_a = ''
else:
read_a = "" | "".join(
state_a.trans[j])
self.rules.append(
'A' + repr(state_a.id)
+ ',' + repr(i)
+ ':' + read_a
+ ' A' + repr(j)
+ ',' + repr(state_b.id))