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.