Chap6 LR Parsing

Download Report

Transcript Chap6 LR Parsing

Chap6 LR Parsing
YANG
YANG1
• Recall some terminologies:
phrase:
* a
a  (Vt  Vn)*, A  Vn, A 
simple phrase:
a  (Vt  Vn)*, A  Vn, A  a
handle of a sentential form:
leftmost simple phrase of the
sentential form.
e.g.
S
A
a
consider the
sentential form
B
aAbabB
a A
b
b B
handle
simple
phrase
Chap6 LR Parsing
YANG
YANG2
• shift-reduce parser: two operations:
shift input into the parse stack
until the handle is identified; then
reduce the handle to the LHS
nonterminal
e.g. Given the grammar
P  begin S end $
Sa;S
S  begin S end ; S
S
begin a ; begin a ; end ; end $
input
stack
handles: l
(trace this example)
a;S
l
begin S end; S
a; S
begin S end$
Chap6 LR Parsing
YANG
YANG3
LOOKING AT THE TREE
P
begin
S
a ;
begin
a
S
;
end
$
S
end
S
;
S
l
l
(bottom-up tree construction)
(This is an overlay slide.)
(p. 159)
Chap6 LR Parsing
YANG
YANG4
LOOKING AT THE DERIVATION
P  begin S end $
 begin a ; S end $
 begin a ; begin S end ; S end $
 begin a ; begin S end ; l end $
 begin a ; begin a ; S end ; end $
 begin a ; begin a ; l end; end $
