Prev Next

Programming Language Implementations [Chapter 2]

Compilers

A compiler translates from one language (the source language) to another (the target language). Often, the target language is an assembly language. C is also a common target language.

Interpreters

An interpreter performs instructions as it reads them. It does not do any translation.

Comparison of compilers and interpreters

  • Compilers produce more efficient programs. The overhead of running an interpreter is typically one to two orders of magnitude.

  • Compilers allow efficient chaining of translations: Translate from A to B, then from B to C, then from C to D, for example. If you do this with interpreters, the overhead factors multiply.

  • Compilers can typically do more error checking than interpreters.

  • A compiler does not need to be present when you run your program. You can sell a compiled program to someone who does not have a compiler, and you can run a compiled program on a machine that is too small to support a compiler (a toaster, for example).

  • Interpreters are more portable. The interpreter itself is usually portable, and programs can run on any machine that has the right interpreter.

  • Interpreters are often easier to use for debugging.

Hybrid implementations

Most interpreters actually use compilers to do part of the work.

  • A compiler translates into an abstract machine language, and the interpreter reads the instructions of the abstract machine language. This makes the whole process much more efficient.

  • A just-in-time compiler only compiles functions on a one-by-one basis. The interpreter compiles a function after that function has been used enough times to justify compiling. These are also called on-the-fly compilers.

Languages are not their implementations

A language implementation is a poor definition of a language.

  • Language implementations are difficult to read.

  • What if there is a mistake in the implementation?

  • A language implementation often needs to make choices that are intended to be arbitrary in the language definition. In C++, for example, expression f(A,B) allows subexpressions A and B to be computed in either order. (After computing them, the results of the computations must be passed to f in the order shown.)

  • A particular language implementation might give you the idea that the language is "efficient" or "inefficient". but another implementation of the same language might have very different characteristics.

Other aspects of programming language

A language implementation often has other tools associated with it. They are not part of the language itself, but certainly can make using the language easier.

  • Libraries (explicitly used by programs)
  • Run-time support (implicitly used by programs)
  • Integrated development environments (text editor, debugger, ...)
  • CASE tools (help to keep software, software requirements and tests organized; allow programmers to communicate with one another; help keep track of and build different versions)


Prev Next