text stringlengths 0 828 |
|---|
for key in state.trans: |
if state.trans[key] != []: |
if key not in visited: |
for nextstate in graph: |
if graph[nextstate].id == key: |
queue.append(graph[nextstate]) |
break |
i = 0 |
for state in graph: |
if graph[state].id in visited: |
newstatediag[i] = graph[state] |
i = i + 1 |
return newstatediag" |
1777,"def get(self, statediag): |
"""""" |
Args: |
statediag (list): The states of the PDA |
Returns: |
list: A reduced list of states using BFS |
"""""" |
if len(statediag) < 1: |
print 'PDA is empty and can not be reduced' |
return statediag |
newstatediag = self.bfs(statediag, statediag[0]) |
return newstatediag" |
1778,"def get(self, statediag, accepted=None): |
"""""" |
Replaces complex state IDs as generated from the product operation, |
into simple sequencial numbers. A dictionaty is maintained in order |
to map the existed IDs. |
Args: |
statediag (list): The states of the PDA |
accepted (list): the list of DFA accepted states |
Returns: |
list: |
"""""" |
count = 0 |
statesmap = {} |
newstatediag = {} |
for state in statediag: |
# Simplify state IDs |
if statediag[state].id not in statesmap: |
statesmap[statediag[state].id] = count |
mapped = count |
count = count + 1 |
else: |
mapped = statesmap[statediag[state].id] |
# Simplify transitions IDs |
transitions = {} |
for nextstate in statediag[state].trans: |
if nextstate not in statesmap: |
statesmap[nextstate] = count |
transmapped = count |
count = count + 1 |
else: |
transmapped = statesmap[nextstate] |
transitions[transmapped] = statediag[state].trans[nextstate] |
newstate = PDAState() |
newstate.id = mapped |
newstate.type = statediag[state].type |
newstate.sym = statediag[state].sym |
newstate.trans = transitions |
newstatediag[mapped] = newstate |
newaccepted = None |
if accepted is not None: |
newaccepted = [] |
for accepted_state in accepted : |
if (0, accepted_state) in statesmap: |
newaccepted.append(statesmap[(0, accepted_state)]) |
return newstatediag, count, newaccepted" |
1779,"def _generate_state(self, trans): |
"""""" |
Creates a new POP state (type - 2) with the same transitions. |
The POPed symbol is the unique number of the state. |
Args: |
trans (dict): Transition dictionary |
Returns: |
Int: The state identifier |
"""""" |
state = PDAState() |
state.id = self.nextstate() |
state.type = 2 |
state.sym = state.id |
state.trans = trans.copy() |
self.toadd.append(state) |
return state.id" |
1780,"def replace_read(self): |
"""""" |
Replaces all READ (type - 3) states to a PUSH (type - 1) and a POP (type - 2). |
The actual state is replaced with the PUSH, and a new POP is created. |
"""""" |
for statenum in self.statediag: |
state = self.statediag[statenum] |
if state.type == 3: # READ state |
state.type = 1 |
destination_and_symbol = self._generate_state(state.trans) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.