070_Advanced_Parsing

070_Advanced_Parsing - Advanced Parsing Techniques...

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

View Full Document Right Arrow Icon
Advanced Parsing Techniques
Background image of page 1

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

View Full DocumentRight Arrow Icon
Announcements Written Assignment 2 out , due Monday, July 18 at 5:00PM. Start early; this problem set is tricky! Programming Project 2 due Wednesday, July 11 at 11:59 PM.
Background image of page 2
Where We Are
Background image of page 3

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

View Full DocumentRight Arrow Icon
Where We Are
Background image of page 4
Parsing so Far We've explored five deterministic parsing algorithms: LL(1) LR(0) SLR(1) LALR(1) LR(1) These algorithms all have their limitations. Can we parse arbitrary context-free grammars?
Background image of page 5

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

View Full DocumentRight Arrow Icon
Why Parse Arbitrary Grammars? They're easier to write . Can leave operator precedence and associativity out of the grammar. No worries about shift/reduce or FIRST/FOLLOW conflicts. If ambiguous, can filter out invalid trees at the end. Generate candidate parse trees, then eliminate them when not needed. Practical concern for some languages. We need to have C and C++ compilers!
Background image of page 6
Questions for Today How do you go about parsing ambiguous grammars efficiently ? How do you produce all possible parse trees ? What else can we do with a general parser?
Background image of page 7

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

View Full DocumentRight Arrow Icon
The Earley Parser
Background image of page 8
Motivation: The Limits of LR LR parsers use shift and reduce actions to reduce the input to the start symbol. LR parsers cannot deterministically handle shift/reduce or reduce/reduce conflicts. However, they can nondeterministically handle these conflicts by guessing which option to choose. What if we try all options and see if any of them work?
Background image of page 9

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

View Full DocumentRight Arrow Icon
The Earley Parser Maintain a collection of Earley items , which are LR(0) items annotated with a start position. The item A → u·v @n means we are working on recognizing A → uv , have seen u , and the start position of the item was the nth token. Each Earley item has a position in the input sequence denoting where the next symbol of input is. Using techniques similar to LR parsing, try to scan across the input creating these items. We're done when we find an item S → @1 at the very last position.
Background image of page 10
Earley in Action S → E E → E + E E → int
Background image of page 11

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

View Full DocumentRight Arrow Icon
Earley in Action S → E E → E + E E → int + int + int int
Background image of page 12
Earley in Action S → E E → E + E E → int + int + int int
Background image of page 13

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

View Full DocumentRight Arrow Icon
Earley in Action S → E E → E + E E → int + int + int int Items 1 Items 2 Items 3 Items 4 Items 5 Items 6
Background image of page 14
Earley in Action S → E E → E + E E → int + int + int int Items 1 Items 2 Items 3 Items 4 Items 5 Items 6 SCAN PREDICT COMPLETE
Background image of page 15

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

View Full DocumentRight Arrow Icon
Earley in Action S → E E → E + E E → int + int + int int Items 1 Items 2 Items 3 Items 4 Items 5 Items 6 SCAN PREDICT COMPLETE S→·E @1
Background image of page 16
PREDICT SCAN COMPLETE Earley in Action S → E E → E + E E → int + int + int int Items 1 Items 2 Items 3 Items 4 Items 5 Items 6 S→·E @1
Background image of page 17

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

View Full DocumentRight Arrow Icon
PREDICT SCAN COMPLETE Earley in Action S → E E → E + E E → int + int + int int Items 1 Items 2 Items 3 Items 4 Items 5 Items 6 S→·E @1 E→·E+E @1 E→·int @1
Background image of page 18
SCAN PREDICT COMPLETE Earley in Action S → E E → E + E E → int + int + int int Items 1 Items 2 Items 3 Items 4 Items 5 Items 6 S→·E @1 E→·E+E @1 E→·int @1
Background image of page 19

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

View Full DocumentRight Arrow Icon
SCAN PREDICT COMPLETE Earley in Action S → E E → E + E E → int + int + int int Items 1 Items 2 Items 3
Background image of page 20
Image of page 21
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 07/18/2011.

Page1 / 275

070_Advanced_Parsing - Advanced Parsing Techniques...

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

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