Introduction

ICS 40: Compiler Design Principles

     This subject is an introduction to the design and implementation of high-level programming language translators and compilers. It will open with a discussion of translators related to compilers, followed by an overview of the phases and data structures involved in compilation. Topics including lexical analysis, parsing techniques, symbol tables, run-time storage allocation, semantic routines, code generation, and optimization will then be covered with a series of projects assigned to illustrate practical issues.

from http://courseweb.xu.edu.ph/courses/ics40/

Tuesday, June 24, 2008

Phases of a Compiler



A compiler is a computer program (or set of programs) that translates text written in a computer language (the source language) into another computer language (the target language). The original sequence is usually called the source code and the output called object code. Commonly the output has a form suitable for processing by other programs (e.g., a linker), but it may be a human-readable text file.[1] There are six (6) Phases of a Compiler and these are:


1. Lexical Analyzer


- converts a sequence of characters into a sequence of tokens. Programs performing lexical analysis are called lexical analyzers or lexers. A lexer is often organized as separate scanner and tokenizer functions, though the boundaries may not be clearly defined.[2]


2. Syntax Analyzer


- checks that something conforms to the rules of a given syntax and analysing its structure according to those rules.[3]


3. Semantic Analyzer


- checks the source program for semantic errors and gathers type information for the subsequent code-generation phase.[4]



4. Intermediate Code Generator


- is generated as a program for an abstract machine. It helps to easily translate into the target program. We consider the three-address code, similar to assembly.[5]


5. Code Optimizer


- attempts to improve the intermediate code, so that faster-running machine code will result.[6]


6. Code Generator


- is the process by which a compiler's code generator converts some internal representation of source code into a form (e.g., machine code) that can be readily executed by a machine (often a computer).[7]





No comments: