0% found this document useful (0 votes)
53 views3 pages

CD Q5 PDF

The document discusses compiler design concepts including: - Follow sets for nonterminals S and B in a sample grammar are calculated. - False statements about LR parsing and grammars are identified. - A sample SDT rule violating the L-attributed definition is identified. - A translation scheme for an expression is evaluated to determine the print order. - The number of registers needed apart from the accumulator for an expression is calculated. - Properties of two sample grammars regarding LR parsing are evaluated. - The number of backtracks needed to generate a string from a sample grammar is calculated.

Uploaded by

bhavesh agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

CD Q5 PDF

The document discusses compiler design concepts including: - Follow sets for nonterminals S and B in a sample grammar are calculated. - False statements about LR parsing and grammars are identified. - A sample SDT rule violating the L-attributed definition is identified. - A translation scheme for an expression is evaluated to determine the print order. - The number of registers needed apart from the accumulator for an expression is calculated. - Properties of two sample grammars regarding LR parsing are evaluated. - The number of backtracks needed to generate a string from a sample grammar is calculated.

Uploaded by

bhavesh agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COMPILER DESIGN

S → aSAb | bSBc
A → +AB | ε
B → *BC | ε
C → aC | d

1. What is in the Follow(S)?

(a) {a, b, c, +, $} (b) {a, c, +, *, $}


(c) {b, c, +, *, $} (d) {a, b, d, *, $}

2. What is in the Follow(B)?

(a) {a, b, c, d, *} (b) {a, b, d, ε, $}


(c) {a, c, d, *, $} (d) {c, d, b, +, *}

3. Choose the False statement.

(a) No left recursive/ ambiguous grammar can be LL(1)


(b) The class of grammars that can be parsed using LR methods is proper subset of the class of
grammar that can be parsed by LL method
(c) LR parsing is non-backtracking method
(d) LR parsing can describe more languages than LL parsing

4. Consider the following SDT.

A → BC *(I) B.i = f(A.i)


(II) B.i = f(A.S)
(III) A.S = f(B.s)

Which of the above is violating L – attributed definition?

(a) I only (b) II only


(c) I, II (d) I, II, III

1
5.

X → YZ

Y → Y + Z {print (‘+’);}
T {Y.val = T.val}

Z → *Y {print (‘*’);} Z
T {Z.val = T.val}
ε

T → num {print(num.val);}

For 2+3*2, the above translation scheme prints

(a) 2+3*2 (b) 23+2*


(c) 232*+ (d) 23*2+

6. Consider the following expression


x = a*b – c*d+e

For generating target code how many register will be required apart from accumulator A?

(a) 1 (b) 2
(c) 3 (d) 5

7. Consider the following two grammars

G1: A → A1 | 0A1 | 01
G2: A → 0A | 1

Which of the following is True regarding above grammars?

(a) L1 is LR(k) (b) L2 is LR(k)


(c) Both L1 and L2 is LR(k) (d) None is LR(k)

8. Consider the following grammar.

S → aB | aAb
A → bAb | a
B → aB | ε

2
How many back tracks are required to generate the string aab from the above grammar?

(a) 1 (b) 2
(c) 3 (d) 4

You might also like