CpS 450 Lecture Notes

Introduction to Compilers


And Ezra opened the book in the sight of all the people; (for he was above all the people;) and when he opened it, all the people stood up: .. Also Jeshua, and Bani, and Sherebiah, Jamin, Akkub, Shabbethai, Hodijah, Maaseiah, Kelita, Azariah, Jozabad, Hanan, Pelaiah, and the Levites, caused the people to understand the law: and the people stood in their place. So they read in the book in the law of God distinctly, [translating to give] the sense, and caused them to understand the reading.
Nehemiah 8:5-8


Definition

What is a compiler?

Best definition: Translator. Thus, the name of the course: Language Translation Systems

History

Related Programs

Operation

The translation process involves several steps (p. 7):

  1. Lexical analysis: Convert a stream of characters into a stream of tokens (lexical units). Performed by a scanner.

  2. Syntactic analysis: "Sentence Diagramming" - Verify that program is written according to language's grammar rules; may produce a tree data structure. Performed by a parser.

  3. Semantic analysis: Verify that the program is legal, collect certain information, decorate the tree

  4. Optimization: Remove unused subroutines, perform any constant arithmetic, etc.

  5. Code Generation: Generate code in the target language

Compiler Structure

Front End vs. Back End

The structure of a compiler can be divided into:

A cross-compiler is a compiler that produces target code for an architecture that is different than the architecture the compiler runs on.

Example: GCC

Single Pass vs. Multipass

A single pass compiler processes an input program in a single traversal.

A multipass compiler typically builds an intermediate representation (syntax tree or atoms) and makes several traversals / passes to produce the final target code.