1 / 11

Prof. Roy Levow

COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 7, 10/09/2003. Prof. Roy Levow. Bottom-up Parsing. Almost always automatic generation Because algorithm is complex Uses Push-down Automata

dexter
Download Presentation

Prof. Roy Levow

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP 4620 / 5625Programming Language Translation /Compiler WritingFall 2003Lecture 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. 2.100

  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

More Related