1
Jan Maluszynski - HT 2007 4.1 CS Master – Introduction to the Theory of Computation
Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
http://www.ida.liu.se/~janma
janma @ ida.liu.se
Jan Maluszynski - HT 2007 4.2 CS Master – Introduction to the Theory of Computation
Outline (Sipser 2.1 – 2.3)
- 1. Motivating example
- 2. CFG Definition
- 3. Parse trees, ambiguity
- 4. Push-down automata
- 5. Equivalence CFG – PDA
- 6. Pumping lemma for CFG
Jan Maluszynski - HT 2007 4.3 CS Master – Introduction to the Theory of Computation
Motivating example A → (A) A → ε Gramatical rules used for rewriting: A ⇒ (A) ⇒ () A ⇒ (A) ⇒ ((A)) ⇒ (((A))) ⇒ ((())) L(A) : all terminal strings derivable L(A) is not regular!
Jan Maluszynski - HT 2007 4.4 CS Master – Introduction to the Theory of Computation
Context Free Grammars A CFG : (V, Σ, R, S)
- V a finite set of nonterminals (variables)
- Σ a finite set of terminals, disjoint with V
- R a finite set of rules of the form
X → w where X∈V and w ∈ (V+ Σ)*
- S∈V is a start nonterminal
Jan Maluszynski - HT 2007 4.5 CS Master – Introduction to the Theory of Computation
Context-Free Languages A CFG G: (V, Σ, R, S) L(G) denotes the language of G: the set of all terminal strings derivable in G from V A language is a context-free language iff it is the language of a CFG
Jan Maluszynski - HT 2007 4.6 CS Master – Introduction to the Theory of Computation
Ambiguity E → E+E E → E#E E → (E) E → a