You are on page 1of 4

 OBJECTIVE : To familiarize context free grammars

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.

1. Define free grammar.

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

The production A-> β is applied to the string α A to obtain α β

3. What are the types of derivation?

The derivation may be


 Left most derivation
 Right most derivation
Left most derivation :
If at each step of derivation ,a production is applied to the left most non
terminal then the derivation is said to be left most derivation.

Example :

E -> E+E | E*E|(E) |id


Deriving a string id+id using left most derivation

E=> E+E

=>id+E

=> id+E*E

=> id+id*E

=> id+id*id

Right most derivation:

If at each step of derivation, a production is applied to the right most non


terminal then the derivation is said to be right most derivation.

Example :

E=> E*E

=>E*id

=> E+E*id

4. what is CFL?

The language generated by G is L(G)

L(G) = { w| w is in T* and S => w}

A string is in L(G) if

i) The string consists of only terminals

ii) The string can be derived from S.

5.What is derivation tree?

 Derivation can be displayed as a derivation tree.

 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.

 The derivation tree.

 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

 A tree is a derivation tree for G if

(1) Every vertex has a label, which is a symbol of VUTU { ∈¿¿

(2) The label of the root is S

(3) If a vertex is interior and has label then A must be in V

(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.

6.What is an ambiguous grammar?

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.

7.What is an useless symbol?

A symbol x is useful if there is a derivation


S= > αxβ=> w, for some α, β and w where w is in T* ,Otherwise X is useless.
8.Eliminate the useless symbol, from the following grammar

S-> AB|a A-> a


Solution :
No terminal string is derivable from B. so eliminate B and the production S-> AB.
S-> a A->a
9.What is nullable production? Write the method to eliminate the nullable
production?

For each variable A, whether A=> E,if so it is called as A-nullable. We may


replace each production B-> x1,x2…xn by all productions striking out some
subsets of those Xi ‘s that are nullable. But we do not include B-> ε even if all Xi’s
are nullable.

10.Eliminate the E-production from the following grammar.

S-> as |bA|E A->E


Solution :
We find that ε is in L(G), so we cannot eliminate S-> t and A is nullable. So
the resultant grammar
S-> as|b|E
11.What is unit production?

The productions of the form A-> B is called as unit productions.

12.Eliminate the unit productions from the grammar

S-> A A->B B->C C->a


Solution
By eliminating the unit productions the resultant grammar is
S-> a
13.What is Chomsky normal form?

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

α->is a string of variables.

You might also like