Chapter 2: Introduction to compilers

What are Compilers?

Compiler is a program which translates a program written in one language (the source language) to an equivalent program in other language (the target language). Usually the source language is a high level language like Java, C, Fortran etc. whereas the target language is machine code or "code" that a computer's processor understands. The source language is optimized for humans. It is more user-friendly, to some extent platform-independent. They are easier to read, write, and maintain and hence it is easy to avoid errors. Ultimately, programs written in a high-level language must be translated into machine language by a compiler. The target machine language is efficient for hardware but lacks readability.

Compilers

. Translates from one representation of the program to another

. Typically from high level source code to low level machine code or object code

. Source code is normally optimized for human readability

- Expressive: matches our notion of languages (and application?!)

- Redundant to help avoid programming errors

. Machine code is optimized for hardware

- Redundancy is reduced

- Information about the intent is lost