Programming Languages: Chapter 4: Programming Language Implementation



Interpretation

  • preprocessing (purges comments)
  • lexical analysis (scanning)
  • syntax analysis (parsing)
  • semantic analysis


Alternative View of Interpretation


Compilation


Low-level view of execution by compilation


Compiler vs. interpreter

  • both compilers and interpreters have a front end which consists of a scanner (lexical analyzer) and parser (syntactic analyzer)

  • compiler
    • a compiler is a program which translates a program in one language (the source language) to an equivalent program in another language (the target language)
    • a compiler is just a translator, nothing more
    • advantages to compilation:
      • fast execution: generates machine code which executes fast
      • compile once, execute multiple times
    • disadvantages to compilation:
      • slow development: vicious compile-run-debug-re-compile cycle
      • less flexibility: most choices in a program are fixed at compile-time (e.g., size of an array)

  • an interpreter is a software simulation of machine which natively (i.e., no translation involved) understands instructions in the source language [COPL6]
  • an interpreter provides a virtual machine for a programming language
    • advantages to interpretation:
      • interpreters provide direct support for source-level debugging (e.g., consider a run-time array out-of-bounds error)
      • interpreters lend themselves to late binding
        • dynamic typing (based on run-time data)
        • programming on-the-fly and then interpreting the code at run-time
    • disadvantages to interpretation:
      • slow: decoding high-level expressions (which are more complex than machine instructions) is the bottleneck as opposed to pipeline between the processor and memory [COPL6]
      • source program usually occupies more space (i.e., program manipulated by the interpreter is often stored in a representation which makes interpretation convenient and this representation is typically not of minimal size)

  • hybrid (compilation-interpretation) systems: Perl, Java; why?


References

    [COPL6] R.W. Sebesta. Concepts of Programming Languages. Addison-Wesley, Boston, MA, Sixth edition, 2003.

Return Home