[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]
Back to Shift-Reduce Parsing (1). On to Shift-Reduce Parsing (3).
Held: Monday, 8 March 2004
Summary: Today we consider how to build shift-reduce automata and the tables that represent them.
Related Pages:
Overview:
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 ::= . exp $
exp ::= . exp + term exp ::= . exp - term exp ::= . term
S ::= . exp $ exp ::= . exp + term exp ::= . exp - term exp ::= . term term ::= . term MULOP factor term ::= . factor factor ::= . id factor ::= . num factor ::= . ( exp )
here mark(period) over that symbol in all rules, and then filling in the rest.
s ::= exp . $ exp ::= exp . + term exp ::= exp . - term
exp ::= exp + . t term
term, so we need to fill in
all the items that say ready to see a term
exp ::= exp + . term term ::= . term MULOP factor term ::= . factor factor ::= . id factor ::= . num factor ::= . ( exp )
here markand get to
exp ::= exp + term . term ::= term . MULOP factor
exp. The
second suggests that we may be in the midst of a term.
How do we decide which it is? By context (and a little lookahead
in some cases).
fills in the restwhenever we advance the mark. We'll call this
closure
closure(State S)
repeat
for each item, n ::= alpha . m beta in S
for each production M ::= gamma
add m ::= . gamma to S
end for each production
end for each item
until no changes are made to S
return S
end closure
goto
goto(State S, Symbol sym)
newS = {}
for each item n ::= alpha . sym beta in S
newS = newS union { N ::= alpha sym . beta }
end for
return closure(newS)
end goto
S0 = { s' ::= . s $ }
S0 = closure(S0);
while there are unmarked states
pick an unmarked state, S
mark S
for each symbol, sym, add state goto(S,s) with edge labelled s
end while
Back to Shift-Reduce Parsing (1). On to Shift-Reduce Parsing (3).
[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:06 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.21.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby