in Compiler Design
628 views
0 votes
0 votes

Q1: Consider G :-

$X \rightarrow X + Y | Y$

$Y \rightarrow Y*Z|Z$

$Z \rightarrow (X)$

$Z \rightarrow id$

if LR(1) parser is used to parse the above grammar, then total how many lookahead will be present in the dfa state I0 for the items $X \rightarrow .Y \text{ and } Z \rightarrow .id$.

My Answer:- 5

For, $X \rightarrow .Y $ lookahead will be $ \text{\$,+ }$

And for $Z \rightarrow .id$ lookahead will be $\text{\$,+, * }$ 

---------------------------------------------------------------------------------------------------------------------------------

Q2: 

i = 10
j = 1
a = i*j
b = i+j
if b<=a goto 7
a = a + 1
i = i-1 goto 3

Calculate the no of nodes and edges in the above code for Basic Block construction process.

My Answer:- Nodes : 6 and Edges : 7.

---------------------------------------------------------------------------------------------------------------------------------

Q3: A grammar that has not any epsilon productions and also free from unit productions. The maximum number of reduce moves that can be taken during bottom-up evaluation of 25 token string by bottom-up parsers is__________.

My Answer: 24.

---------------------------------------------------------------------------------------------------------------------------------

Q4: Consider the following two sets of LR(1) items of LR(1) grammar.

Set 1:

$A \rightarrow d., c \\ B \rightarrow d., b \\ X \rightarrow .fx, g \\ Y \rightarrow .g, a$

Set 2:

$A \rightarrow d., b|f  \\ B \rightarrow d., d| \$  \\ X \rightarrow .fx, \$   \\ Y \rightarrow .g, \$ $

Which of the following statement related to merging of the two sets in the corresponding parser is true?

1. Can be merged byt will results in S-R Conflicts.

2. Can be merged but will result in R-R conflicts.

3. Can bot be merged since goto of f is leading to SR conflict with $A \rightarrow d., $

4. Can not be merged since look ahead are different.

My Answer is 1 and 2 only, but the answer given that 3 is also true along with 1 and 2.

---------------------------------------------------------------------------------------------------------------------------------

Someone verify all these answers.

 

in Compiler Design
628 views

4 Comments

QUES 1:- YUP, 5 IS CORRECT

QUES 2: THATS CORRECT 13 ,IF YOU CONSIDER ENTRY AND EXIT BLOCK OTHERWISE 9

(i wrote 9 , i thought unless and until asked we donot consider entry and exit node, and hence i got 4 nodes, 5 edges)

QUES 3: YES ,24

link for similar problem:https://gateoverflow.in/1418/gate2013-9

QUES 4:YES, ONLY 1,2 ARE CORRECT!!( we cant have goto on terminal)

 

 

1
1
edited by

Shubhanshu

reference to ques 2;

if not mentioned in the question, that do we have to consider entry and exit block??

do we take it by default!

like when i solved this ques , i didn't take it!!

is it compulsory to take if not given in ques??

0
0
Same doubt.
0
0

Please log in or register to answer this question.

Related questions