Thursday, 24 October 2013

COMPILER DESIGN

Compiler Design:
       
        A Compiler is a computer program that transform source code written in a programming language into another computer language.The reason for wanting transform source code is to create an Executable program.

Structure Of a Compiler:

Compilers bridge source programs in high-level languages with the underlying hardware.

A compiler requires

     1. determining the correctness of the syntax of programs.

     2. generating correct and efficient object code.

     3. run-time organization.

     4. formatting output according to assembler and/or linker conventions.

 A compiler consists of three main parts:

        The frontend

        The middle-end

        The backend.
   
             The Front end checks whether the program is correctly written in terms of the programming language syntax and semantics. Here legal and illegal programs are recognized. Errors are reported, if any, in a useful way. Type checking is also performed by collecting type information.The frontend then generates an intermediate representation or IR of the source code for processing by the middle-end.

             The Middle end is where optimization takes place. Typical transformations for optimization are removal of useless or unreachable code, discovery and propagation of constant values, relocation of computation to a less frequently executed place (e.g., out of a loop), or specialization of computation based on the context. The middle-end generates another IR for the following backend. Most optimization efforts are focused on this part.

              The Back end is responsible for translating the IR from the middle-end into assembly code. The target instructions are chosen for each IR instruction.
Register allocation assigns processor registers for the program variables where possible. The backend utilizes the hardware by figuring out how to keep parallel execution units busy, filling delay slots, and so on. Although most algorithms for optimization are in NP, heuristic techniques are well-developed.

There are two major parts of a compiler:

         1.Analysis 

        2.Synthesis

In analysis phase, an intermediate representation is created from the given source program.

Lexical Analyzer, Syntax Analyzer and Semantic Analyzer are the parts of this phase.

In synthesis phase, the equivalent target program is created from this intermediate representation.

Intermediate Code Generator, Code Generator, and Code Optimizer are the parts of this phase.


PARSER:

    In computer technology, a parser is a program, usually part of a compiler, that receives input in the form of sequential source program instructions, interactive online commands, markup tags, or some other defined interface and breaks them up into parts (for example, the nouns (objects), verbs (methods), and their attributes or options) that can then be managed by other programming (for example, other components in a compiler).

 A parser may also check to see that all input has been provided that is necessary.

Lexical Analysis:

        It is a Process of converting sequence of characters into sequence of Tokens.

Syntactic Analysis:

        The process of analyzing a sequence of tokens to determine its grammatical structure.

Syntax errors are identified during this stage.

Symantic analysis:

        The Process of analyzing semantic cheeks(ex:Type checking,Object Binding).

Compiler Optimization:

        This Process tune the output of a compiler to minimize or maximize some attributes of an executable computer program.

Code generator:
        It will convert the intermediate files into assembly language programs.