lecture-notes

lecture-notes - CMSC 22100/32100: Programming Languages...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 (Backus-Naur-Form), a.k.a. production rules , a.k.a. context-free grammar: e e 1 e e- e Here: e is a non-terminal symbol; , 1 , and- are terminal symbols. One of the non-terminals is the designated start symbol (so in our case it must be e since thats all weve got). The language is generated by taking the start symbols and repeatedly applying one of the production rules, replacing its non-terminal on the left with the corresponding right-hand side. The language is defined to be the set of strings of terminal symbols (non non-terminals!) 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 meta-variables 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 meta-variables) that can be obtained by substituting actual (ground) terms for all meta-variables. 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

Page1 / 57

lecture-notes - CMSC 22100/32100: Programming Languages...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online