views:

88

answers:

1

I'm using Kenneth Louden's Compiler Construction book but it lacks examples and the rules stating how this goes are really hard to follow. I'm not sure how to go to the LR(1) states. also, not sure how to go from the LR(1) states to the LALR(1) ones.

For example, these LR(1) states:

alt text

i understand how the "S -> .XX, $" got there, but then take a look at "X -> .aX, a/b". Why is $ not a part of it? Wasn't it generated from a rule that had $, so doesn't it have to have a $? And how did the a/b appear? According to the book, if A -> alpha.Bgama,a and B is a non-terminal, then B -> .beta, b is added for every B -> beta where b is in first(gamaalpha). So, from what I understood:

S -> .XX, $ and X -> aX and X -> b => X -> aX, $ and X -> b, $
X -> .aX, $ and X -> b, $ => nothing happens
A -> .a, $ => nothing happens

But that seems completely wrong, given the above example.

+1  A: 

I understand how the "S -> .XX, $" got there, but then take a look at "X -> .aX, a/b". Why is $ not a part of it?

Are you referring to the 2nd and 3rd items in the item set I0 ?

The $ signifies that the input symbol is the empty string. The a/b that the input symbol is either an a/b.

Your terminal set is { a, b, $ }, non terminal set is { S' , S , X }

It is important to note that LR(n),SLR,LALR(1) are all bottom-up parsers. They start from the terminals and work their way up to the start symbol S'.

Sean A.O. Harney
well, yes, i realize the difference between terminal and non-terminal symbols. but i'm wondering how the a/b have gotten there because the derivation rules are obscure and from what i understood, they were not supposed to be there
they changed my name