Back to A Sample Parser. On to Shift-Reduce Parsing (2).
Held: Friday, 5 March 2004
Summary: Today we consider an alternate form of parsing, shift-reduce parsing. Shift-reduce parsing can be applied to many more grammars than can predictive parsing.
Related Pages:
Notes:
Overview:
s ::= b | c b ::= A b B b ::= epsilon c ::= A c C c ::= epsilon
left-to-right traversal of the input, the next R stands for
rightmost derivationand the k stands for
number of characters of lookahead.
Wait!You may say,
How can we build a parser with no lookahead?
end of input($) to the start symbol.
S' ::= S $
S' ::= . S $
when we begin parsing, we are ready to match an S
and the end-of-input symbol
S' ::= . E $ E ::= . E + T E ::= . E - T E ::= . T
S' ::= . E $ E ::= . E + T E ::= . E - T E ::= . T T ::= . T mulop F T ::= . F F ::= . id F ::= . num F ::= . ( E )
here mark(period) over that symbol in all rules, and then filling in the rest.
S' ::= E . $ E ::= E . + T E ::= E . - T
E ::= E + . T
T, so we need to fill in
all the items that say ready to see a T
E ::= E + . T T ::= . T mulop F T ::= . F F ::= . id F ::= . num F ::= . ( E )
here markand get to
E ::= E + T . T ::= T . mulop F
E. The
second suggests that we may be in the midst of a T.
How do we decide which it is? By context (and a little lookahead
in some cases).
Back to A Sample Parser. On to Shift-Reduce Parsing (2).
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
Misc:
[2001S]
[2002F]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed May 5 11:47:05 2004.
The source to the document was last modified on Tue Jan 20 23:06:46 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2004S/Outlines/outline.20.html.
You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby
Samuel A. Rebelsky, rebelsky@grinnell.edu