Download presentation
Presentation is loading. Please wait.
Published byMelina Freeman Modified over 5 years ago
1
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 7, 10/09/2003
Prof. Roy Levow
2
Bottom-up Parsing Almost always automatic generation
Because algorithm is complex Uses Push-down Automata Basic principles are can be seen with LR(0) though it is of little practical value “handle” is complete sequence of children that can be “reduced”
3
LR(0) Using dotted notation
A shift item has dot anywhere but end A reduce item has dot at end Item sets are sets of items that can occur in a state
4
Sample Grammar for LR(0)
5
Transition Diagram
6
LR(0) PDA
7
Example LR(0) Parse
8
LR Parsing with Lookahead
There are a number of variants for LR parsing with lookahead Problem is that tables for direct approaches can be very large 1M for LR(1) 10K for SLR(1) 1K for LALR(1) Smaller size reduces class of languages that can be parsed
9
Example for LR(1)
10
LALR(1) Automaton, fig
11
Conflicts & Error Recovery
Grammars that are not LR(1) exhibit Shift-Reduce Conflicts Reduce-Reduce Conflicts Adding actions often generates conflicts Error recovery Add symbol in input Pop items from stack and input to recovery point
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.