Context-free-grammar

Question 1

Let G be a context-free grammar where G = ({S, A, B, C},{a,b,d},P,S) with the productions in P given below.

   S → ABAC
   A → aA ∣ ε
   B → bB ∣ ε
   C → d  

(ε denotes null string). Transform the grammar G to an equivalent context-free grammar G' that has no ε productions and no unit productions. (A unit production is of the form x → y, and x and y are non terminals.)

A
Theory Explanation.
Question 2

(a) Let G1 = (N, T, P, S1) be a CFG where,
N = {S1, A, B}, T = {a,b} and
P is given by

         S1 → aS1b             S1 → aBb
         S1 → aAb              B → Bb
         A → aA                B → b
         A → a 

What is L(G1)?

(b) Use the grammar in part(a) to give a CFG
for L2 = {ai bj ak bl | i, j, k, l ≥ 1, i=j or k=l} by adding not more than 5 production rule.

(c) Is L2 inherently ambiguous?

A
Theory Explanation.
Question 3

A simple Pascal like language has only three statements.
(i) assignment statement e.g. x:=expression
(ii) loop construct e.g. for i:=expression to expression do statement.
(iii) sequencing e.g. begin statement ;…; statement end

(a) Write a context-free grammar (CFG) for statements in the above language. Assume that expression has already been defined. Do not use optional parentheses and * operator in CFG.
(b) Show the parse tree for the following statement:

     for j:=2 to 10 do
         begin x:=expr1;
               y:=expr2
         end  
A
Theory Explanation.
Question 4
Consider the context-free grammar G below
S → aSb | X
X → aX | Xb | a | b ,
where S and X are non-terminals, and a and b are terminal symbols. The starting non-terminal is S. Which one of the following statements is CORRECT?
A
The language generated by G is (a + b)*
B
The language generated by G is a*(a + b)b*
C
The language generated by G is a*b*(a + b)
D
The language generated by G is not a regular language
Question 5
Let G = (V, T, S, P) be any context-free grammar without any λ-productions or unit productions. Let K be the maximum number of symbols on the right of any production P. The maximum number of production rules for any equivalent grammar in Chomsky normal form is given by:
A
(K – 1) |P| + |T| - 1
B
(K – 1) |P| +| T|
C
K |P| + |T| - 1
D
K |P| + |T|
Question 5 Explanation: 
Let G = (V, T, S, P) be any context-free grammar without any λ-productions or unit productions. Let K be the maximum number of symbols on the right of any production P. The maximum number of production rules for any equivalent grammar in Chomsky normal form is given by (K – 1) |P| + |T|
Question 6
One of the uses of CNF is to turn parse tree into :
A
AVL trees
B
Binary search trees
C
Binary trees
D
None of the above
Question 6 Explanation: 
One of the uses of CNF is to turn parse trees into binary trees. – These trees have some convenient properties, one of which we exploit here.
Theorem 7.17: Suppose we have a parse tree according to a Chomsky- Normal-Form grammar G = (V, T, P, S), and suppose that the yield of the tree is a terminal string w.
Question 7
CFG can be recognized by a
A
push-down automata
B
2-way linear bounded automata
C
both (A) and (B)
D
none of these
Question 7 Explanation: 
CFG can be recognized by push-down automata. Moreover every CFG is a CSG and every CSG can be recognized by linear bounded automata. Hence every CFG can be recognized by linear bounded automata.
Question 8
Let G = (V, T, S, P) be a context-free grammar such that every one of its productions is of the form A → v, with |v| = K > 1. The derivation tree for any W ∈ L(G) has a height h such that
A
logK|W| ≤ h ≤ logK((|W|-1) / k-1)
B
logK|W| ≤ h ≤ logK(K|W|)
C
logK|W| ≤ h ≤ K logK|W|
D
logK|W| ≤ h ≤ ((|W|-1) / k-1)
Question 8 Explanation: 
Min height of any tree is log_k |W|
For max height (since k>1, consider k=2) , hence it is CNF form and in CNF height is log_2 (|W|+1)
so in general it should be log_k ((|w|-1) / (k-1))
There are 8 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access