Skip to main content

Interpretation

  • Chapter
  • First Online:
Introduction to Compiler Design

Part of the book series: Undergraduate Topics in Computer Science ((UTICS))

  • 4117 Accesses

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)

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. 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/

  2. 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)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Torben Ægidius Mogensen .

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics