Lecture 9 - Context-Free Languages & Context-Free Grammars Flashcards
Context-Free/Regular Grammars, Context-Free/Regular Languages
Finite Automata are:
Formal language recognizers - they are devices that accept valid strings
Context-free Grammars are:
A certain type of formal language generators - they are devices that produce valid strings
A Context-Free Grammar is a
Quadruple
G = (V, Σ, R, S)
V is an alphabet
Σ ⊆ V is a set of terminals
V − Σ is the set of nonterminals
R is a finite set of rules R ⊆ (V − Σ) × V∗
S ∈ V − Σ is the start symbol
Terminal vs Nonterminal
- Alphabet the words of the language are made from and we
denote its elements, by small letters or symbol σVS
- Symbols of capital letters
A language L is a context-free language iff.
There is
a context-free grammar G such that
L = L(G)
Definition of the language L(G) generated by G
L(G) = {w ∈ Σ∗ :
S∗⇒G w}
where ⇒∗G
is a transitive, reflexive closure of ⇒G
What is fact 1?
The language L = {a^nb^n : n ≥ 0} is context-free
What is fact 2?
RL != CFL
What is the theorem?
The class of all regular languages is a proper subset of the class of all context-free languages, i.e.
RL ⊂ CFL
A context-free grammar is called regular, or right-linear iff.
R ⊆ (V − Σ) × Σ∗ ((V − Σ) ∪ {e})
A regular (right-linear) grammar is a context-free grammar such that the right-hand side of every rule
contains at most one nonterminal, which if present, must be
the last symbol in the string. The rules must have a form
A → wB, A → w for any A, B ∈ V − Σ,
w ∈ Σ∗
L-G Theorem
Establishes
the relationship between the Regular Languages
and Regular Grammars; Language L is regular iff. there exists a regular grammar G such that
L = L(G)
R-CF Theorem
By definition, any regular grammar is context free and
hence generates a context-free language; The class RL of all regular languages is a proper subset
of the class CFL of all context-free languages, i.e.
RL ⊂ CFL