File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """This is an example of using a PDA to parse strings with
2+ well-formed parentheses."""
3+ from PDA import *
4+ from State import *
5+
6+ accept5 = State (state_type = "Accept" )
7+ pop4 = State (state_type = "Pop" )
8+ pop3 = State (state_type = "Pop" )
9+ push2 = State (state_type = "Push" )
10+ read1 = State (state_type = "Read" )
11+
12+ # add transitions for 'a', 'b', and the 'end' of the tape.
13+ read1 .add_transition (push2 , character = "(" )
14+ read1 .add_transition (pop3 , character = ")" )
15+ read1 .add_transition (pop4 , character = "!" )
16+
17+ push2 .add_transition (read1 , character = "X" )
18+ pop3 .add_transition (read1 , character = "X" )
19+
20+ pop4 .add_transition (accept5 , character = "!" )
21+
22+ start_state = State (state_type = "Start" , next_state = read1 )
23+
24+ my_pda = PDA (start_state )
25+
26+ tape_word = "(((((((()))(((())))()()((())))))))!"
27+ my_pda .start (tape = tape_word , stack = ['!' ], verbose = False )
You can’t perform that action at this time.
0 commit comments