Formal Languages, Automata and Models of Computation

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata CPSC 388 Ellen Walker Hiram College.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
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.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
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.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 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.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Formal Languages, Automata and Models of Computation
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.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
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.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
G. Pullaiah College of Engineering and Technology
PDAs Accept Context-Free Languages
Non Deterministic Automata
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
NPDAs Accept Context-Free Languages
Pushdown Automata (PDA). Part 2
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata PDAs
NPDAs Accept Context-Free Languages
CSE322 The Chomsky Hierarchy
Non-Deterministic Finite Automata
فصل دوم Context-Free Languages
Deterministic PDAs - DPDAs
Pushdown automata a_introduction.htm.
Chapter 2 Context-Free Language - 01
Principles of Computing – UFCFA3-30-1
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
Normal Forms for Context-free Grammars
Presentation transcript:

Formal Languages, Automata and Models of Computation CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2005

Content Context-Free Languages Push-Down Automata, PDA NPDA: Non-Deterministic PDA Formal Definitions for NPDAs NPDAs Accept Context-Free Languages Converting NPDA to Context-Free Grammar

Non-regular languages Context-Free Languages Regular Languages

Context-Free Languages

Context-Free Languages Grammars Pushdown Automata stack automaton (CF grammars are defined as generalized Regular Grammars)

Definition: Context-Free Grammars Variables Terminal symbols Start variables Productions of the form: is string of variables and terminals

Definition: Regular Grammars Variables Terminal symbols Start variables Right or Left Linear Grammars. Productions of the form: or is string of terminals

Pushdown Automata PDAs

Pushdown Automaton - PDA Input String Stack States

A PDA can write symbols on stack and read them later on. The Stack A PDA can write symbols on stack and read them later on. POP reading symbol PUSH writing symbol All access to the stack only on the top! (Stack top is written leftmost in the string, e.g. yxz) A stack is valuable as it can hold an unlimited amount of information. The stack allows pushdown automata to recognize some non-regular languages.

The States Pop old reading Push new Input stack symbol writing symbol

input stack top Replace (An alternative is to start and finish with empty stack)

input Push top stack

input Pop top stack

input No Change top stack

Example 3.7 Salling: Input Time 0 A PDA for simple nested parenthesis strings Time 0 Input Stack

Example 3.7 Time 1 Input Stack

Example 3.7 Time 2 Input Stack

Example 3.7 Time 3 Input Stack

Example 3.7 Time 4 Input Stack

Example 3.7 Time 5 Input Stack

Example 3.7 Time 6 Input Stack

Example 3.7 Time 7 Input Stack

NPDAs Non-deterministic Push-Down Automata

Non-Determinism

A string is accepted if: All the input is consumed The last state is a final state Stack is in the initial condition (either: empty (when we started with empty stack), or: bottom symbol reached, or similar)

Example NPDA is the language accepted by the NPDA:

Example NPDA NPDA (Even-length palindromes)

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 2 Input Stack

Time 3 Input Stack

Time 4 Input Stack

Time 5 Input Stack

Time 6 Input Stack

Time 7 Input Stack accept

Formal Definitions for NPDAs

Transition function:

Transition function: new state current state current stack top new stack top current input symbol An unspecified transition function is to the null set and represents a dead configuration for the NPDA.

Formal Definition Non-Deterministic Pushdown Automaton NPDA Final States Input alphabet Stack Transition function Final states start symbol

Instantaneous Description Current state Current stack contents Remaining input

Instantaneous Description Example Instantaneous Description Input Time 4: Stack

Instantaneous Description Example Instantaneous Description Input Time 5: Stack

We write Time 4 Time 5

A computation

A computation

A computation

A computation

A computation

A computation

A computation

A computation

For convenience we write

Formal Definition Language of NPDA Initial state Final state

Example: NPDA :

NPDA :

Therefore: NPDA :

NPDAs Accept Context-Free Languages

Theorem Context-Free Languages (Grammars) 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:

Converting Context-Free Grammars to NPDAs

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 Start

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 Top-down parser 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

Which means Context-Free Languages (Grammars) Accepted by NPDAs

Converting NPDAs to Context-Free Grammars

For any NPDA we will construct a context-free grammar with

The grammar simulates the machine A derivation in Grammar in NPDA Input processed Stack contents terminals variables

First we modify the NPDA so that It has a single final state Some Simplifications First we modify the NPDA so that It has a single final state It empties the stack when it accepts the input Original NPDA Empty Stack

Second we modify the NPDA transitions. All transitions will have form: which means that each move increases/decreases stack by a single symbol.

Those simplifications do not affect generality of our argument. It can be shown that for any NPDA there exists an equivalent one having above two properties i.e. the equivalent NPDA with a single final state which empties its stack when it accepts the input, and which for each move increases/decreases stack by a single symbol.

Example of a NPDA in an appropriate form

The Grammar Construction In grammar Stack symbol Variables: states Terminals: Input symbols of NPDA

For each transition: we add production:

For each transition: we add production: for all states

Stack bottom symbol Start Variable Start state (Single) Final state

Example Grammar production:

Grammar productions:

Grammar production:

Resulting Grammar

Resulting Grammar, cont.

Resulting Grammar, cont.

Derivation of string

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

We have shown the procedure to convert any NPDA to a context-free grammar with: which means Context-Free Languages (Grammars) Accepted by NPDAs

Therefore Context-Free Languages Languages Accepted by (Grammars) NPDAs END OF PROOF

Example (Sudkamp 8.1.2) Language consisting solely of a’s or an equal number of a´s and b´s.

When scanning an a in state q0 two transitions are possible When scanning an a in state q0 two transitions are possible. A string of the form aibi is accepted by a computation in states q0 and q1.