This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CMSC 22100/32100: Programming Languages Lecture Notes M. Blume December 5, 2008 1 Introduction What are programming languages ? Languages: formal languages, i.e. , sets of strings Programming: languages with semantics 1.1 Languages as sets Example: difference terms: Three equivalent ways of defining the syntax of the language: Inductive definition: L is the smallest set such that: • ∈ L • 1 ∈ L • if e ∈ L and e ∈ L , then e e ∈ L Notice: juxtaposition of symbols (taken from the set { , 1 ,} ) is string concatenation , which is a monoid operation, meaning that among other things it is associative . BNF: definition using BNF (BackusNaurForm), a.k.a. production rules , a.k.a. “contextfree grammar”: e → e → 1 e → e e Here: e is a “nonterminal” symbol; , 1 , and are “terminal” symbols. One of the nonterminals is the designated “start” symbol (so in our case it must be e since that’s all we’ve got). The language is generated by taking the start symbols and repeatedly applying one of the production rules, replacing its nonterminal on the left with the corresponding righthand side. The language is defined to be the set of strings of terminal symbols (non nonterminals!) that can be generated in this fashion. 1 Frequently used alternative notation, which tends to be more compact: e ::=  1  e e (1) Inference rules: We use a judgment (a term encoding a relation, in this case a set) to characterize the expressions of the language. We want to be able to derive the judgment e exp if and only if s ∈ L where e encodes the string s. For the time being we will use strings directly, i.e. , we make e identical to s : exp zero 1 exp one e exp e exp e e exp minus Each inference rule has a name, written to its right, so we can refer to it later on. It consists of a horizontal line, separating the premises above from the conclusion below. Each premise and each conclusion is a term template , i.e. , a term possibly containing metavariables such as e and e above. A rule containing meta variables is a finite representation of the (usually infinite) family of ground rules (rules without metavariables) that can be obtained by substituting actual (ground) terms for all metavariables. A (ground) judgment A can be derived if there exists a set of rules where A is the conclusion of at least one rule, and where every premise in any of the rules is also the conclusion of some (other) rule. We can arrange this set of rules into a tree called the derivation tree or proof tree . Example: We can derive the judgment 1 1 exp as follows: 1 exp one exp zero 1 exp one 1 exp minus 1 1 exp minus Notice that, as we will see shortly, there is another possible derivation for the same judgment....
View
Full
Document
This note was uploaded on 10/10/2009 for the course CMSC 2210 taught by Professor Macqueen during the Fall '09 term at UChicago.
 Fall '09
 MacQueen

Click to edit the document details