Constructors and Selectors: - The constructors for lists include the 'list' and 'cons' systems discussed in the last lecture. They are the method for building a list. - The selectors for lists provide a method for getting at particular elements of a list. They include 'first' and 'rest'. first: returns the first element of a list, which is equivalent to the first argument of a cons constructed list. rest: returns everything but the first element of a list, which is equivalent to the second argument of a cons constructed list. e.g.: (first (cons x y)) --> x (rest (cons x y)) --> y (see DEMO for more examples) - Another list operation is 'append'. It concatenates, or joins, two lists into one, regardless of contents. (See Demos for examples). Abstract and Concrete Syntax: - Abstract syntax is how a language internal represents code, and can be thought of as a labelled tree (not necessary binary), e.g.: + / \ / \ * 7 represents the operation of multiplying 21 by 3 / \ and adding 7 to the product 21 3 - Concrete syntax is the string representation of abstract syntax and is the syntax presented to and input by the user. The abstract tree above becomes: "21 * 3 + 7" - The intermediary between abstract and concrete syntax is a list of tokens: e.g.: (list "21" "*" "3" "+" "7") Abstract Syntax in Scheme: - Consider the abstract syntax given by the tree label /|\ / | \ / | \ / | \ / | \ / | \ / | \ / | \ subtree1 subtree2 subtree3 The abstract representation is formed by taking each vertex of a tree and making a list of it followed by its subvertices. For the tree above, this becomes: (list label subtree1 subtree2 subtree3) where each subtree should be replaced by the abstract syntax representing it. For the tree from above + / \ / \ * 7 / \ 21 3 the abstract syntax is represented in Scheme by (list '+ (list '* 21 3) 7) NOTE: Symbols are indicated in the abstract syntax list by a preceding single quote ('). Parsing and Unparsing: - Unparsing is defined as the process of producing concrete syntax for a given abstract syntax (unparsing = abstract --> concrete). - Parsing is defined as the process of producing abstract syntax for a given concrete syntax (parsing = concrete --> abstract). Parsing is typically the process of interest for a programmer. Grammar: - See the 'Tangled Terminology' preface of Assignment #2 for a discussion of context-free grammars (CFGs).