970 likes | 977 Views
G. Pullaiah College of Engineering and Technology. Formal Languages & Automata Theory Department of Computer Science & Engineering.
E N D
G. Pullaiah College of Engineering and Technology Formal Languages & Automata Theory Department of Computer Science & Engineering
ContentMidterm resultsRegular vs. Non-regular Languages Context-Free LanguagesContext-Free GrammarsDerivation Trees. AmbiguityApplicationsPush-Down Automata, PDA
Midterm 1 Solution http://www.idt.mdh.se/kurser/cd5560/12_11/examination/Duggor/MIDTERM1-20121127-Solution.pdf
A comment on the MIDTERM 1 The Pumping Lemma for Regular Languages Pumping Lemma cannot be used to prove that a language is regular! An example: If something is a square it always has four edges (a property of square) But: having proved that something has four edges does not necessarily mean that the object is a square. http://www2.mat.ua.pt/rosalia/cadeiras/TC/pump.pdf
Time to take the next step: beyond Regular Languages Non-regular languages Context-Free Languages Regular Languages
Context-Free Languages Based on C Busch, RPI, Models of Computation
Context-Free Languages Context-Free Grammars Pushdown Automata
Set of variables Set of terminal symbols Start variable Set of production rules Formal Definition • Grammar
isstring of terminals Repetition: Regular Grammars Grammar Variables Terminal symbols Start variables Right or Left Linear Grammars. Productions of the form: or
is string of variablesand terminals Definition: Context-Free Grammars Grammar Variables Terminal symbols Start variables Productions of the form:
Regular vs. Context-free Grammar A regular grammar is either right or left linear, whereas context free* grammar is any combination of terminals and non-terminals. Hence regular grammars are a subset of context-free grammars. Grammar generating palindromes is not regular: *The name context-free grammar is explained by the property of productions that are independent of the surrounding symbols. There are also context-sensitive grammars where productions depend on the context (symbols that surround variables).
Example 1: A context-free grammar A derivation
A context-free grammar Another derivation
Example 2: A context-free grammar A derivation
A context-free grammar Another derivation
Example 3: A context-free grammar A derivation
A context-free grammar A derivation
is string of variables and terminals Definition: Context-Free Grammars Grammar Variables Terminal symbols Start variables Productions of the form:
Definition: Context-Free Languages • A language is context-free • if and only if there is a grammar with
Derivation Order Leftmost derivation
Rightmost derivation Derivation Order
Derivation Tree yield
Partial Derivation Trees Partial derivation tree
sentential form Partial derivation tree yield
Sometimes, derivation order doesn’t matter Leftmost: Rightmost: The same derivation tree
derivation (* denotes multiplication) leftmost derivation
derivation leftmost derivation
String has two derivation trees The grammar is ambiguous!
The grammar has two leftmostderivations: is ambiguous as the string
Definition A context-free grammar is ambiguous if some string has two or more derivation trees (two or more leftmost/rightmost derivations).