UP | HOME

Compilers

1. Compiler Example

2. Modern Compilers

3. How compilers handle procedure calls

4. Contrast with interpreters

In an interpreted language, we have a hard to program machine M1. For example, maybe M1 only takes Assembly. We write a program to simulate an easier to program machine M2. Commands are given to the program which interprets the commands.

In a compiled language, we write programs for M2, which are compiled into equivalent programs for M1.

For example, an interpreter for Pascal, written in Python may:

  • Parse programs using recursive descent into Abstract Syntax Trees
  • Use an interpreter to evaluate these trees
  • Store and load variables in a symbol table. Scopes are handled by a scoped symbol table
  • To handle procedure calls, keep a stack of activation records

5. Sources

Created: 2024-07-15 Mon 01:28