PDAs Accept Context-Free Languages

Slides:



Advertisements
Similar presentations
PDAs Accept Context-Free Languages
Advertisements

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Prof. Busch - LSU1 Properties of Context-Free languages.
Courtesy Costas Busch - RPI1 Positive Properties of Context-Free languages.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Costas Busch - RPI1 Positive Properties of Context-Free languages.
Fall 2003Costas Busch - RPI1 Decidable Problems of Regular Languages.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Prof. Busch - RPI1 Decidable Problems of Regular Languages.
1 Applications of Regular Closure. 2 The intersection of a context-free language and a regular language is a context-free language context free regular.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
1 A Non Context-Free Language (We will prove it at the next class)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Costas Busch - LSU1 Properties of Context-Free languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
Formal Languages, Automata and Models of Computation
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Formal Languages, Automata and Models of Computation
Standard Representations of Regular Languages
G. Pullaiah College of Engineering and Technology
Properties of Context-Free Languages
PDAs Accept Context-Free Languages
Properties of Regular Languages
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
PROPERTIES OF REGULAR LANGUAGES
Linear Bounded Automata LBAs
7. Properties of Context-Free Languages
NPDAs Accept Context-Free Languages
Simplifications of Context-Free Grammars
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Chapter 7 PUSHDOWN AUTOMATA.
NPDAs Accept Context-Free Languages
Single Final State for NFA
DPDA Deterministic PDA
CSE322 PROPERTIES OF REGULAR LANGUAGES
Properties of Regular Languages
Decidable Languages Costas Busch - LSU.
Deterministic PDAs - DPDAs
Closure Properties of Context-Free languages
Decidable Problems of Regular Languages
The Pumping Lemma for CFL’s
Properties of Context-Free languages
DPDA Deterministic PDA
… NPDAs continued.
Applications of Regular Closure
NFAs accept the Regular Languages
Normal Forms for Context-free Grammars
Presentation transcript:

PDAs Accept Context-Free Languages

Theorem: Context-Free Languages (Grammars) Languages Accepted by PDAs

Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any context-free grammar to a PDA with:

Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any PDA to a context-free grammar with:

Converting Context-Free Grammars to PDAs Proof - step 1 Converting Context-Free Grammars to PDAs

Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any context-free grammar to a PDA with:

We will convert grammar to a PDA such that: simulates leftmost derivations of

Convert grammar to PDA Production in Terminal in

PDA computation Grammar leftmost derivation Simulates grammar variable

Example Grammar PDA

Grammar derivation PDA computation

Derivation: Input Time 0 Stack

Derivation: Input Time 0 Stack

Derivation: Input Time 1 Stack

Derivation: Input Time 2 Stack

Derivation: Input Time 3 Stack

Derivation: Input Time 4 Stack

Derivation: Input Time 5 Stack

Derivation: Input Time 6 Stack

Derivation: Input Time 7 Stack

Derivation: Input Time 8 Stack

Derivation: Input Time 9 Stack accept

In general, it can be shown that: Grammar generates string If and Only if PDA accepts Therefore

Therefore: For any context-free language there is a PDA that accepts Context-Free Languages (Grammars) Languages Accepted by PDAs

Converting PDAs to Context-Free Grammars Proof - step 2 Converting PDAs to Context-Free Grammars

Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any PDA to a context-free grammar with:

We can convert PDA to a context-free grammar such that: simulates computations of with leftmost derivations

1. Modify the PDA so that the stack is never empty during computation Stack OK OK NOT OK

Introduce the new symbol to mark the bottom of the stack

At the beginning insert into the stack Original PDA new initial state original initial state

l , ® # Convert all transitions so that after popping the automaton halts pop pop # ® , l halting state

2. Modify the PDA so that at end it empties stack and has a unique accept state Empty stack PDA l ® , l ® , l ® , New accept state Old accept states

Deterministic PDAs - DPDAs

