1 … NPDAs continued
2 Pushing Strings Input symbol Pop symbol Push string
3 top input stack Push pushed string Example:
4 Another NPDA example NPDA
5 Time 0 Input current state Stack Execution Example:
6 Time 1 Input Stack
7 Time 3 Input Stack
8 Time 4 Input Stack
9 Time 5 Input Stack
10 Time 6 Input Stack
11 Time 7 Input Stack
12 Time 8 Input Stack accept
13 Formalities for NPDAs
14 Transition function:
15 Transition function:
16 Formal Definition Non-Deterministic Pushdown Automaton NPDA States Input alphabet Stack alphabet Transition function Final states Stack start symbol
17 Instantaneous Description Current state Remaining input Current stack contents
18 Input Stack Time 4: Example:Instantaneous Description
19 Input Stack Time 5: Example:Instantaneous Description
20 We write: Time 4 Time 5
21 A computation:
22 For convenience we write:
23 Formal Definition Language of NPDA : Initial state Final state
24 Example: NPDA :
25 NPDA :
26 NPDA : Therefore:
27 NPDAs Accept Context-Free Languages
28 Context-Free Languages (Grammars) Languages Accepted by NPDAs Theorem:
29 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 1: Convert any context-free grammar to a NPDA with:
30 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 2: Convert any NPDA to a context-free grammar with:
31 Converting Context-Free Grammars to NPDAs
32 An example grammar: What is the equivalent NPDA?
33 Grammar: NPDA:
34 The NPDA simulates leftmost derivations of the grammar L(Grammar) = L(NPDA)
35 Grammar: A leftmost derivation:
36 NPDA execution: Input Stack Time 0 current state
37 Input Stack Time 1
38 Input Stack Time 2
39 Input Stack Time 3
40 Input Stack Time 4
41 Input Stack Time 5
42 Input Stack Time 6
43 Input Stack Time 7
44 Input Stack Time 8
45 Input Stack Time 9
46 Input Stack Time 10 accept
47 In general: Given any grammar We can construct a NPDA With
48 Constructing NPDA from grammar : For any production For any terminal
49 Grammar generates string if and only if NPDA accepts
50 Therefore: For any context-free language there is an NPDA that accepts the same language
51 Converting NPDAs to Context-Free Grammars
52 For any NPDA we will construct a context-free grammar with
53 Intuition:The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA
54 in NPDA Input processedStack contents terminalsvariables A derivation in Grammar :
55 Some Necessary Modifications First, we modify the NPDA: It has a single final state It empties the stack when it accepts the input Original NPDA Empty Stack
56 Second, we modify the NPDA transitions: all transitions will have form or
57 Example of a NPDA in correct form:
58 The Grammar Construction In grammar : Terminals: Input symbols of NPDA states Stack symbol Variables:
59 For each transition We add production
60 For each transition We add production For all states
61 Start Variable: Stack bottom symbol Start state final state
62 Example: Grammar production:
63 Example: Grammar productions:
64 Example: Grammar production:
65 Resulting Grammar:
66
67 Derivation of string
68 In general, in Grammar: if and only if is accepted by the NPDA
69 Explanation: By construction of Grammar: if and only if in the NPDA going from to the stack doesn’t change below and is removed from stack