0
4

1 に答える 1

1

(After reading that Wikipedia page more carefully.)

The Wikipeda quote is (emphasis added):

If an item set i contains an item of the form A → w • and A → w is rule m with m > 0 then the row for state i in the action table is completely filled with the reduce action rm.

Rule 0 is the augmented start rule, which in your case should be:

start : mexp '$'

(Personally, I prefer adding the EOF token explicitly; there are fewer exceptions that way.)

However, what you've got, I think, is:

start : exp '$'
exp   : mexp

which actually isn't LR(0), because the unit reduction rule ( exp → mexp ) leads to the shift-reduce conflict you discovered.

The Wikipedia article's exception for m = 0 would be unnecessary if the rule were written with an explicit end-marker; in this case, the action acc is generated according to modified action 3:

  1. An extra column for '$' (end of input) is added to the action table that contains acc for every item set that contains S → E • '$'.

(Actually, you don't need the "extra column" part; with an explicit end-marker you should already have a column for it. The point is to override the shift action with an acc action.)

于 2012-10-17T23:18:51.913 に答える