You are on page 1of 6

CHAPTER 4 CFG

1. What is the language generated by following grammar? ( 1 Mark)


S  0S1 | 0A1
A  0A1 | 01
Answer 
S  0S1
 00A11
 000A111
 00001111  * 0n 1n  L(G) but
G
Here if n = 0, or 1, no string is getting derived from the grammar.
The only possible values of n are n  2.
 L(G) = {0n 1n | n  2}.

Scheme of marking : correct definition of language : 1 mark

2. Mention various methods of grammar simplification. ( 1 Mark)


Answer 
Grammar simplification methods :
a. Elimination of -productions.
b. Elimination of nullable symbols
c. Elimination of Unit productions.
d. Elimination of useless symbols.

Scheme of marking : One correct type : 1/4 mark

3. Define Nullable Symbol.

4. Define the following suitable examples ( 1 Mark each)


a. Leftmost derivation.
b. Rightmost derivation.
c. Ambiguous grammar.
Answer 
a. Leftmost derivation
In a derivation process, if the leftmost non-terminal in sentential form is replaced by
R.H.S. of its rule and then the derivation is obtained, it is called as leftmost
derivation.

b. Rightmost derivation
In a derivation process, if the rightmost non-terminal in sentential form is replaced by
R.H.S. of its rule and then the derivation is obtained, it is called as rightmost
derivation.

c. Ambiguous grammar
A CFG is ambiguous if for at least one word in the language that it generates there are
two possible derivations of the word that correspond to different syntax trees.

1. Rewrite the grammar after removing useless symbol. ( 5 Marks)

S  AB | CA, B  BC | AB, A  a, C  aB | b, D  SS | d
Answer 

a. Non-terminal B does not derive any terminal string  B is useless.


Drop productions having ‘B’ symbol.
S  CA
Aa
Cb
D  SS | d
b. Non-terminal D is not derivable from start symbol.  D is useless.
Drop D production.
S  CA
Aa
Cb
This is the final production set

Scheme of marking :
Identification of useless symbols : 2 mark
Elimination of useless symbols : 2Marks
Grammar formation : 1 mark

2. Rewrite the following grammar after removing -production. ( 5 Marks)


S  aS | AB, A  a | , B b | , Db
Answer 

To find nullable symbols


as A   and B    A and B are nullable
S  AB   *  S is nullable
To delete A  , B  , we add new productions to the grammar as

Old Productions with nullables Productions newly formed by rule


S  aS Sa (deleting S)
SA (deleting B)
S  AB
SB (deleting A)
Aa Nothing
Ab Nothing
Db Nothing
 Final set of productions = S  aS | AB | A | B | a
Aa
Bb
Db

Scheme of marking : Defining nullable symbols : 2 mark


Deleting nullable symbols and forming new productions : 3
Marks

3. Rewrite the following grammar after removing -production. ( 5 Marks)


S  XaX | bX, X  XxX | AbX | 
Answer 
As X    X is nullable symbol.
Deleting X   from productions, adds new productions as\

Old Productions with nullables Productions newly formed by rule


Sa (deleting both X)
S  XaX S  Xa (deleting 2nd X)
S  aX (deleting 1st X)
S  bX Sb (deleting X)
Sa (deleting both X)
X  XaX S  Xa (deleting 2nd X)
S  aX (deleting 1st X)
Xb (deleting both X)
X  XbX X  bX (deleting 1st X)
X  Xb (deleting 2nd X)
 Final set of productions is
S  XaX | Xa | aX | a | bX | b
X  XaX | a | Xa | aX | b | bX | Xb.

Scheme of marking : Defining nullable symbols : 2 mark


Deleting nullable symbols and forming new productions : 3
Marks
5:
6:
7:

You might also like