handles
(This is a rightmost derivation.)
Chap6 LR Parsing
YANG
YANG5
Two questions:
1. Have we reached the end of handles
and how long is the handle?
2. Which nonterminal does the handle
reduce to?
• We use tables to answer the questions.
ACTION table
GOTO table
• We first show how to use the table,
then how to construct the table.
Chap6 LR Parsing
YANG
YANG6
1. How does the LR(0) parser work?
2. How are the action and goto tables
constructed?
3. Is LR(0) parsing correct?
4. LR(1)
5. SLR(1)
6. LALR(1)
Chap6 LR Parsing
YANG
YANG7
• LR parsers are driven by two tables:
action table, which specifies what
actions to take (shift, reduce,
accept or error)
goto table, which specifies state
transition
and we push states, rather than
symbols, onto the stack.
Each state represents a subtree of
the parse tree.
Chap6 LR Parsing
YANG
YANG8
shift-reduce-driver /*look ahead 1 token*/
{ push( start_state );
T := scanner();
do {
S := state on top of stack
switch( action(S,T) )
case shift:
push( state(S,T) );
T := scanner();
break;
case reduce i:
m := length of RHS of prod. i;
pop( m );
S := state on top of stack after
poping;
X := LHS of prod. i;
push( state(S,X) );
break;
case accept: ...
case error: ...
end
} forever
}
Chap6 LR Parsing
YANG
YANG9
Chap6 LR Parsing
YANG
YANG10
• Parsing Example
Chap6 LR Parsing
YANG
YANG11
§6.2 LR parsers
LR(1): left-to-right scanning
rightmost derivation(reverse)
1-token lookahead
• LR parsers are deterministic
no backup, no retry
• LR(k) parsers decide the next action by
examining the tokens already shifted
and at most k lookahead tokens.
• LR (1) is the most powerful of
deterministic bottom-up parsers with
at most k lookahead tokens.
Chap6 LR Parsing
YANG
YANG12
Use the four small grammars to
motivate the construction of
LR tables.
Chap6 LR Parsing
YANG
YANG13
§6.2.1 LR(0) tables
• A production has the form AX1X2...Xj.
• By adding a dot, we get an item
(configuration)
e.g.
A·X1 X2 ... Xj
AX1 · X2 ... Xj
... ...
AX1 X2 ... Xj ·
The · indicates how much of a RHS has
been shifted into the stack.
Chap6 LR Parsing
YANG
YANG14
• An item with the · at the end of the RHS,
AX1 X2 ... Xj ·
indicates (or recognized) that RHS
should be reduced to LHS.
• An item with the · at the beginning of
RHS, i.e.
A·X1 X2 ... Xj
predicts that RHS will be shifted into the
stack.
Chap6 LR Parsing
YANG
YANG15
• An LR(0) state is a set of items.
This means that the actual state of LR(0)
parsers is denoted by one of the items.
• The close operation:
if there is an item Aa·Bb in the set
then add all items of the form B·g
to the set.
• The initial state is
close( { S·a$ } )
where S is the start symbol.
• Show the construction for grammar
SE$
EE+T
ET
T  id
T(E)
Chap6 LR Parsing
YANG
YANG16
• Close operation example
Chap6 LR Parsing
• LR(0) Parsing
• For example, given grammar G2
S'S$
SID|l
YANG
YANG17
Chap6 LR Parsing
YANG
YANG18
• Build goto function from CFSM
Chap6 LR Parsing
YANG
YANG19
• To construct the action table of
LR(0)
parsers, we use the following rule:
Chap6 LR Parsing
YANG
YANG20
• The state diagram is called the
characteristic finite state machine
(CFSM) of the grammar.
• CFSM is the goto table of LR(0) parsers.
Chap6 LR Parsing
YANG
YANG21
• Action table of LR(0)
1. S
2. S
3. S
...
B  r·
...
...
B  a·ab
...
...
S  a$·
...
action[S] =
reduce with B  r
action[S] = shift
where a  Vt
action[S] = accept
4. otherwise, action[S] = error
* Show the action table for the previous
example.
Chap6 LR Parsing
YANG
YANG22
• Constructing the LR(0) machine
SE$
EE+T
ET
T  id
T(E)
The initial state is
close( { E · E $ } )
Figure 6.11 CFSM for G1
Figure 6.12 action table for G1
Chap6 LR Parsing
YANG
YANG23
• Consider G1
SE$
EE+T | T
TID|(E)
CFSM for G1 
Chap6 LR Parsing
YANG
YANG24
• Two kinds of conflicts:
1. shift-reduce conflict
if there exist S such that action(S)
can be either shift or reduce
In this case, the parser does not
know whether to shift or to reduce.
2. reduce-reduce conflict
if there exist S such that action(S)
contains two reduce entries.
In this case, the parser does not
know which production to use in
reduction.
• A grammar is LR(0) iff there is no
conflict in the action table.
Chap6 LR Parsing
YANG
YANG25
• Few practical grammars are LR(0).
1. For instance, consider any
l-production A .
If A can generate any terminal string,
then there must be a shift-reduce conflict
Suppose b  First(A),
reduce to
a·by----------------> aA·by
or
shift
a·by----------------> ab·y
2. Also consider operator precedence:
reduce to
id + id · + id-----------------> E· + id
or
shift
id + id · * id------------------> id + id * · id
(remember no lookahead!)
Chap6 LR Parsing
YANG
YANG26
§6.3 LR(1) parsing
• An LR(1) item has the form
A  X1X2... Xi·Xi+1... Xj, l
l  { l }  Vt
l is the set of terminals that may
follow A in some context.
• close(S)
{ for each item in S do
if the item is B  d·Ar,l
then add A  ·g, First(rl)
for each production with
LHS A (i.e. A  g )
}
Chap6 LR Parsing
YANG
YANG27
Ex. S  E $
EE+T
ET
T  ID
T(E)
First(S) = First(E) = First(T) = { ID, ( }
close( S  ·E$, { l } )
={ S  ·E$, { l }
E  ·E+T, { $+ }
E  ·T,
{ $+ }
T  ·ID, { $+ }
T  ·(E), { $+ }
}
Chap6 LR Parsing
YANG
YANG28
Constructing the LR(1) machine
• A state is a set of items.
•
A b·xr,l
......
x
A bx·r,l
......
(then close the set)
• Starting state is
close(S  ·E$ {l})
• Ex.
SE$
EE+T
ET
TT*P
TP
P  ID
P(E)
Chap6 LR Parsing
YANG
YANG29
Figure 6.16
LR(1) machine for G3
Chap6 LR Parsing
YANG
YANG30
Chap6 LR Parsing
YANG
YANG31
• Action table of LR(1)
1. S
2. S
3. S
...
B  r ·, { a }
...
...
B  a·ab, l
...
...
S  a·$, { l }
...
action[S,a] =
reduce with B  r
action[S,a] = shift
where a  Vt
action[S,$] = accept
4. otherwise, action[S,x] = error
* Show the action table for the previous
example.
Chap6 LR Parsing
YANG
YANG32
Figure 6.17
LR(1) action table for G3
Chap6 LR Parsing
YANG
YANG33
G is LR(1) iff there is no conflict in the
action table.
Chap6 LR Parsing
YANG
YANG34
• Compare LR(0) and LR(1)
SE$
EE+T|T
G 3: T  T * P | P
P  ID
|(E)
LR(1)
In LR(0) nachine:
S0
S  ·E$
E  ·E+T
E  ·T
T  ·T*P
T  ·P
P  ·ID
P  ·(E)
G3 is not LR(0).
T
E  T·
E  T·*P
reduce-shift
conflict!
Chap6 LR Parsing
YANG
YANG35
In LR(1) machine,
S0
S  ·E$
{l}
E  ·E+T {$+}
E  ·T
{$+}
T  ·T*P {$+*}
T  ·P
{$+*}
P  ·ID
{$+*}
P  ·(E)
{$+*}
T
S7
E  T·
{$+}
T  T·*P {$+*}
*
S8
T  T*·P {$+*}
P  ·ID {$+*}
P  ·(E) {$+*}
action[S7,+] = reduce
action[S7,$] = reduce
action[S7,*] = shift
No conflict!
G3 is LR(1).
Chap6 LR Parsing
YANG
YANG36
6.4 SLR(1)
• LR(1) is very powerful.
• The goto and action tables of LR(1)
are too big due to too many states.
• two alternatives to LR(1)
» SLR(1): LR(0) machine+lookahead
» LALR(1): merge states of LR(1)
machine
Chap6 LR Parsing
YANG
YANG37
• SLR(1) uses LR(0) machine to define
the goto table.
• Only the action table is different.
1. S
2. S
3. S
...
B  r·
...
...
B  a·ab
...
...
S  a·$
...
action[S,a] =
reduce with B  r
for all a  Follow(B)
action[S,a] = shift
where a  Vt
action[S,$] = accept
4. otherwise, action[S] = error
* Show the action table for the previous
example.
Chap6 LR Parsing
YANG
YANG38
Follow(T) = { + * ) $ }
Follow(E) = { + ) $ }
Follow(P) = { +* ) $ }
Note states 7, 10, and 11.
Figure 6.18
CFSM for G3
Chap6 LR Parsing
YANG
YANG39
Figure 6.19
SLR(1) action function for G3
Chap6 LR Parsing
YANG
YANG40
• G is SLR(1) iff there is no conflict in the
action table.
• Show example on pp.164 - 165.
• For inadequate states (7 and 11), we
use Follow sets to resolve conflicts.
• For adequate states, we may or may
not use Follow sets.
Ex. state 10.
» LR(0) always reduce
» SLR(1) ??
trade off:
early error detection
smaller tables.
Chap6 LR Parsing
YANG
YANG41
§6.4.2
• The lookahead in LR(1) machine is
computed from the context.
whereas the lookahead in SLR(1) is the
follow sets.
• LR(1) lookaheads are more precise.
Chap6 LR Parsing
YANG
YANG42
• Some grammars are LR(1) but
not SLR(1)
Ex. E  ( L , E )
ES
S  ID
G4 S  ( S )
LL,E
LE
part of LR(0) machine:
0 E  ·(L,E)
E  ·S
S  ·ID
S  ·(S)
(
1 E  (·L,E)
S  (·S)
L  ·E
E  ·(L,E)
E  ·S
S  ·ID
S  ·(S)
S
2 S  (S·)
E  S·
Chap6 LR Parsing
YANG
YANG43
• Now Follow(E) = { ) ... }
So action[2,)] = shift
action[2,)] = reduce
There is a conflict!
This grammar cannot be SLR(k) for any k.
This grammar is LR(1).
action[2,)] = reduce
action[2,)] = shift
Chap6 LR Parsing
YANG
YANG44
• Lookahead in SLR(1) is inexact.
Ex. state 4 in Fig. 6.16
Follow(T) = { * $ + ) }
in LR(1)
action[4,$] = reduce with T  P
action[4,+] =
“
action[4,*] =
“
action[14,)] = reduce with T  P
action[14,+] =
“
action[14,*] =
“
By construct, in SLR(1),
In state 4 of Fig. 6.18
action[4,$] = reduce with T  P
action[4,+] =
“
action[4,*] =
“
action[4,)] =
“
Chap6 LR Parsing
YANG
YANG45
• Since SLR(1) uses inexact lookahead,
some unnecessary conflicts may occur.
Solution:
» change the grammar
» change the parser (e.g. LALR(1))
Chap6 LR Parsing
YANG
YANG46
6.5 LALR(1)
• Merge states of LR(1) machine that
differ only in the lookaheads.
Ex. Consider LR(1) machine of G3 on
p.160 (Fig. 6.16).
1. states 13 and 15 are combined
13 P(E)· {$+*}
15 P(E)· {)+*}
2. 4
P(E)· {$+*)}
10
TP· {$+*}
14 TP· {)+*}
TP· {$+*)}
4
Chap6 LR Parsing
YANG
YANG47
3. 3 EE+·T $+
T·T*P $+*
T·P $+*
P·ID $+*
P·(E) $+*
17 EE+·T )+
T·T*P )+*
T·P )+*
P·ID )+*
P·(E) )+*
4.
5.
6.
7.
8.
9.
10.
states 11, 20
states 12, 16
states 7, 19
states 9, 22
states 8, 21
states 6, 18
states 5, 10
EE+·T $+)
T·T*P $+*)
T·P $+*)
P·ID $+*)
P·(E) $+*)
3
Chap6 LR Parsing
YANG
YANG48
Figure 6.22
LALR(1) machine for G3
23 states
11 states
in LR(1)
in LALR(1)
Chap6 LR Parsing
YANG
YANG49
Chap6 LR Parsing
YANG
YANG50
• Construct the action table of LALR(1)
(same as LR(1)).
1. S
2. S
3. S
...
B  r·,{a}
...
action[S,a] =
reduce with B  r
...
B  a·ab,L
...
action[S,a] = shift
...
S  a·$,{$}
...
action[S,$] = accept
4. else action[S,a] = error
• G is LALR(1) iff there is no conflict in
the action table.
Chap6 LR Parsing
YANG
YANG51
Ex. G5: <prog>  <stmt> ;
<stmt>  ID
<stmt>  <var> := <exp>
<var>  ID
<var>  ID [ <exp> ]
<exp>  <var>
Further assume ;  Follow(<stmt>)
;  Follow(<var>)
0
<prog>  ·<stmt>;
<stmt>  ·ID
<stmt>  ·<var>:=<exp>
<var>  ·ID
<var>  ·ID[<exp>]
ID
1
<stmt>  ID·
<var>  ID·
<var>  ID·[<exp>]
Chap6 LR Parsing
YANG
YANG52
• In state 1, there is a reduce-reduce
conflict in LR(0).
The grammar is not SLR(1)
since ;  Follow(<stmt>) and
;  Follow(<var>).
However, in LALR(1), if we use
<var>  ID,
the next symbol must be :=
so action[ 1, := ] = reduce(<var>  ID)
action[ 1, ; ] = reduce(<stmt>  ID)
action[ 1,[ ] = shift
There is no conflict.
Chap6 LR Parsing
YANG
YANG53
• Change LALR(1) grammar to SLR(1):
– use new nonterminals.
Ex. <stmt>  <var> := <exp>
is change to
<stmt>  <LHS> := <exp>
<LHS>  ID
<LHS>  ID [ <exp> ]
Now Follow(<LHS>) = { := }
<prog>  ·<stmt>
<stmt>  ·ID
<stmt>  ·<LHS>:=<exp>
<LHS>  ·ID
<LHS>  ·ID[<exp>]
ID
This grammar is SLR(1).
<stmt>  ID·
<LHS>  ID·
<LHS>  ID·[<exp>]
Chap6 LR Parsing
YANG
YANG54
• One last example
S  ( E1 )
S  [ E1 ]
S  ( E2 ]
S  [ E2 )
E1  ID
E2  ID
1 S·(E1)
2 S (.E1)
S·[E1] (
S (.E2]
S·(E2]
E1 ·ID
S·[E2)
E2 ·ID
[
ID 4 E1 ID.
E2 ID.
ID
3 S [.E1]
S [.E2)
E1·ID
E2·ID
• State 4 contains a reduce-reduce conflict
since Follow(E1) = Follow(E2) = { ) ] }.
• Lookahead does not help.
• It is not SLR(1), not LALR(1).
• But it is LR(1) (state 4 is split into two
states).
Chap6 LR Parsing
YANG
YANG55
§6.5.1 Building LALR(1) parsers
» 1st approach: build LR(1) machine,
then merge states.
» 2nd approach: build LR(0) machine,
then add lookaheads.
• An item may be generated in two ways:
X
1. Aa·Xr,L1
AaX·r,L2
propagate link L2 = L1
2. close operation
Bb·Ag,L1
...
A·a,L2
L2 = First(g L1)
Chap6 LR Parsing
YANG
YANG56
Two cases:
1. if l  First(g)
Bb.Ag,L1
then
A.a2,L2
L2 = First( g )  L1 A.a3,L3
(called spontaneous)
propagate
link
2. if l First(r) then L2 = First( g )
(This is called spontaneous lookaheads.)
Now we have the situation:
S1 ... L
...
...
S3
S2
...
...
...
...
... L
We want to propagate spontaneous
lookaheads along the propagate links.
Chap6 LR Parsing
YANG
YANG57
• Use a stack (or queue) to propagate:
Each element of the stack is
(stack item L)
Initially, there is an element on the stack
for each spontaneous lookahead
while stack is not empty do
pop(state, item, L) from stack
propagate L along propagate links
of item
for each item j whose lookahead M
is change do
push(S, j, M) onto stack.
end
Chap6 LR Parsing
YANG
YANG58
Ex. S
 Opts $
Opts  Opt Opt
Opt  ID
S1
c1 S
·Opts$ {l}
c2 Opts·Opt Opt {$}
c3 Opt ·ID {ID}
S2
c1 OptsOpt·Opt {}
c2 Opt ·ID {}
S3
c1 OptID· {}
Chap6 LR Parsing
YANG
YANG59
stack
1. (S1 c2 {$})
(S1 c3 {ID})
2.
pop(S1 c2 {$})
update(S2 c1 {$})
(S2 c1 {$})
(S1 c3 {ID})
3.
pop(S2 c1 {$})
update(S2 c2 {$})
(S2 c2 {$})
(S1 c3 {ID})
4.
pop(S2 c2 {$})
update(S3 c1 {ID})
(S3 c1 {$})
(S1 c3 {ID}
5.
pop(S3 c1 {$})
No update
6.
pop(S1 c3 {ID})
update(S3 c1 {$ ID})
(S3 c1 {$ ID})
7.
pop(S3 c1 {$ ID})
No update: stack empty - done!
Chap6 LR Parsing
YANG
YANG60
• LALRGen uses the propagation
algorithm.
YACC examines each state repeatedly.
• Another way to compute lookahead
of LALR:
backward analysis (read the book)
Chap6 LR Parsing
YANG
YANG61
§ Correctness of LALR(1)
— State merging in LALR(1) may cause
conflicts.
Ex.
S1 Br·,{a}
Cg·,{b}
S2
Br·,{b}
Cg·,{d}
action[ S1, a ] = ...
action[ S2, b ] =
reduce with Br
action[ S1, b ] =
action[ S2, d ] = ...
reduce with Cg
After S1 and S2 are merged,
S1/S2
Br·,{a,b}
Cg·,{b,d}
action[ S1/S2, b ] =
reduce with Br
reduce with Cg
or
There is a reduce-reduce conflict.
Chap6 LR Parsing
YANG
YANG62
—Suppose no conflicts.
LALR(1) performs exactly as LR(1) on
correct input.
For incorrect input, error detection may
be delayed.
Chap6 LR Parsing
YANG
YANG63
§6.6 Semantic routines
• In LL(1), action symbols correspond to
semantic routines.
(Review LL(1) action symbols)
• In LL(1), action symbols may appear
any place of RHS of a production.
• In shift-reduce parsers, semantic
routines may be invoked only after a
production is recognized and reduced.
That is, action symbols can appear only
at the end of RHS.
Why?
Ab cd
Ab ef
need action 1
need action 2
However, this is not a serious problem.
Chap6 LR Parsing
YANG
YANG64
• Trick: use new nonterminals.
Ex. S  if C then S else S end
action action
S  if C A1 then S A2 else S end
A1  (semantic action here)
A2  (semantic action here)
• However, this is not trivial.
Ex. S  if C then S end
action 1
S  if C then S else S end
action2
We may create the following productions:
S  if C A1 then S end
S  if C A2 then S else S end
A1 
A2 
We will have a conflict after “if C“.
Chap6 LR Parsing
YANG
YANG65
• Alternative:
Break a production into pieces.
SXYZ
X  if C
Y  then S
Z  else S end
No l-production is needed in this case.
Chap6 LR Parsing
YANG
YANG66
§6.7 Parser Generator
» LALRGen
» YACC
Try the example lrada.bnf
lrpascal.bnf
lalrgen
§6.7.3 controlled ambiguity
• In LALRGen, when conflicts occur, we
may use the option resolve to give
preference to earlier productions.
• In YACC, conflicts are solved in
1. shift is preferred to reduce;
2. earlier productions are preferred.
• Grammars with conflicts are usually
smaller.
• Application: operator precedence and
associativity.
Chap6 LR Parsing
YANG
YANG67
§6.8 Optimizing the parsing tables
1. GOTO and ACTION tables may be
combined
state1
terminal
S/5
Chap6 LR Parsing
YANG
YANG68
2. Many states recognize a single
reduction. These are called
single-reduce states.
Ex.
+ * ID ( ) $ E
4 R5 R5
R5 R5
5 R6 R6
R6 R6
0 ... ...
T
P
S4L5
• Whenever the parser is in singlereduce states, we always perform the
reduction.
Therefore the state may be erased.
• Error detection may be delayed, but the
parser still works correctly.
• Removing single-reduce states could
be very useful in practice.
Chap6 LR Parsing
YANG
YANG69
Figure 6.35
SLR(1) parse table for G3
and
Figure 6.36
Optimized SLR(1) parse table for G3
Chap6 LR Parsing
YANG
YANG70
3. almost-single-reduce states
Ex. states 7 and 11 in Fig. 6.35
We can make R2 as the default action
for state 11.
+ * ID ( ) $ E T P
11 R2 S8 R2 R2 R2 R2 R2 R2 R2
R2 11
S8
• This makes the table sparser.
Thus, it might be easier to compress.
• Error detection may be delayed.
Chap6 LR Parsing
YANG
YANG71
4. Unit productions
Consider E  T | E + T
TP|T*P
P  ID
Frequently, ID is reduced to P,
P is reduced to T,
T is reduced to E.
This chain of unit reductions can be
collepsed into a single reduction.
• These unit productions are frequently
used to enforce operator precedence.
n precedence levels 
n+1 unit productions
Chap6 LR Parsing
YANG
YANG72
• If no action symbol is involved, some
unit reductions may be skipped.
Ex. Consider
S  ·E$
E  ·E+T $+
E  ·T
$+
T  ·T*P
T  ·P
$+*
P  ·ID
$+*
P  ·(E)
T
E  T· $+
E  T·*P ...
E
S  E·$ $
E  E·+T ...
P
T  P· ...
ID
P  ID· $+*
at this state,
*  ID is reduced to T
+  ID is reduced to E
$  accept
by constrast, in LR(1)
*,+,$  reduce ID to P
Chap6 LR Parsing
YANG
YANG73
• Unit production optimization may speed
up parsing, but probably will create new
states.
Chap6 LR Parsing
YANG
YANG74
§6.9
LR(1)
LALR(1)
merge all
similar
states
Chap6 LR Parsing
YANG
YANG75
§6.10 Properties of LR
• correct
• error detection occurs when the
offending terminal is about to be shifted.
• un-ambiguous grammars
• deterministic parsing (no backtrack)
• linear time
because parse tree size is linear in
the size of input.
• linear space
If no l-production,
stack size £ input size
with l-productions,
Each l-production may be used
at most once when each terminal
is shifted.
input
a1 a2 ... an
Chap6 LR Parsing
YANG
YANG76
§6.11 Comparison
LALR(1)
simple driver
more general
more restrictive
action
LL(1)
simple driver
stricter
flexible placement
of action symbols
error repair is
easier
Pascal
|Vt| = 60
|Vn| = 127
|P| = 280
3358 entries
|Vt| = 60
|Vn| = 125
|P| = 234
1231 entries
# of states = O( eg ) g is grammar size.
2
:
(size ratio)
Speed is comparable.
1
Chap6 LR Parsing
YANG
YANG77
§6.12
1. LR(k)
SLR(k)
LALR(k)
2. precedence parsing
– simple precedence
– operator precedence
3. Earleys algorithm
– for all context-free grammars