Click to See Complete Forum and Search --> : LR1 Parser Generation


lhayes00
March 7th, 2008, 05:37 PM
Hi,

I am currently studying LR1 parser construction and have a question regarding shift-reduce conflicts.

Shift-reduce conflicts can be resolved using precedence directives. A conflict can be resolved by comparing the precedence of the symbol (which would be shifted) with that of the rule (which would be reduced). My books say that the precedence of the rule is determined by the rightmost terminal symbol. However I cannot work out what should happen in situations like the following:

* represents active position within item

When a shift-reduce conflict occurs with items like:
Item 1: non_terminal_a --> non_terminal_b * terminal_a lookahead: +
Item 2: non_terminal_q --> * lookahead: anything

Item 2 does not have a right-most terminal, so should it be given precedence by its lookahead symbol? Or by default should a rule have the lowest/highest possible precedence?


Another similar situation:

Item 1: non_terminal_a --> non_terminal_b * terminal_a lookahead: +
Item 2: non_terminal_q --> * non_terminal_f lookahead: anything


Any help would be brilliant! :)

Lea Hayes