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.)
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?
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
Theory Explanation. |
Question 4 |
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?
The language generated by G is (a + b)* | |
The language generated by G is a*(a + b)b* | |
The language generated by G is a*b*(a + b) | |
The language generated by G is not a regular language |
Question 5 |
(K – 1) |P| + |T| - 1 | |
(K – 1) |P| +| T| | |
K |P| + |T| - 1 | |
K |P| + |T| |
Question 6 |
AVL trees | |
Binary search trees | |
Binary trees | |
None of the above |
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 |
push-down automata | |
2-way linear bounded automata
| |
both (A) and (B) | |
none of these |
Question 8 |
logK|W| ≤ h ≤ logK((|W|-1) / k-1) | |
logK|W| ≤ h ≤ logK(K|W|) | |
logK|W| ≤ h ≤ K logK|W| | |
logK|W| ≤ h ≤ ((|W|-1) / k-1) |
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))