Unformatted text preview: spot – Powerful enough to describe nGrossman
Dan esQng, recursion Dan Grossmansome more general grammars – But easy to parse, unlike Fall 2011 • Not perfect Fall 2011 – Cannot capture semanQcs, as in “variable must be declared” – Can be ambiguous – i.e., mulQple ways to derive a string, which may lead to diﬀerent “meanings” (e.g., order of operaQon) Winter 2013 UW CSE 401 (Michael Ringenburg) 32 Context Free Grammars CSE341: Programming Languages CSE341: grammar G is Languages
• Formally, a Programming a tuple <N,Σ,P,S> where Lecture 1 L ymbols – N a ﬁnite set of non terminal secture 1
C ymbols C et of t Mechanics
– Σ a ﬁnite sourseerminal sourse Mechanics
ML Variable Bindings
ML Variable Bindings
– P a ﬁnite set of producQons • A subset of N × (N ∪ Σ )*, i.e., a non terminal right Dan Grossman
Dan Grossman
hand side, and zero or more terminals and non Fall 2011
Fall 2011
terminals on the leg hand side. – S the start symbol, a disQnguished element of N • If not speciﬁed otherwise, this is usually assumed to be the non terminal on the leg of the ﬁrst producQon Winter 2013 UW CSE 401 (Michael Ringenburg) 33 Standard NotaQons CSE341: Programming
CSE341: Programming Languages Languages •
•
•
•
•
• a, b, c elements of Σ (terminals) 1
Lecture 1 Lecture
Course Mechanics
w, x, y, z Course Mechanics elements of Σ* (terminal strings) ML Variable Bindings
ML Variable Bindings
A, B, C elements of N (nonterminals) an Grossman
Dan of N (
X, Y, Z elements GrossmanΣ Dterminals or nonterms) ∪
Fall 2011
Fall
α, β, γ elements o2011 ∪ Σ )* (term/nonterm strings) f (N A α or A ::= α if <A, α> in P (producQons) Winter 2013 UW CSE 401 (Michael Ringenburg) 34 DerivaQon RelaQons (1) CSE341: Programming
CSE341: Programming Languages Languages • α A γ => α β γ iﬀ A ::= β in P Lecture 1 Lecture 1
Course
Course Mechanics Mechanics
ML Variable ro...
View
Full Document
 Winter '09
 Computer Programming, Contextfree grammar, Dan Grossman Dan Grossman

Click to edit the document details