Skip to content

Commit 910b6ad

Browse files
committed
Automata v.1.4.2
Another empty stack error solved on prints; when you select the step by step visual transit, it has to print info from the stack, when it is empty, if fails, because it had not a validation when the stack is empty and it tries to print the top symbol of it :3
1 parent 60b3a6f commit 910b6ad

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pda.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ def transite(self, symbol: str, printStep: bool = False):
174174
#* and top stack symbol == transition[2], then:
175175
#* push on the stack each character of transition[3], and:
176176
#* self.currents.append([transition[4](next state on the transition tuple)]);
177+
177178
validTransitions = []
178179
for current in self.currents:
179180
for transition in self.Transitions:
180181
# print(self.stack[len(self.stack)-1])
181182
# print(f"if ({current} == {transition[0]}) and ({symbol} == {transition[1]} or {transition[1]} == \"\") and ({self.stack[len(self.stack)-1]} == {transition[2]}):")
182-
if (current == transition[0]) and (symbol == transition[1] or transition[1] == "") and (self.stack[len(self.stack)-1] == transition[2]) and (not self.error):
183+
#* If it has an empty stack and pendient transitions:
184+
if len(self.stack) == 0:
185+
topSymbol = ""
186+
else:
187+
topSymbol = self.stack[len(self.stack)-1]
188+
if (current == transition[0]) and (symbol == transition[1] or transition[1] == "") and (topSymbol == transition[2]) and (not self.error):
183189
print(" * Transición a tomar:", transition)
184190
validTransitions.append(transition)
185191

@@ -214,7 +220,11 @@ def transite(self, symbol: str, printStep: bool = False):
214220
userShowStack = self.stack[:]
215221
userShowStack.reverse()
216222
print(" * Pila:", userShowStack)
217-
print(" * Símbolo top en la pila:", self.stack[len(self.stack)-1])
223+
if len(self.stack) == 0:
224+
topSymbol = ""
225+
else:
226+
topSymbol = self.stack[len(self.stack)-1]
227+
print(" * Símbolo top en la pila:", topSymbol)
218228
print(" * Símbolo en apilar:", transition[3])
219229
destinies = []
220230
for destiny in validTransitions:
@@ -230,7 +240,7 @@ def transite(self, symbol: str, printStep: bool = False):
230240
if len(self.stack) > 0:
231241
self.stack.pop()
232242
else:
233-
self.error = True
243+
# self.error = True
234244
return
235245

236246
# It push down symbols on the stack:

safebox-validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def validatePassword(password: str):
6060
Automata = PDA(Estados, Alfabeto, Transiciones, Inicial, Finales, Alfapila, Pila)
6161
Automata.show()
6262
print()
63-
return True if Automata.accepts(password, stepByStep=False) else False
63+
return True if Automata.accepts(password, stepByStep=True) else False
6464

6565

6666
#* Punto de ejecución:

0 commit comments

Comments
 (0)