Deterministic PDA: DPDA Allowed transitions: (deterministic choices)

Allowed transitions: (deterministic choices)

Not allowed: (non deterministic choices)

DPDA example

Definition: A language is deterministic context-free if there exists some DPDA that accepts it Example: The language is deterministic context-free

Example of Non-DPDA (PDA)

Not allowed in DPDAs

PDAs Have More Power than DPDAs

It holds that: Deterministic Context-Free Languages (DPDA) Context-Free Languages PDAs Since every DPDA is also a PDA

We will actually show: Deterministic Context-Free Languages (DPDA) Context-Free Languages (PDA) We will show that there exists a context-free language which is not accepted by any DPDA

The language is: We will show: is context-free is not deterministic context-free

Language is context-free Context-free grammar for :

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 is a DPDA that accepts

DPDA with accepts accepts

DPDA with Such a path exists due to determinism

Context-free languages Fact 1: The language is not context-free Regular languages Context-free languages (we will prove this at a later class using pumping lemma for context-free languages)

Fact 2: The language is not context-free (we can prove this using pumping lemma for context-free languages)

We will construct a PDA that accepts: which is a contradiction!

DPDA Replace with Modify DPDA

A PDA that accepts Connect the final states of with the final states of

Since is accepted by a PDA it is context-free Contradiction! (since is not context-free)

Therefore: Is not deterministic context free There is no DPDA that accepts it End of Proof

Positive Properties of Context-Free languages

Union Context-free languages are closed under: Union is context free

Example Language Grammar Union

In general: For context-free languages with context-free grammars and start variables The grammar of the union has new start variable and additional production

Concatenation Context-free languages are closed under: Concatenation is context free is context free is context-free

Example Language Grammar Concatenation

In general: For context-free languages with context-free grammars and start variables The grammar of the concatenation has new start variable and additional production

Star Operation Context-free languages are closed under: Star-operation is context free is context-free

Example Language Grammar Star Operation

In general: For context-free language with context-free grammar and start variable The grammar of the star operation has new start variable and additional production

Negative Properties of Context-Free Languages

Intersection Context-free languages are not closed under: intersection is context free is context free not necessarily context-free

Example Context-free: Context-free: Intersection NOT context-free

Complement Context-free languages are not closed under: complement is context free not necessarily context-free

Example Context-free: Context-free: Complement NOT context-free

Intersection of Context-free languages and Regular Languages

The intersection of a context-free language and a regular language is a context-free language context free regular context-free

Machine Machine DFA for NPDA for regular context-free Construct a new NPDA machine that accepts simulates in parallel and

NPDA DFA transition transition NPDA transition

NPDA DFA transition NPDA transition

NPDA DFA initial state initial state NPDA Initial state

NPDA DFA final state final states NPDA final states

Example: context-free NPDA

regular DFA

context-free Automaton for: NPDA

In General: simulates in parallel and accepts string if and only if accepts string and accepts string

Therefore: is NPDA is context-free is context-free

Applications of Regular Closure

The intersection of a context-free language and a regular language is a context-free language Regular Closure context free regular context-free

An Application of Regular Closure Prove that: is context-free

We know: is context-free

We also know: is regular is regular

context-free regular (regular closure) context-free is context-free

Another Application of Regular Closure Prove that: is not context-free

Impossible!!! If is context-free Then context-free regular (regular closure) Then context-free regular context-free Impossible!!! Therefore, is not context free

Decidable Properties of Context-Free Languages

Membership Question: for context-free grammar find if string Membership Algorithms: Parsers Exhaustive search parser CYK parsing algorithm

Empty Language Question: for context-free grammar find if Algorithm: Remove useless variables Check if start variable is useless

Infinite Language Question: for context-free grammar find if is infinite Algorithm: 1. Remove useless variables 2. Remove unit and productions 3. Create dependency graph for variables 4. If there is a loop in the dependency graph then the language is infinite

Example: Infinite language Dependency graph