1

I come with a question while doing one of the exercises for my parsing course in the university. The question specifically goes to constructing a parsing table using canonical LR items.

The given grammar production rules go as follow:

S -> NP VP  
NP -> NP PP  
NP -> a n  
VP -> v  
VP -> VP NP  
VP -> VP PP  
PP -> p NP  

Now the problem is, when I try to construct the table by figuring out the states, I end up with this problem:

at I_0  
S'-> .S   
S->.NP VP      
NP->.NP PP/.a n    

In this above case, I have to perform go-to action on both S->.NP VP and NP->.NP PP. This would indicate that when I create the parsing table, I would have two states in which NP could bring the parsing to. Am I missing something here?

Please do note that while I can see this question not being a problem with a lookahead, this question was specifically for LR(0) exercise.

rici
  • 234,347
  • 28
  • 237
  • 341
sunny11
  • 31
  • 1
  • 5
  • The goto state has both items in it (as well as their closures). The fact that a state represents a set of items is a(or the) essential point in LR parsing – rici Feb 07 '17 at 18:09
  • so what you are saying is that I should create one state that takes both S->.NP VP and NP->.NP PP right? If this is the case, I'm surprised none of the texts I've read so far covered this up. Thank you! – sunny11 Feb 07 '17 at 18:19
  • Not quite. The combined state has both `S->NP • VP` and `NP -> NP • PP` (plus their closures) and is the destination of the goto action. I'd be very surprised if you had a textbook which doesn't mention this. – rici Feb 07 '17 at 23:31
  • 1
    By the way, you might find http://jsmachines.sourceforge.net/machines/slr.html useful. I just pasted your grammar from the question, and it seemed to produce the right machine. – rici Feb 08 '17 at 01:38
  • Thank you, it is indeed very helpful. Unfortunately, from the sources I've learned from, I've not had any examples where there existed combined states during LR(0). I've only encountered those going to CLR(1) and LALR parsing, so I was unsure if the merging of the states was even legal (I guess it was implied). But your explanation confirmed it, so thanks! – sunny11 Feb 08 '17 at 13:23

0 Answers0