Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
LR parser
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Conflicts in the constructed tables === The automaton is constructed in such a way that it is guaranteed to be deterministic. However, when reduce actions are added to the action table it can happen that the same cell is filled with a reduce action and a shift action (a ''shift-reduce conflict'') or with two different reduce actions (a ''reduce-reduce conflict''). However, it can be shown that when this happens the grammar is not an LR(0) grammar. A classic real-world example of a shift-reduce conflict is the [[dangling else]] problem. A small example of a non-LR(0) grammar with a shift-reduce conflict is: : (1) E β 1 E : (2) E β 1 One of the item sets found is: : '''Item set 1''' : E β 1 <big>{{color|#f7f|β’}}</big> E : E β 1 <big>{{color|#f7f|β’}}</big> : '''+''' E β <big>{{color|#f7f|β’}}</big> 1 E : '''+''' E β <big>{{color|#f7f|β’}}</big> 1 There is a shift-reduce conflict in this item set: when constructing the action table according to the rules above, the cell for [item set 1, terminal '1'] contains '''s1''' (shift to state 1) '''and r2''' (reduce with grammar rule 2). A small example of a non-LR(0) grammar with a reduce-reduce conflict is: : (1) E β A 1 : (2) E β B 2 : (3) A β 1 : (4) B β 1 In this case the following item set is obtained: : '''Item set 1''' : A β 1 <big>{{color|#f7f|β’}}</big> : B β 1 <big>{{color|#f7f|β’}}</big> There is a reduce-reduce conflict in this item set because in the cells in the action table for this item set there will be both a reduce action for rule 3 and one for rule 4. Both examples above can be solved by letting the parser use the follow set (see [[LL parser]]) of a nonterminal ''A'' to decide if it is going to use one of ''A''s rules for a reduction; it will only use the rule ''A'' β ''w'' for a reduction if the next symbol on the input stream is in the follow set of ''A''. This solution results in so-called [[Simple LR parser]]s.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)