Title: Outline for Test
1Outline for Test 2
26b Pushdown Automata 7.1,7.2,7.3
- Outline for Test 2
- Deterministic Pushdown Simulator
- Define Non-Deterministic Pushdown Automata (npda)
- State Graphs, State Tables for npda (not in text)
- Instantaneous Description of a npda
- Acceptance of a Language by a npda
- Constructing a npda for a Given Language
- npda Corresponding to an Arbitrary Context-Free
Grammar - Context-Free Grammar for a npda
- Deterministic Context-Free Languages
3Block Diagram of Pushdown Acceptor
Input Tape
Pushdown Store
Finite-State Control
z
4Pushdown Machine Simulation
- http//cs.union.edu/csc140/simulators/
- Simulates only deterministic machines
- Accepts by Final State AND Empty Stack
- (different than textbook and written HW)
- Handout Sample Pushdown Machines
- Unusual Simulation will get extra credit
Simulate SOMETHING for regular credit
5Define Non-Deterministic Pushdown Automaton (npda)
- M (Q, ?, ?, ?, q0 , z, F) ordered septuple
- Q finite set of states
- ? input alphabet
- ? stack alphabet
- q0 ? Q initial state
- z ? ? stack start symbol
- F ? Q set of final states
6Transition Function
- ? Q ??? ? ? 2Q ?
- ?(q0,a,z) (q1,0z), (q0,z)
- ?(q0,b,z) (q1,z)
- ?(q1,b,0) (q1,?)
- ?(q1,?,z) (qf,z) qf final state
7Trace the Action of an npda
- ?(q0,a,z) (q1,0z), (q0,z)
- ?(q0,b,z) (q1,z)
- ?(q1,b,0) (q1,?)
- ?(q1,?,z) (qf,z) qf final state
- input aab
- watch stack...
8State Graphs for npda (not in text)
b,0/?
?,z/z
q0
qf
a,z/0z a,0/00
9Instantaneous Description of a npda
- represents a move
- (q0,aabb,z) (q0,abb,0z) (q0,bb,00z)
- (q1,b, 0z) (q1,?,z) (qf,?,z)
10Acceptance of a Language by a npda
- L(M) w in ? (q0,w,z) M (p,?,u) where p
? F, u ? ? - Called acceptance by final state. Equivalently we
could have defined it by empty stack or both
final state and empty stack
11Constructing a npda for a Given Language
- Key issue in design is the use of the stack
- na(w) nb(w) page 179-80
- wwR page 180-81
- aibi i ? 0
12npda Corresponding to an Arbitrary Context-Free
Grammar
- First Convert language to Greibach form
- Corresponding npda will have three states
- q0, q1, qf, q0 is initial state, qf is only
final state - Add transitions
- ?(q0, ?, z) (q1, Sz) and
- ?(q1, ?, z) (qf, z)
- Non-terminals become stack symbols
- not states as with right-linear grammars
- Add transitions for each production in grammar
- see page 194
13Sample Conversioncfg to npda
- S ? aAS bAB aB
- A ? bBB aS a
- B ? bA a
14Context-Free Grammar for a npda
- To be converted, npda has two restrictions
- single final state, qf, that is entered if and
only if the stack is empty - each move either increases (or decreases) the
stack content by one symbol - Other npdas can easily be converted to
equivalent machines with these restrictions(i.e.
I won't ask you to convert on test)
15npda Conversion to cf Grammar(grammar
"simulates" machine)
- "Plug and Chug" from pages 189-90
- All transitions are of one of the following two
types - ?(qi,a,A) c1, c2, , cn where either
- (7.5) ci (qj, ?)
- (7.6) ci (qj, BC)
- For transitions of type (7.5) add productions
- (qiAqj) ? a
- For transitions of type (7.6) add productions
- (qiAqk) ? a(qjBql)(qlCqk) for all qk and ql in Q
- Finally, take (q0zqf) as the S in the grammar
16Sample Conversion
b,0/?
?,z/?
From (7.6) (q0zq0) ?a(q00q0)(q0zq0)(q0zq0)
?a(q00qf)(qfzq0) (q0zqf) ?a(q00q0)(q0zqf)(q0zqf)
?a(q00qf)(qfzqf) (q00q0) ?a(q00q0)(q00q0)(q00q0
) ?a(q00qf)(qf0q0) (q00qf) ?a(q00q0)(q00qf)(q00q
f) ?a(q00qf)(qf0qf)
q0
qf
a,z/0z a,0/00
From (7.5)(q00q0) ? b(q0zqf) ? ?
17(qfzq0), (qfzqf), (qf0q0) and (qf0qf) are
undefined(q0zq0) and (q00qf) are nonterminating
- (q00q0) ? b(q0zqf) ? ?
- (q0zq0) ?a(q00q0)(q0zq0)(q0zq0)
?a(q00qf)(qfzq0)(q0zqf) ?a(q00q0)(q0zqf)(q0zqf)
?a(q00qf)(qfzqf) - (q00q0) ?a(q00q0)(q00q0)(q00q0)
?a(q00qf)(qf0q0)(q00qf) ?a(q00q0)(q00qf)(q00qf)
?a(q00qf)(qf0qf)
- Replacing (q0zqf) with S
- and (q00q0) with B we get
- S ? ? aBS
- B ? b aBB
18Deterministic Context-Free Languages
- Given w ? a,b, considerwwR vs. wcwR
- What about wcw? (trick questionlooks simpler
than wcwR) - It turns out that wcw is not context free
- Stay tuned for proof (next class)
19In-Class ExerciseJavaScript Pushdown Simulator
- Work in groups of 2 or 3
- (state graph of first 2 groups finished on board)
- Link to
- cs.union.edu/csc140/simulators
- Given
- L anbn n?1
- L wcwR w in a,b
- Create a machine to accept
- L set of matched parentheses, ? (,),,
- See language of exercise 5.1.21 page 135
- Recall To accept, simulator needs final state
and empty stack.