text
stringlengths
0
828
print '* Simplify State IDs:',
simple_a = SimplifyStateIDs()
mma.s, biggestid, newaccepted = simple_a.get(mma.s)
if newaccepted:
print 'OK'
else:
print 'OK'
print '* Eliminate READ states:',
replace = ReadReplace(mma.s, biggestid)
mma.s = replace.replace_read()
print 'OK'
print ' - Total PDA states now are ' + repr(len(mma.s))
maxstate = replace.nextstate() - 1
print '* Reduce PDA:',
simple_b = ReducePDA()
mma.s = simple_b.get(mma.s)
print 'OK'
print ' - Total PDA states now are ' + repr(len(mma.s))
print '* PDA to CFG transformation:',
cnfgenerator = PdaCnf(mma.s)
grammar = cnfgenerator.get_rules(optimized)
print 'OK'
print ' - Total CFG rules generated: ' + repr(len(grammar))
if mode == 'STR':
gen = CFGGenerator(CNFGenerator(grammar),
optimized=optimized,
splitstring=splitstring,
maxstate=maxstate)
print gen.generate()
else:
print grammar"
1775,"def get(self, statediag, dfaaccepted):
""""""
# - Remove all the POP (type - 2) transitions to state 0,non DFA accepted
# for symbol @closing
# - Generate the accepted transitions
- Replace DFA accepted States with a push - pop symbol and two extra states
Args:
statediag (list): The states of the PDA
dfaaccepted (list):The list of DFA accepted states
Returns:
list: A cleaned, smaller list of DFA states
""""""
newstatediag = {}
newstate = PDAState()
newstate.id = 'AI,I' # BECAREFUL WHEN SIMPLIFYING...
newstate.type = 1
newstate.sym = '@wrapping'
transitions = {}
transitions[(0, 0)] = [0]
newstate.trans = transitions
i = 0
newstatediag[i] = newstate
# print 'accepted:'
# print dfaaccepted
for stateid in statediag:
state = statediag[stateid]
# print state.id
if state.type == 2:
for state2id in dfaaccepted:
# print state.id[1]
if state.id[1] == state2id:
# print 'adding...'
state.trans['AI,I'] = ['@wrapping']
# print state.trans
break
i = i + 1
newstatediag[i] = state
return newstatediag"
1776,"def bfs(self, graph, start):
""""""
Performs BFS operation for eliminating useless loop transitions
Args:
graph (PDA): the PDA object
start (PDA state): The PDA initial state
Returns:
list: A cleaned, smaller list of DFA states
""""""
newstatediag = {}
# maintain a queue of paths
queue = []
visited = []
# push the first path into the queue
queue.append(start)
while queue:
# get the first path from the queue
state = queue.pop(0)
# get the last node from the path
# visited
visited.append(state.id)
# enumerate all adjacent nodes, construct a new path and push it
# into the queue