Abstract
The simplest way to execute a program is interpretation. Interpretation is done by a program call ed an interpreter, which takes the abstract syntax tree of a program and executes it by inspecting the syntax tree to see what needs to be done. This is similar to how a human evaluates a mathematical expression: We insert the values of variables in the expression and evaluate it bit by bit, starting with the innermost parentheses and moving out until we have the result of the expression. We can then repeat the process with other values for the variables. There are some differences, however. Where a human being will copy the text of the formula with variables replaced by values, and then write a sequence of more and more reduced copies of a formula until it is reduced to a single value, an interpreter will keep the formula (or, rather, the abstract syntax tree of an expression) unchanged and use a symbol table to keep track of the values of variables. Instead of reducing a formula, the interpreter is a function that takes an abstract syntax tree and a symbol table as arguments and returns the value of the expression represented by the abstract syntax tree. The function can call itself recursively on parts of the abstract syntax tree to find the values of subexpressions, and when it evaluates a variable, it can look its value up in the symbol table. This process can be extended to also handle statements and declarations, but the basic idea is the same: A function takes the abstract syntax tree of the program and, possibly, some extra information about the context (such as a symbol table or the input to the program) and returns the output of the program.
Any good software engineer will tell you that a compiler and an interpreter are interchangeable.
Tim Berners-Lee (1955)
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
Abelson, H., Sussman, G.J., Sussman, J.: Structure and Interpretation of Computer Programs. MIT Press (1996). http://mitpress.mit.edu/sicp/full-text/sicp/book/
Steele, G.L., Sussman, G.J.: The Art of the Interpreter or, The Modularity Complex. Technical Report AIM-453, Massachusetts Institute of Technology, Cambridge, MA, USA (1978)
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
Copyright information
© 2017 Springer International Publishing AG
About this chapter
Cite this chapter
Mogensen, T. (2017). Interpretation. In: Introduction to Compiler Design. Undergraduate Topics in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-319-66966-3_4
Download citation
DOI: https://doi.org/10.1007/978-3-319-66966-3_4
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-66965-6
Online ISBN: 978-3-319-66966-3
eBook Packages: Computer ScienceComputer Science (R0)