Com S 641 meeting -*- Outline -*- * core imperative language (Schmidt 1.1) ------------------------------------------ CORE OF A PROGRAMMING LANGUAGE def: the *core* of a programming language Examples: ------------------------------------------ ... is the values and operations that establish its fundamental capabilities (a collection of ADTs) e.g., core of SNOBOL is strings and pattern matching core of APL is array manipulation Q: What's the core of Haskell? C? Q: What's the goal in designing the core for a general purpose language? ------------------------------------------ SCHMIDT'S DESIGN METHOD 1. Start with 2. ------------------------------------------ ... designing the core What are its computational powers? What can't it do? ... then add conveniences as needed (naming, parameters, ...) this is where most of the book will focus ** core imperative language (1.1) *** abstract syntax ------------------------------------------ CORE IMPERATIVE LANGUAGE (1.1) (While0) Abstract Syntax: C \in Command E \in Expression L \in Location N \in Numeral C ::= L := E | skip | C1 ; C2 | if E then C1 else C2 fi | while E do C od E ::= N | @L | E1 + E2 | not E | E1 = E2 L ::= loc , if i > 0 i N ::= n, if n \in Integer Examples: ------------------------------------------ Explain: syntactic domains Q: Why separate a language into different syntactic domains? different concepts, avoids silly programs... Notation: nontermials (capitals, possibly subscripted. Locations are really addresses of memory cells, numbers! explain what this is supposed to mean Q: Can you give some examples? use parens when needed to disambiguate. Q: How would you model this in Haskell? ------------------------------------------ HASKELL MODEL OF SYNTAX type C = data Command = data Location = Loc Integer type Numeral = Integer Examples: ------------------------------------------ > -- helpful notationally > infixr `Semi` > type C = Command > type E = Expression > type L = Location > type N = Numeral > > data Command = L `Assign` E | Skip > | C `Semi` C | If E C C > | While E C > data Expression = Num N | Deref L > | E `Plus` E > | Not E | E `Equals` E > data Location = Loc Integer > type Numeral = Integer Q: Can you give the examples in the Haskell notation? Q: What are the differences between the Haskell and the standard notation? - C \in Command in standard C = Command in Haskell really the Haskell is better here, because C plays the role of a nonterminal here - no subscripts, although we could write type C1 = Command - note that the role of loc is clarified as a constructor this is an example of what Sussman calls "procedural epistimology"... *** abstract vs. concrete syntax ------------------------------------------ ABSTRACT vs. CONCRETE SYNTAX def: *abstract syntax* describes def: *concrete syntax* describes ------------------------------------------ ... the parse trees of a language, typically without a lot of keywords, needs at least one per construct ... the form of programs typed by users. it contains enough information for parsing we'll always focus on the abstract syntax, parsing is well-understood, problem is to give meaning to the parse trees... show the parser for the concrete syntax and how it relates