















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Compiler Design; Subject: Computer & Info Science; University: Syracuse University; Term: Unknown 1989;
Typology: Study notes
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















In top-down parsers, the stack will have non-terminals which canbe expanded by replacing it with the right-hand-side of a production
-^
In bottom-up parsers, the stack will have sequences of terminalsand non-terminals which can be reduced by replacing it with thenon-terminal for which it is the rhs of a production
Sometimes called LL(k)
deterministic
If a grammar is not in an LL(k) form, removing left recursion anddoing left-factoring may produce one
Scan the input from Left to Right
-^
Produce a Rightmost derivation from the grammar
id
T’
e
E’
id
T’
id
T’
e
E’
e
id + id * id $id + id * id $id + id * id $id + id * id $
id * id $id * id $id * id $
id $id $
$E $E’T$E’T’F$E’T’id$E’T’$E’$E’T +$E’T$E’T F$E’T’ id$E’T’$E’T’ F *$E’T’ F$E’T’ id$E’T’$E’$
Output
Input
Stack
For each terminal a in First(E),
add N
E to M[N, a]
If
ε
is in First(E), for each terminal b in Follow(N),
add N
E to M[N, b]
If
ε
is in First(E) and eot is in Follow(N),
add N
E to M[N, b]
All other entries are errors
the stack has a sequence of terminal and non-terminal symbolsrepresenting the part of the input worked on so far, and
-^
the input has the remaining symbols
Reduce: If the stack has a sequence FE and there is a productionN
E, we can replace E by N to get FN on the stack
Shift: If there is no possible reduction, transfer the next inputsymbol to the top of the stack
-^
Error: otherwise it is an error
Matches the rhs of a production
-^
Will be a step along the path of producing a correct parse tree
E.g. dangling else problem
The TOS state and the next input symbol are used to look upthe parser’s actions and goto function from the table
Has more history on the stack to make decisions than top-down
16
Closure is defined to construct a configurating set for each item. For thestarting item, N
-^
N
W .Y is in the set
-^
If Y begins with a terminal, we are done
-^
If Y begins with a non-terminal N’, add all N’ productions with the dot at thestart of the rhs, N’
.Z
For each configurating set and grammar symbol, the goto operation givesanother configurating set.^ –
If a set of items I contains items of the form N
W. x Y, where W and Y
are sequences but x is a single grammar symbol, the goto(I,x) contains
N
W x. Y
To create the family of configurating sets for a grammar, add an initialproduction S’
S, and construct sets from
Use the sets for parser states – states that end with a dot will be reduce
-^
Example pg. 11 of Stanford Notes 9
A configurating set can have only shift or reduce and not both basedon the input
Epsilon rules create shift/reduce conflict if there are other rules
-^
Items like these have shift/reduce conflicts:
id.
id. [ E ]
Items like these have reduce/reduce conflicts
id. , T
id.
Identify a core of configurating sets and merge states that differ onlyby lookahead
actions, but it may introduce reduce/reduce conflicts that LR(1)did not have
is not usually done by brute force to construct LR(1) and then mergesets
-^
As configurating sets are generated, a new configurating set isexamined to see if it can be merged with an existing one