Compiler Design

 

 

What is Compiler

       
     Compiler is a program which takes one language (source program) as input and translates it into an equivalent another language (target program).

                   During this process of translation if some errors are encountered then compiler displays them as error messages, The basic model of compiler can be represented as follows.
 
compiler
 
The compiler takes a source program such as higher level languages such as C, PASCAL. FORTRAN and converts it into low level language or a machine level language such as assembly language.
 

 

Structure of Compiler

The compilation can be done in two parts : Analysis and synthesis, In analysis part the source program is read and broken down into constituent pieces, The syntax and the meaning of the source string is detenruned and then an intermediate code is created from the input source program. In synthesis put this internediate form of the source language is taken and converted into an equivalent target program.                        
 
                                                                                                                                                                Read More
 

Properties of Compiler

When compiler is built it should possess following properties .
1. The compiler itself  must be bug free.
2. It must generate correct machine code.
3. The generated machine code must run fast.
4. The compiler itself must run fast (compilation time must be proportional to program size).
5. The compiler must be portable (i.e. modular supporting separate compilation).
6. It must give good diagnostics and error messages.
7. The generated code must work well with existing debuggers.
8. It must have consistent optimization.

 

Analysis of Source Program
 
The source program can be analysed in three phases .
1) Linear  Analysis. : In this type of analysis the source string is read from left to right and grouped into tokens. For example· Tokens for a language can be identifiers, constants, relational operators, keywords.
2) Hierarchical Analysis : In this analysis, characters or tokens are grouped hierarchically into nested collections for checking them syntactically.
3) Semantic Analysis: This kind  of anaIysis ensures the correctness of meaning of the program.
 
 
Context-free Grammer
  • A context-free grammar for a language specifies the syntactic structure of programs in that language
  • Components of a grammar:
    • a finite set of tokens (obtained from the scanner);

 

                               Read More

 

Parsers

  • Accepts string of tokens from lexical analyzer (usually one token at a time)
     
  • Verifies whether or not string can be generated by grammar
                                                                                                                             Read More