0

I ask a question some days ago SLR(1) and LALR(1) and Reduce, i do lot's of search and contact to some professor, but i couldn't summarize that the solution of 2nd problem is right or false. we have 2 question on entrance exam in 2 different year.

Two question is multiple choice. in 2010 question we have:

1) we have a SLR(1) Grammar G as following. we use SLR(1) parser generator and generate a parse table S for G. we use LALR(1) parser generator and generate a parse table L for G.

S->AB
A->dAa
A-> lambda (lambda is a string with length=0)
B->aAb

And the question designer select the solution as:

Solution: the number of elements with R (reduce) in S is more than L.

after two years the question designer ask:

2) Suppose T1, T2 is created with SLR(1) and LALR(1) for arbitrary Grammar G. if G be a SLR(1) Grammar which of the following is TRUE?

a) T1 and T2 has not any difference.

b) total Number of non-error entries in T1 is lower than T2

c) total Number of error entries in T1 is lower than T2

Solution:

(a) is selected by the question designer. 

My question is:

any one could describe for me why the solution of 1st question is contradict to 2nd question? 

someone answered in previous post that two solution is right, but not describe it very well-formed.

anyway i waiting for one expert that get me out of confusing !!!

Community
  • 1
  • 1

1 Answers1

1

Answer to Q1:

First of all you need to create DFA for SLR(1) and LALR(1) parsers. I created DFA for both of them.

SLR(1) and LALR(1) DFAs

For SLR(1) I got 10 states and 10 reduce entries whereas for LALR(1) I created DFA for CLR(1) with 13 states which got minimized to 10 states with 7 reduce entries. Thats answers your first question.


Answer to Q2:

G is SLR(1) grammar, then surely there are no conflicts (or error) S-R or R-R in the SLR(1) table. LALR(1) has more power than SLR(1),therefore there is also no conflict in LALR(1) table for given grammar G. Lets see option by option

(c) : there no error in T1 and T2 (wrong option)

(b) : Non-error entries means shift entries and reduce entries. It should be clearly noted that in bottom up parsers from parser to parser only rules for reduce entries changes while for that of shift entries remain same. For e.g in LR(0) reduce entries are made in each column, for SLR(1) it is done in FOLLOW of left hand side variable, while in CLR(1) and LALR(1) reduce entries are made in lookahead symbols. Thus reduce entries changes from parser to parser but shift entries are same.

We have also already proved in Q1 where reduce entries of SLR(1) parsing table are more than that of LALR(1). Therefore proving (b) option to be incorrect.

(a) T1 and T2 may come out to be same but not always. And other important thing is that multiple choice questions sometimes wants you to choose most appropriate option. Thus for me (a) is the answer

obmjo
  • 135
  • 10