10-LR-Parsing - CS 421 Lecture 9: LR parsing and resolving...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 421 Lecture 9: LR parsing and resolving conflicts s Review s Top-down parsing s Bottom-up parsing s Lecture outline s What are conflicts? s Using parse trees to understand conflicts s Fixing conflicts s Eliminating conflicts using %prec declarations 6/22/2009 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Review: Top-down parsing s A.K.A. recursive descent s One parse function per non-terminal s Ambiguity s LL(1) condition s Parse tree construction s Precedence s Associativity s How do we choose which production to apply? 6/22/2009 2
Background image of page 2
Review: Bottom-up parsing s A.K.A. shift-reduce s Keep a stack of partial parse trees s Automatic parser generation (ocamlyacc) s Actions s Shift s Reduce s Accept s Reject s How to decide which action to take? s Today: dealing with conflicts 6/22/2009 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Conflicts s Big question: how to choose whether to shift or reduce? s ocamlyacc uses a method – called LALR(1) – to construct tables that say which action to take s There are times when there is no good way to make this decision s ocamlyacc will reject grammar and give an error message s In bottom-up parsing, these are called conflicts s As with top-down parsing, these problems can sometimes be resolved by modifying the grammar. 6/22/2009 4
Background image of page 4
Conflicts s Ocamlyacc generates tables saying which action to take at each point in the parse s Method is called “LALR(1)” s “LR(1)” is a similar, but somewhat more powerful, method. Will often use “LR(1)” and “LALR(1)” as synonyms. ot every grammar can be parsed using this method
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/01/2009 for the course CS CS421 taught by Professor Kirillmechitov during the Summer '09 term at University of Illinois, Urbana Champaign.

Page1 / 24

10-LR-Parsing - CS 421 Lecture 9: LR parsing and resolving...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online