EECS 395Programming LanguagesWinter 2010Instructor: Robby Findler1Course Detailshttp://www.eecs.northwestern.edu/~robby/courses/395-2010-winter/(or google “findler” and follow the links)2Programming Language ConceptsThis course teaches concepts in two ways:By implementing interpretersnew concept ! new interpreterBy using Scheme and variantswe don’t assume that you already know Scheme3Interpreters vs CompilersAn interpreter takes a program and produces a resultDrSchemex86 processordesktop calculatorbashAlgebra student4Interpreters vs CompilersAn interpreter takes a program and produces a resultDrSchemex86 processordesktop calculatorbashAlgebra studentA compiler takes a program and produces a programDrSchemex86 processorgccjavac5Interpreters vs CompilersAn interpreter takes a program and produces a resultGood for understandingprogram behavior, easyto implementDrSchemex86 processordesktop calculatorbashAlgebra studentA compiler takes a program and produces a programGood for speed, morecomplex (come backnext quarter)DrSchemex86 processorgccjavac6Interpreters vs CompilersAn interpreter takes a program and produces a resultGood for understandingprogram behavior, easyto implementDrSchemex86 processordesktop calculatorbashAlgebra studentA compiler takes a program and produces a programGood for speed, morecomplex (come backnext quarter)DrSchemex86 processorgccjavacSo, what’s a program?7A Grammar for Algebra ProgramsA grammar of Algebra in BNF (Backus-Naur Form):prog ::= defn* exprdefn ::= id(id) = exprexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numid ::= a variable name: f, x, y, z, ...num ::= a number: 1, 42, 17, ...8A Grammar for Algebra ProgramsA grammar of Algebra in BNF (Backus-Naur Form):prog ::= defn* exprdefn ::= id(id) = exprexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numid ::= a variable name: f, x, y, z, ...num ::= a number: 1, 42, 17, ...Each meta-variable, such as prog, defines a set9Using a BNF Grammarid ::= a variable name: f, x, y, z, ...num ::= a number: 1, 42, 17, ...The set id is the set of all variable namesThe set num is the set of all numbers10Using a BNF Grammarid ::= a variable name: f, x, y, z, ...num ::= a number: 1, 42, 17, ...The set id is the set of all variable namesThe set num is the set of all numbersTo make an example member of num, simply pickan element from the set11Using a BNF Grammarid ::= a variable name: f, x, y, z, ...num ::= a number: 1, 42, 17, ...The set id is the set of all variable namesThe set num is the set of all numbersTo make an example member of num, simply pickan element from the set2 " num298 " num12Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numThe set expr is defined in terms of other sets13Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variablecombine the examples with literal text14Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variablecombine the examples with literal text15Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variable7 " numcombine the examples with literal text16Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variable7 " numcombine the examples with literal text7 " expr17Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variablecombine the examples with literal text18Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variablef " idcombine the examples with literal text19Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variablef " id 7 " exprcombine the examples with literal text20Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variablef " id 7 " exprcombine the examples with literal textf(7) " expr21Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variablef " id f(7) " exprcombine the examples with literal text22Using a BNF Grammarexpr ::= (expr + expr)| (expr - expr)| id(expr)| id| numTo make an example expr:choose one case in the grammarpick an example for each meta-variablef " id f(7) " exprcombine the examples with literal textf(f(7)) " expr23Using a BNF Grammarprog ::= defn* exprdefn ::= id(id) = exprf(x) = (x + 1) " defn24Using a BNF Grammarprog ::= defn* exprdefn ::= id(id) = exprf(x) = (x + 1) " defnTo make a prog pick some number of defns(x + y) " progf(x) = (x + 1)g(y) = f((y - 2))g(7) " prog25Programming LanguageA programming language is defined by• a grammar for programs• rules for evaluating any program to produce
View Full Document