10.4 Preliminaries: Interpreter Essentials

Building an interpreter for a computer language involves defining the following elements:

  1. A Read-Eval-Print Loop (REPL): a user interface that reads program strings and passes them to the front end of the interpreter

  2. A Front End: a source code parser that translates a string representing a program into an abstract-syntax representation—usually a tree—of the program, sometimes referred to as bytecode

  3. An Interpreter:1 an expression evaluation function or loop that traverses and interprets an abstract-syntax representation of the program

  4. Supporting Data Types/Structures and Libraries: a suite of abstract data types (e.g., an environment, closure, and reference) and associated functions to support the evaluation of expressions

We present each of the first three of these components in Section 10.6. We first encounter the need for supporting data types (in this case, an environment) and libraries in Section 10.7.

10.4.1 Expressed Values Vis-à-Vis Denoted Values

The set of values that a programming language manipulates fall into two categories:

  • Expressed values are the possible (return) values of expressions (e.g., numbers, characters, and strings in Java or Scheme)

  • Denoted values are values bound to variables (e.g., references to locations containing expressed values in Java or Scheme)

10.4.2 Defined Language Vis-à-Vis Defining Language

When building an interpreter, we think of two languages:

  • The defined programming language (or source language) is the language specified (or operationalized) by the interpreter.

  • The defining programming language (or host language) is the language in which we implement the interpreter (for the defined language).

Here, our defined language is Camille and our defining language is Python.

1. The component of a language implementation that accepts an abstract-syntax tree and evaluates it is called an interpreter—see Chapter 4 and the rightmost component labeled “Interpreter” in Figure 10.1. However, we generally refer to the entire language implementation as the interpreter. To the programmer of the source program being interpreted, the entire language implementation (Figure 4.1) is the interpreter rather than just the last component of it.

A flow diagram of execution by interpretation.

Figure 10.1 Execution by interpretation.

Description
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.144.228