430 likes | 443 Vues
Converting NPDAs to Context-Free Grammars. For any NPDA. we will construct a context-free grammar with. Intuition:. The grammar simulates the machine. A derivation in Grammar :. Current configuration in NPDA. A derivation in Grammar :. terminals. variables.
E N D
For any NPDA we will construct a context-free grammar with
Intuition: The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA
A derivation in Grammar : terminals variables Input processed Stack contents in NPDA
Some Necessary Modifications • First, we modify the NPDA: • It has a single final state • It empties the stack • when it accepts the input Empty Stack Original NPDA
Second, we modify the NPDA transitions: • all transitions will have form or
The Grammar Construction stack symbol In grammar variables have form states Terminals are input symbols
For each transition We add production For all states
For each transition We add production For all states in the NPDA
Stack bottom symbol Start Variable: Start state final state
Example: Grammar production:
Example: Grammar productions:
Example: Grammar production:
In general, in grammar if and only if is accepted by the NPDA
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
DPDAs • Allowed Transitions:
Not allowed: Not allowed even when is
Not allowed: Not allowed even when is
The language is deterministic context-free
In general: A language is deterministic context-free if there is some NPDA that accepts it
We will show: There is (accepted by a NPDA) a context-free language which is not (not accepted by a DPDA) deterministic context-free
The language is context-free Context-free grammar for : (there is an NPDA that accepts )
Theorem: The language is not deterministic context-free (there is no DPDA that accepts )
Proof: Assume for contradiction that is deterministic context free Therefore: There exists a DPDA that accepts
The DPDA with accepts accepts
A fact: The language is not context-free (we will prove it at the next class)
Another fact: The language is not context-free
First, we modify : Replace with Modified
The NPDA that accepts Modified Original
is accepted by a NPDA Therefore: is context-free Contradiction! ( is not context-free)
Therefore: There is no DPDA that accepts End of Proof