But can sqll generate exact same language try it

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: ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Winter 2013 UW CSE 401 (Michael Ringenburg) 45 Check: Derive 5 + 6 + 7 CSE341: Programming CSE341: Programming vs right- recursive rules and •  Note interacQon between leg- Languages Languages resulQng associaQvity Lecture 1 Lecture 1 Course Course Mechanics Mechanics ML Variable Bindings ML Variable Bindings Dan Grossman Fall 2011 Dan Grossman Fall 2011 expr ::= expr + term | expr – term | term term ::= term * factor | term / factor | factor factor ::= int | ( expr ) int ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Winter 2013 UW CSE 401 (Michael Ringenburg) 46 Check: Derive 5 + (6 + 7) CSE341: Programming CSE341: Programming Languages Languages Lecture 1 Lecture 1 Course Course Mechanics Mechanics ML Variable Bindings ML Variable Bindings Dan Grossman Fall 2011 Dan Grossman Fall 2011 expr ::= expr + term | expr – term | term term ::= term * factor | term / factor | factor factor ::= int | ( expr ) int ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Winter 2013 UW CSE 401 (Michael Ringenburg) 47 Another Classic Example CSE341: Programming CSE341: Programming Languages Languages •  Grammar for condiQonal statements Lecture 1 Lecture 1 stmt ::= if ( cond ) stmtCourse Mechanics Course Mechanics | ML cond ) stmt L Variable Bindings if ( Variable Bindings M else stmt Dan Grossman Fall 2011 Dan Grossman –  Exercise: show that this is ambiguous Fall 2011 •  How? Winter 2013 UW CSE 401 (Michael Ringenburg) 48 Another Classic Example CSE341: Programming CSE341: Programming Languages Languages •  Grammar for condiQonal statements Lecture 1 Lecture 1 stmt ::= if ( cond ) stmtCourse Mechanics Course Mechanics | ML cond ) stmt L Variable Bindings if ( Variable Bindings M else stmt Dan Grossman Fall 2011 Dan Grossman –  Exercise: show that this is ambiguous Fall 2011 •  How? •  Hint: Consider if (Cond1) if (Cond2) Stmt1 else Stmt2 Winter 2013 UW CSE 401 (Michael Ringenburg) 49 Derive if(c1) if(c2) s1 else s2 CSE341: Programming CSE341: Programming Languages Languages Lecture 1 Lecture 1 Course Course Mechanics Mechanics ML Variable Bindings ML Variable Bindings Dan Grossman Fall 2011 Dan Grossman Fall 2011 stmt ::= if ( cond ) stmt | if ( cond ) stmt else stmt Winter 2013 UW CSE 401 (Michael Ringenburg) 50 Solvin...
View Full Document

Ask a homework question - tutors are online