Normal Forms for Context-free Grammars

Slides:



Advertisements
Similar presentations
Simplifications of Context-Free Grammars
Advertisements

Fall 2006Costas Buch - RPI1 Simplifications of Context-Free Grammars.
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.
Fall 2004COMP 3351 Simplifications of Context-Free Grammars.
Prof. Busch - LSU1 Simplifications of Context-Free Grammars.
Introduction to Computability Theory
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.
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Courtesy Costas Buch - RPI1 Simplifications of Context-Free Grammars.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Costas Buch - RPI1 Simplifications of Context-Free Grammars.
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 Simplifications of Context-Free Grammars. 2 A Substitution Rule substitute B equivalent grammar.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
1 Simplifications of Context-Free Grammars. 2 A Substitution Rule Substitute Equivalent grammar.
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:
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.
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.
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.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Formal Languages, Automata and Models of Computation
G. Pullaiah College of Engineering and Technology
PDAs Accept Context-Free Languages
Linear Bounded Automata LBAs
NPDAs Accept Context-Free Languages
Simplifications of Context-Free Grammars
Simplifications of Context-Free Grammars
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Theory of Computation Lecture #27-28.
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata PDAs
NPDAs Accept Context-Free Languages
Principles of Computing – UFCFA3-30-1
CSE322 The Chomsky Hierarchy
Pushdown automata and CFG ↔ PDA conversions
Deterministic PDAs - DPDAs
Parsing Costas Busch - LSU.
Closure Properties of Context-Free languages
Chapter 2 Context-Free Language - 01
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
The Chomsky Hierarchy Costas Busch - LSU.
Context-Free Languages
Presentation transcript:

Normal Forms for Context-free Grammars

Chomsky Normal Form All productions have form: and variable variable terminal

Examples: Chomsky Normal Form Not Chomsky Normal Form

Convertion to Chomsky Normal Form Example: Not Chomsky Normal Form

Introduce variables for terminals:

Introduce intermediate variable:

Introduce intermediate variable:

Final grammar in Chomsky Normal Form: Initial grammar

In general: From any context-free grammar not in Chomsky Normal Form we can obtain: An equivalent grammar in Chomsky Normal Form

The Procedure First remove: Nullable variables Unit productions

For every symbol : Add production In productions: replace with New variable:

Replace any production with New intermediate variables:

Theorem: For any context-free grammar there is an equivalent grammar in Chomsky Normal Form

Observations Chomsky normal forms are good for parsing and proving theorems It is very easy to find the Chomsky normal form of any context-free grammar

Greinbach Normal Form All productions have form: symbol variables

Examples: Greinbach Normal Form Not Greinbach Normal Form

Conversion to Greinbach Normal Form:

Theorem: For any context-free grammar there is an equivalent grammar in Greinbach Normal Form

Observations Greinbach normal forms are very good for parsing It is hard to find the Greinbach normal form of any context-free grammar

An Application of Chomsky Normal Forms

The CYK Membership Algorithm Input: Grammar in Chomsky Normal Form String Output: find if

The Algorithm Input example: Grammar : String :

Therefore: Time Complexity: Observation: The CYK algorithm can be easily converted to a parser

Pushdown Automata PDAs

Pushdown Automaton -- PDA Input String Stack States

Initial Stack Symbol Stack Stack bottom special symbol

The States Pop symbol Input symbol Push symbol

input stack top Replace

input stack top Push

input stack top Pop

input stack top No Change

Non-Determinism

NPDA: Non-Deterministic PDA Example:

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

Time 8 Input Stack accept

A string is accepted if: All the input is consumed The last state is a final state We do not care about the stack contents

The input string is accepted by the NPDA:

In general, is the language accepted by the NPDA:

Another NPDA example NPDA

Execution Example: Time 0 Input Stack

Time 1 Input Stack

Time 2 Input Stack

Time 3 Input Stack

Time 4 Input Stack

Time 5 Input Stack

Time 6 Input Stack accept