Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
LR parser
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
LR parser
(section)
Add topic