G e e f for leg associaqve addiqon winter 2013 uw

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: legmost ecture 1 Lecture 1 L (or rightmost) derivaQon C nique –  Fact: unique legmost or uourserightmost implies the Course Mechanics Mechanics other ML Variable Bindings ML Variable Bindings •  A grammar without this property is ambiguous Dan Grossman Dan Grossman –  Note that other grammars that generate the same F language may be allnambiguous all 2011 F u 2011 •  We need unambiguous grammars for parsing –  The derivaQon determines the shape of the parse tree/ abstract syntax tree, which in turn determines meaning. Winter 2013 UW CSE 401 (Michael Ringenburg) 39 Example: Ambiguous Grammar for ArithmeQc Expressions CSE341: Programming CSE341: Programming Languages Languages expr ::= expr + expr | expr - expr | expr * eLecturexpr / expr | 1nt xpr | e 1 Lecture i Course Course Mechanics Mechanics int ::= 0M 1Variable | 4 | 5 | 6 |Bindings 9 |L | 2 | 3 Bindings 7 | 8 | ML Variable •  Exercise: show that this Ds ambiguous ian Grossman Dan Grossman –  How? Show tFall 2011 wo different Fegmost or rightmost l all 2011 derivaQons for the same string –  Equivalently: show two different parse trees for the same string Winter 2013 UW CSE 401 (Michael Ringenburg) 40 Exercise (cont) CSE341: Programming CSE341: Programming Languages Languages •  Give two different legmost derivaQons of 2+3*4 and show the parse tree 1 Lecture 1 Lecture Course Course Mechanics Mechanics ML Variable Bindings ML Variable Bindings Dan Grossman Fall 2011 Dan Grossman Fall 2011 expr ::= expr + expr | expr - expr | expr * expr | expr / expr | int int ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Winter 2013 UW CSE 401 (Michael Ringenburg) 41 Another exercise CSE341: Programming CSE341: Programming Languages Languages •  Give two different rightmost derivaQons of 5+6+7 Lecture 1 Lecture 1 Course Course Mechanics Mechanics ML Variable Bindings ML Variable Bindings Dan Grossman Fall 2011 Dan Grossman Fall 2011 expr ::...
View Full Document

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online