Professional Documents
Culture Documents
UNIT II GRAMMARS 9
Introduction - Types of Grammar - Context Free Grammars and Languages - Derivations -
Parse Trees - Equivalence of Derivations and Parse Trees - Ambiguity - Normalization of
CFG - Elimination of Useless symbols - Unit productions - productions - Chomsky
normal form - Greibach Normal form.
Grammar G is defines as
G= (V,T,P,S) Where
V = Set of variables or not terminals
T = Set of Terminals
P= set of productions of the form A -> α.
Where A -> is a variable
α-> string of terminals and non terminals
S = a special variable, called start symbol.
2. What is derivation?
If A-> β is a production and α and are any strings than the derivation is
Example :
E=> E+E
=>id+E
=> id+E*E
=> id+id*E
=> id+id*id
Example :
E=> E*E
=>E*id
=> E+E*id
4. what is CFL?
A string is in L(G) if
The vertices of a derivation tree and labeled with terminal or variable symbols
of the grammer or ∈
If an interior vertex is labeled A, and the sons of A are labeled x 1, x2, ….xk
from the left then A → x1 x2 … xk must be a production.
If we lead the leaves from left to light, we get the string (id + id) * id.
More formally Let G (V, T, P, S) be a CFG
(4) If vertex has label A and sons vertex A are labeled from left
as x1, x2 … xk then A → x 1 , x 2 ...x k must be a production
in p.
(5) If a vertex has a label ∈ , then it leaf and is the only son of
its father.
A context free grammar is said to be ambiguous if any word has more than
one parse tree or more than one left most derivation or more than one right most
derivation is said to be an ambiguous grammar.
A->BC A->a
Where A,B,C are variables , a is a terminal
14.What is Greibach normal form(GNF)?
GNF:
In GNF, every production is of the form
A-> aα
Where a-> is a terminal