Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is this grammar LR(1) but not SLR(1)?

I have the following grammar, which I'm told is LR(1) but not SLR(1):

S ::= a A | b A c | d c | b d a

A ::= d

I don't understand why this is. How would you prove this?

like image 936
Konstantinos Georgiadis Avatar asked May 08 '12 20:05

Konstantinos Georgiadis


People also ask

What is the difference between LR 1 and SLR 1?

LR(1) grammars Every SLR(1) grammar is a canonical LR(1) grammar, but the canonical LR(1) parser may have more states than the SLR(1) parser. An LR(1) grammar is not necessarily SLR(1), the grammar given earlier is an example.

How do you prove grammar is not a SLR?

To show the given grammar to be not SLR, we only need to examine the following two LR(0) states. S2: S → L . = R • R → L .

How do you check grammar is SLR 1 or not?

If you can construct a parsing table and there are no conflicts, it's SLR(1).

How do you show grammar is LR 1 but not LALR 1?

Therefore, given grammar is LR (1). For LALR (1), we combine state 2 and state 3. Here, RR conflict arises. Therefore, given grammar is not LALR (1).


1 Answers

I don't have enough reputation to comment on the above answer, and I'm a bit late to this question, but...

I've seen this grammar as an example elsewhere and the OP actually made a typo. It should be:

S ::= A a | b A c | d c | b d a

A ::= d

i.e., the very first clause of S is 'A a', not 'a A'.

In this case the FOLLOWS set for A is { $, a, c} and there is an SLR conflict in state 8.

like image 116
Toby Hutton Avatar answered Oct 08 '22 20:10

Toby Hutton