Courtesy Costas Busch - RPI1 Context-Free Languages.

Slides:



Advertisements
Similar presentations
Context-Free Languages
Advertisements

1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
Grammars, constituency and order A grammar describes the legal strings of a language in terms of constituency and order. For example, a grammar for a fragment.
CFGs and PDAs Sipser 2 (pages ). Last time…
CS5371 Theory of Computation
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.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
Courtesy Costas Busch - RPI
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
Costas Busch - RPI1 Context-Free Languages. Costas Busch - RPI2 Regular Languages.
Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Fall 2006Costas Busch - RPI1 The Chomsky Hierarchy.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Fall 2004COMP 3351 Context-Free Languages. Fall 2004COMP 3352 Regular Languages.
Prof. Busch - LSU1 Context-Free Languages. Prof. Busch - LSU2 Regular Languages Context-Free Languages.
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 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Fall 2005Costas Busch - RPI1 Context-Free Languages.
Context-Free Languages Hinrich Schütze CIS, LMU, Slides based on RPI CSCI 2400 Thanks to Costas Busch.
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 5 Mälardalen University 2005.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Context-free Grammars [Section 2.1] - more powerful than regular languages - originally developed by linguists - important for compilation of programming.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2010.
Grammars CPSC 5135.
Context-free Languages
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
CS 3240: Languages and Computation Context-Free Languages.
Context Free Grammars. Context Free Languages (CFL) The pumping lemma showed there are languages that are not regular –There are many classes “larger”
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Context Free Grammars 1. Context Free Languages (CFL) The pumping lemma showed there are languages that are not regular –There are many classes “larger”
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Grammars Hopcroft, Motawi, Ullman, Chap 5. Grammars Describes underlying rules (syntax) of programming languages Compilers (parsers) are based on such.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Context-Free Languages. Regular Languages Context-Free Languages.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Chapter 5 Context-Free Languages Regular language are effective in describing certain simple patterns. But it is not enough to describe programming languages.
Formal Languages, Automata and Models of Computation
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
5. Context-Free Grammars and Languages
Formal Languages, Automata and Models of Computation
Context-Free Languages
Formal Language & Automata Theory
G. Pullaiah College of Engineering and Technology
PDAs Accept Context-Free Languages
NPDAs Accept Context-Free Languages
Pushdown Automata PDAs
NPDAs Accept Context-Free Languages
Properties of Context-Free languages
Context-Free Languages
Chapter 2 Context-Free Language - 01
… NPDAs continued.
The Chomsky Hierarchy Costas Busch - LSU.
Presentation transcript:

Courtesy Costas Busch - RPI1 Context-Free Languages

Courtesy Costas Busch - RPI2 Regular Languages

Courtesy Costas Busch - RPI3 Regular Languages Context-Free Languages

Courtesy Costas Busch - RPI4 Context-Free Languages Pushdown Automata Context-Free Grammars stack automaton

Courtesy Costas Busch - RPI5 Context-Free Grammars

Courtesy Costas Busch - RPI6 Example A context-free grammar : A derivation:

Courtesy Costas Busch - RPI7 A context-free grammar : Another derivation:

Courtesy Costas Busch - RPI8

9 A context-free grammar : A derivation: Example

Courtesy Costas Busch - RPI10 A context-free grammar : Another derivation:

Courtesy Costas Busch - RPI11

Courtesy Costas Busch - RPI12 A context-free grammar : A derivation: Example

Courtesy Costas Busch - RPI13 A context-free grammar : A derivation:

Courtesy Costas Busch - RPI14

Courtesy Costas Busch - RPI15 Definition: Context-Free Grammars Grammar Productions of the form: is string of variables and terminals VariablesTerminal symbols Start variables

Courtesy Costas Busch - RPI16 Notation: Context-Free Grammars Lower case letters near beginning of alphabet (e.g. a, b, c, …) are terminal symbols Upper case letters near beginning of alphabet (e.g. A, B, C, …) are variables Lower case letters near end of alphabet (e.g. w, x, …) are strings of terminals Upper case letters near end of alphabet (e.g. X, Y, …) are either terminals or strings Lower case Greek letters (e.g. α, β, γ, …) are strings of terminals and/or variables

Courtesy Costas Busch - RPI17 Definition: Context-Free Languages A language is context-free if and only if there is a grammar with

Courtesy Costas Busch - RPI18 Recall Language of a Grammar For a grammar with start variable : String of terminals

Courtesy Costas Busch - RPI19 Derivation Order Leftmost derivation: Rightmost derivation:

Courtesy Costas Busch - RPI20 Leftmost derivation: Rightmost derivation:

Courtesy Costas Busch - RPI21 Derivation Trees

Courtesy Costas Busch - RPI22

Courtesy Costas Busch - RPI23

Courtesy Costas Busch - RPI24

Courtesy Costas Busch - RPI25

Courtesy Costas Busch - RPI26 Derivation Tree

Courtesy Costas Busch - RPI27 yield Derivation Tree

Courtesy Costas Busch - RPI28 Partial Derivation Trees Partial derivation tree

Courtesy Costas Busch - RPI29 Partial derivation tree

Courtesy Costas Busch - RPI30 Partial derivation tree sentential form yield

Courtesy Costas Busch - RPI31 Same derivation tree Sometimes, derivation order doesn’t matter Leftmost: Rightmost:

Courtesy Costas Busch - RPI32 Ambiguity

Courtesy Costas Busch - RPI33 leftmost derivation

Courtesy Costas Busch - RPI34 leftmost derivation

Courtesy Costas Busch - RPI35 Two derivation trees

Courtesy Costas Busch - RPI36 The grammar is ambiguous: stringhas two derivation trees

Courtesy Costas Busch - RPI37 stringhas two leftmost derivations The grammar is ambiguous:

Courtesy Costas Busch - RPI38 Definition: A context-free grammar is ambiguous if some string has: two or more derivation trees

Courtesy Costas Busch - RPI39 In other words: A context-free grammar is ambiguous if some string has: two or more leftmost derivations (or rightmost)

Courtesy Costas Busch - RPI40 Why do we care about ambiguity? take

Courtesy Costas Busch - RPI41

Courtesy Costas Busch - RPI42

Courtesy Costas Busch - RPI43 Correct result:

Courtesy Costas Busch - RPI44 We want to remove ambiguity Ambiguity is bad for programming languages

Courtesy Costas Busch - RPI45 We fix the ambiguous grammar: New non-ambiguous grammar:

Courtesy Costas Busch - RPI46

Courtesy Costas Busch - RPI47 Unique derivation tree

Courtesy Costas Busch - RPI48 The grammar : is non-ambiguous: Every string has a unique derivation tree

Courtesy Costas Busch - RPI49 Inherent Ambiguity Some context free languages have only ambiguous grammars Example:

Courtesy Costas Busch - RPI50 The string has two derivation trees