11""" A transition function in a pushdown automaton """
22
33from copy import deepcopy
4- from typing import Dict , List , Set , Iterator , Iterable , Tuple , Optional
4+ from typing import Dict , Set , Sequence , Iterator , Iterable , Tuple
55
66from ..objects .pda_objects import State , Symbol , StackSymbol
77
88TransitionKey = Tuple [State , Symbol , StackSymbol ]
9- TransitionValue = Tuple [State , List [StackSymbol ]]
9+ TransitionValue = Tuple [State , Tuple [StackSymbol , ... ]]
1010TransitionValues = Set [TransitionValue ]
1111Transition = Tuple [TransitionKey , TransitionValue ]
1212
@@ -16,9 +16,6 @@ class TransitionFunction(Iterable[Transition]):
1616
1717 def __init__ (self ) -> None :
1818 self ._transitions : Dict [TransitionKey , TransitionValues ] = {}
19- self ._current_key : Optional [TransitionKey ] = None
20- self ._iter_key : Optional [Iterator [TransitionKey ]] = None
21- self ._iter_inside : Optional [Iterator [TransitionValue ]] = None
2219
2320 def get_number_transitions (self ) -> int :
2421 """ Gets the number of transitions
@@ -36,7 +33,7 @@ def add_transition(self,
3633 input_symbol : Symbol ,
3734 stack_from : StackSymbol ,
3835 s_to : State ,
39- stack_to : List [StackSymbol ]) -> None :
36+ stack_to : Sequence [StackSymbol ]) -> None :
4037 """ Add a transition to the function
4138
4239 Parameters
@@ -53,7 +50,7 @@ def add_transition(self,
5350 The string of stack symbol which replace the stack_from
5451 """
5552 temp_in = (s_from , input_symbol , stack_from )
56- temp_out = (s_to , stack_to . copy ( ))
53+ temp_out = (s_to , tuple ( stack_to ))
5754 if temp_in in self ._transitions :
5855 self ._transitions [temp_in ].add (temp_out )
5956 else :
@@ -71,7 +68,7 @@ def copy(self) -> "TransitionFunction":
7168 for temp_in , transition in self ._transitions .items ():
7269 for temp_out in transition :
7370 new_tf .add_transition (temp_in [0 ], temp_in [1 ], temp_in [2 ],
74- temp_out [ 0 ], temp_out [ 1 ] )
71+ * temp_out )
7572 return new_tf
7673
7774 def __iter__ (self ) -> Iterator [Transition ]:
0 commit comments