
Language Components
General Assertions
Specifications in EOPL consist of assertions of the form (value-of *exp* ρ) = *val,* meaning that the value of expression exp in environment ρ should be val.
Organization
- We start with the text of the program written in the language we are implementing.
This is called the source language or the defined language.
- Program text (a program in the source language) is passed through a front end that converts it to an abstract syntax tree.
- The syntax tree is then passed to the interpreter, which is a program that looks at a data structure and performs some actions that depend on its structure. Of course the interpreter is itself written in some language. We call that language the implementation language or the defining language.
Front-end
No matter what implementation strategy we use, we need a front end that converts programs into abstract syntax trees. The standard approach to building a front end is to use a parser generator. A parser generator is a program that takes as input a lexical specification and a grammar, and produces as output a scanner and parser for them.
- Scanning: Process of dividing the sequence of characters into words, numbers, punctuation, comments, and the like. These units are called lexical items, lexemes, or most often tokens. We refer to the way in which a program should be divided up into tokens as the lexical specification of the language. The scanner takes a sequence of characters and produces a sequence of tokens.
- Parsing: Process of organizing the sequence of tokens into hierarchical syntactic structures such as expressions, statements, and blocks. This is like organizing (diagramming) a sentence into clauses. We refer to this as the syntactic or grammatical structure of the language. The parser takes a sequence of tokens from the scanner and produces an abstract syntax tree.
Specification
- Data Representation: Specifying how the data is represented
Types of Specifications
- Grammar Specification: Specifying inductive/recursive sets of data
- Interface Specification: Specifying constructors and observers (predicates, extractors, etc.) for data
- Behavioral Specification: Showing behavior using Rules of Inference
- Equational Specification: Showing the equational representation of behavior
What to specify?