615 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.

 

Please log in or register to answer this question.

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
2
Ebrahim asked Jan 12
146 views
Q1. For the following grammar N - AB | BA A - a | CAC B - b | CBC C - a | b Find the FIRST and FOLLOW
0 votes
0 votes
0 answers
3
Ebrahim asked Jan 11
86 views
Find the FIRST and FOLLOW of the grammar to check whether it is LL (1) parser or not. N → AB | BA A → a | CAC B → b | CBC C → a | b
0 votes
0 votes
0 answers
4