Showing posts with label Compiler. Show all posts
Showing posts with label Compiler. Show all posts

Tuesday, October 11, 2011

What are Compilers?

A compiler is a program that reads a program in one language, the source language and translates into an equivalent program in another language, the target language.
The translation process should also report the presence of errors in the source program.

Source Program CompilerTarget Program


Error Messages

There are two parts of compilation.
The analysis part breaks up the source program into constant piece and creates an intermediate representation of the source program.
The synthesis part constructs the desired target program from the intermediate representation.
Phases of Compiler
The compiler has a number of phases plus symbol table manager and an error handler.
  




Input Source Program
Lexical Analyzer
Syntax Analyzer
Symbol Table ManagerSemantic Analyzer Error Handler
Intermediate Code Generator
Code Optimizer
Code Generator




Out Target Program
The cousins of the compiler are
  1. Preprocessor.
  2. Assembler.
  3. Loader and Link-editor.
Front End vs Back End of a Compilers. The phases of a compiler are collected into front end and back end.
The front end includes all analysis phases end the intermediate code generator.
The back end includes the code optimization phase and final code generation phase.
The front end analyzes the source program and produces intermediate code while the back end synthesizes the target program from the intermediate code.
A naive approach (front force) to that front end might run the phases serially.
  1. Lexical analyzer takes the source program as an input and produces a long string of tokens.
  2. Syntax Analyzer takes an out of lexical analyzer and produces a large tree.
  3. Semantic analyzer takes the output of syntax analyzer and produces another tree.
  4. Similarly, intermediate code generator takes a tree as an input produced by semantic analyzer and produces  intermediate code.
Minus Points
  • Requires enormous amount of space to store tokens and trees.
  • Very slow since each phase would have to input and output to and from temporary disk
Remedy
  • use syntax directed translation to inter leaves the actions of phases.
  • Compiler construction tools.
Parser Generators:
The specification of input based on regular expression. The organization is based on finite automation.
Scanner Generator:
The specification of input based on regular expression. The organization is based on finite automation.
Syntax-Directed Translation:
It walks the parse tee and as a result generate intermediate code.
Automatic Code Generators:
Translates intermediate rampage  into machine language.
Data-Flow Engines:
It does code optimization using data-flow analysis.

Friday, April 29, 2011

Introduction of Compilers


compiler is a computer program (or set of programs) that transforms source code written in a programming language(the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for wanting to transform source code is to create an executable program.
The name "compiler" is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language or machine code). If the compiled program can run on a computer whose CPU or operating system is different from the one on which the compiler runs, the compiler is known as a cross-compiler. A program that translates from a low level language to a higher level one is a decompiler. A program that translates between high-level languages is usually called a language translatorsource to source translator, or language converter. A language rewriter is usually a program that translates the form of expressions without a change of language.
A compiler is likely to perform many or all of the following operations: lexical analysis, preprocessing, parsing, semantic analysis (Syntax-directed translation), code generation, and code optimization.
Program faults caused by incorrect compiler behavior can be very difficult to track down and work around; therefore, compiler implementors invest a lot of time ensuring the correctness of their software.
The term compiler-compiler is sometimes used to refer to a parser generator, a tool often used to help create the lexerand parser.