lr parsing - the algorithm -...
TRANSCRIPT
LR Parsing - The AlgorithmLecture 13
Sections 4.5, 4.7
Robb T. Koether
Hampden-Sydney College
Wed, Feb 18, 2015
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 1 / 19
1 The Algorithm
2 Shift/Reduce Conflicts
3 Precedence and Associativity
4 Assignment
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 2 / 19
Outline
1 The Algorithm
2 Shift/Reduce Conflicts
3 Precedence and Associativity
4 Assignment
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 3 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 ( 4 id + id ) * id $
0 ( 4 id 5 + id ) * id $
0 ( 4 F 3 + id ) * id $
0 ( 4 T 2 + id ) * id $
0 ( 4 E 8 + id ) * id $
0 ( 4 E 8 + 6 id ) * id $
0 ( 4 E 8 + 6 id 5 ) * id $
0 ( 4 E 8 + 6 F 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 4 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
Example
Example (LR Parsing)
Stack Input0 ( 4 E 8 + 6 T 9 ) * id $
0 ( 4 E 8 ) * id $
0 ( 4 E 8 ) 11 * id $
0 F 3 * id $
0 T 2 * id $
0 T 2 * 7 id $
0 T 2 * 7 id 5 $
0 T 2 * 7 F 10 $
0 T 2 $
0 E 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 5 / 19
In practice, we need only push the state numbers onto the stack.There is no need to push the grammar symbols.Thus, the previous example can be streamlined.
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 6 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (Parse ( id + id )∗ id)
Stack Input0 ( id + id ) * id $
0 4 id + id ) * id $
0 4 5 + id ) * id $
0 4 3 + id ) * id $
0 4 2 + id ) * id $
0 4 8 + id ) * id $
0 4 8 6 id ) * id $
0 4 8 6 5 ) * id $
0 4 8 6 3 ) * id $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 7 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (LR Parsing)
Stack Input0 4 8 6 9 ) * id $
0 4 8 ) * id $
0 4 8 11 * id $
0 3 * id $
0 2 * id $
0 2 7 id $
0 2 7 5 $
0 2 7 10 $
0 2 $
0 1 $
Accept $
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 8 / 19
Example
Example (A Simplified Grammar)We may simplify our grammar to
E → E + EE → E * EE → ( E )
E → id
In this form, the precedence rules for + and * are not implicit.They must be incorporated into the tables.
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 9 / 19
Outline
1 The Algorithm
2 Shift/Reduce Conflicts
3 Precedence and Associativity
4 Assignment
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 10 / 19
Shift/Reduce Conflicts
It is possible that a cell will contain both a shift operation and areduce operation.This is called a shift/reduce conflict.To choose between “shift” and “reduce,” each case must beconsidered on its own merit.Consider the case of E → E + E | E ∗ E and the inputsa + b * c and a * b + c.
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 11 / 19
Reduce/Reduce Conflicts
It is possible that a cell will contain two different reduce operations.This is called a reduce/reduce conflict.This occurs when a sequence of tokens matches the right-handsides of two different productions at the same time.For each such conflict in the table, we must choose whichreduction to apply.
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 12 / 19
Example
Example (The Action and Goto Tables)State Action Goto
+ * ( ) id $ E0 s2 s3 11 s5 s6 acc2 s2 s3 73 r4 r4 r4 r44 r5 r5 r5 r55 s2 s3 86 s2 s3 97 s5 s6 s108 s5/r1 s6/r1 r1 r19 s5/r2 s6/r2 r2 r2
10 r3 r3 r3 r3
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 13 / 19
Outline
1 The Algorithm
2 Shift/Reduce Conflicts
3 Precedence and Associativity
4 Assignment
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 14 / 19
Example
Example (Shift/Reduce Conflicts and Associativity)The shift/reduce conflict in cell (8,+) is between shifting a + andreducing by
E → E + E .
If we choose “shift,” then we will make addition right associative.If we choose “reduce,” then we will make addition left associative.The case is similar in cell (9,*) regarding multiplication.
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 15 / 19
Example
Example (Shift/Reduce Conflicts and Precedence)The shift/reduce conflict in cell (9,+) is between shifting a + andreducing by
E → E * E .
If we choose “shift,” then we will give multiplication a higherprecedence than addition.If we choose “reduce,” then we will give addition a higherprecedence than multiplication.The case is similar in cell (8,*).
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 16 / 19
Example
Example (The Action and Goto Tables)State Action Goto
+ * ( ) id $ E0 s2 s3 11 s5 s6 acc2 s2 s3 73 r4 r4 r4 r44 r5 r5 r5 r55 s2 s3 86 s2 s3 97 s5 s6 s108 r1 s6 r1 r19 r2 r2 r2 r210 r3 r3 r3 r3
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 17 / 19
Outline
1 The Algorithm
2 Shift/Reduce Conflicts
3 Precedence and Associativity
4 Assignment
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 18 / 19
Assignment
HomeworkLet the grammar be
S → ( L ) | idL→ L , S | S
Parse the expression (id,id).
Robb T. Koether (Hampden-Sydney College) LR Parsing - The Algorithm Wed, Feb 18, 2015 19 / 19