690 likes | 742 Views
… NPDAs continued. Pushing Strings. Pop symbol. Input symbol. Push string. Example:. input. pushed string. stack. top. Push. Another NPDA example. NPDA. Execution Example:. Time 0. Input. Stack. current state. Time 1. Input. Stack. Time 3. Input. Stack. Time 4. Input.
E N D
Pushing Strings Pop symbol Input symbol Push string
Example: input pushed string stack top Push
Another NPDA example NPDA
Execution Example: Time 0 Input Stack current state
Time 1 Input Stack
Time 3 Input Stack
Time 4 Input Stack
Time 5 Input Stack
Time 6 Input Stack
Time 7 Input Stack
Time 8 Input Stack accept
Formal Definition Non-Deterministic Pushdown Automaton NPDA Final states States Input alphabet Stack start symbol Transition function Stack alphabet
Instantaneous Description Current state Current stack contents Remaining input
Example: Instantaneous Description Input Time 4: Stack
Example: Instantaneous Description Input Time 5: Stack
We write: Time 4 Time 5
Formal Definition Language of NPDA : Initial state Final state
Example: NPDA :
Therefore: NPDA :
Theorem: Context-Free Languages (Grammars) Languages Accepted by NPDAs
Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by NPDAs Convert any context-free grammar to a NPDA with:
Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by NPDAs Convert any NPDA to a context-free grammar with:
An example grammar: What is the equivalent NPDA?
Grammar: NPDA:
The NPDA simulates leftmost derivations of the grammar L(Grammar) = L(NPDA)
Grammar: A leftmost derivation:
NPDA execution: Time 0 Input Stack current state
Time 1 Input Stack
Time 2 Input Stack
Time 3 Input Stack
Time 4 Input Stack
Time 5 Input Stack
Time 6 Input Stack
Time 7 Input Stack
Time 8 Input Stack
Time 9 Input Stack
Time 10 Input Stack accept
In general: Given any grammar We can construct a NPDA With
Constructing NPDA from grammar : For any production For any terminal
Grammar generates string if and only if NPDA accepts
Therefore: For any context-free language there is an NPDA that accepts the same language