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!
=== LR states === State 2 in the example parse table is for the partially parsed rule :: r1: Sums β Sums + <big>{{color|#f7f|β’}}</big> Products This shows how the parser got here, by seeing Sums then '''+''' while looking for a larger Sums. The <big>{{color|#f7f|β’}}</big> marker has advanced beyond the beginning of the rule. It also shows how the parser expects to eventually complete the rule, by next finding a complete Products. But more details are needed on how to parse all the parts of that Products. The partially parsed rules for a state are called its "core LR(0) items". The parser generator adds additional rules or items for all the possible next steps in building up the expected Products: :: r3: Products β <big>{{color|#f7f|β’}}</big> Products * Value :: r4: Products β <big>{{color|#f7f|β’}}</big> Value :: r5: Value β <big>{{color|#f7f|β’}}</big> ''int'' :: r6: Value β <big>{{color|#f7f|β’}}</big> ''id'' The <big>{{color|#f7f|β’}}</big> marker is at the beginning of each of these added rules; the parser has not yet confirmed and parsed any part of them. These additional items are called the "closure" of the core items. For each nonterminal symbol immediately following a <big>{{color|#f7f|β’}}</big>, the generator adds the rules defining that symbol. This adds more <big>{{color|#f7f|β’}}</big> markers, and possibly different follower symbols. This closure process continues until all follower symbols have been expanded. The follower nonterminals for state 2 begins with Products. Value is then added by closure. The follower terminals are ''int'' and ''id''. The kernel and closure items together show all possible legal ways to proceed from the current state to future states and complete phrases. If a follower symbol appears in only one item, it leads to a next state containing only one core item with the <big>{{color|#f7f|β’}}</big> marker advanced. So ''int'' leads to next state 8 with core :: r5: Value β ''int'' <big>{{color|#f7f|β’}}</big> If the same follower symbol appears in several items, the parser cannot yet tell which rule applies here. So that symbol leads to a next state that shows all remaining possibilities, again with the <big>{{color|#f7f|β’}}</big> marker advanced. Products appears in both r1 and r3. So Products leads to next state 3 with core :: r1: Sums β Sums + Products <big>{{color|#f7f|β’}}</big> :: r3: Products β Products <big>{{color|#f7f|β’}}</big> * Value In words, that means if the parser has seen a single Products, it might be done, or it might still have even more things to multiply together. All the core items have the same symbol preceding the <big>{{color|#f7f|β’}}</big> marker; all transitions into this state are always with that same symbol. Some transitions will be to cores and states that have been enumerated already. Other transitions lead to new states. The generator starts with the grammar's goal rule. From there it keeps exploring known states and transitions until all needed states have been found. These states are called "LR(0)" states because they use a lookahead of ''k''=0, i.e. no lookahead. The only checking of input symbols occurs when the symbol is shifted in. Checking of lookaheads for reductions is done separately by the parse table, not by the enumerated states themselves.
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)