0% found this document useful (0 votes)
88 views11 pages

Compiler Design: - Language Processor - Language Processing System - Phases of Compiler

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 11

COMPILER DESIGN

• Language Processor

• Language Processing System

• Phases Of Compiler
Language Processors
Language Translators
• Computer program which translates a program
written in one (Source) language to its equivalent
program in their[Target]language
• The Source program is a high level language
where as the Target language can be any thing
from the machine language of a target machine
Two commonly Used Translators are
1. Compiler
2. Interpreter
Compiler
• Compiler is a program, reads program in one language
called Source Language and translates in to its equivalent
program in another Language called Target Language.

There are many different types of compilers which produce output in different useful
forms.
• A cross-compiler produces code for a different CPU or operating system than the one
on which the cross-compiler itself runs.
• A bootstrap compiler is often a temporary compiler, used for compiling a more
permanent or better optimised compiler for a language.
Interpreter

1. Interpreter is a computer program that directly executes instructions


written in a programming or scripting language, without requiring them
previously to have been compiled into a machine language program.

2. An interpreter generally uses one of the following strategies for program execution:
• Parse the source code and perform its behaviour directly;
• Translate source code into some efficient intermediate representation or object code
and immediately execute that;
• Explicitly execute stored precompiled bytecode[1] made by a compiler and matched
with the interpreter Virtual Machine.
3. If an error occurs, interpreters will stop execution
Preprocessor
Collects all the modules, files in case if the source program is divided into different
modules stored at different files

Compiler
Translator that takes as input a source program written in high level language and
converts it into its equivalent target program in machine language

Assembler
Is a program that takes as input an assembly language program and converts it into
its equivalent machine language code

Linker
used to link all the parts of the program together for execution
Program that takes as input a relocatable code and collects the library functions,
relocatable object files, and produces its equivalent absolute machine code

Loading
Consists of taking the relocatable machine code, altering the relocatable addresses,
and placing the altered instructions and data in memory at the proper locations

Linking
It makes a single program from several files of relocatable machine code
Language Processing System

Preprocessor
Compiler
Assembler
Loader / Linker
Linking
Loading
The steps involved in a typical language processing system
Lexical Analyser
• uses finite state automata
• The First phase of a compiler is called lexical analysis or scanning
• Reads the stream of characters making up the source program and groups the characters into
meaningful sequences called lexemes
• Lexical analyser produces as output a token of the form
<token-name; attribute-value>
• In the token, the First component token-name is an abstract symbol that is used during syntax
analysis, and the second component attribute-value points to an entry in the symbol table for this
token

Syntax Analyser
• The second phase of the compiler is syntax analysis or parsing. The parser uses the First
components of the tokens produced by the lexical analyser to create a tree-like intermediate
representation that depicts the grammatical structure of the token stream.

Semantic Analyser
• The semantic analyser uses the syntax tree and the information in the symbol table to check the
source program for semantic consistency with the language definition.
• It also gathers type information and saves it in either the syntax tree or the symbol table, for
subsequent use during intermediate-code generation
• An important part of semantic analysis is type checking, where the compiler checks that each
operator has matching operands
• The language specification may permit some type conversions called coercions
Intermediate Code Generator
• In the process of translating a source program into target code, a compiler may
construct one or more intermediate representations, which can have a variety of forms.
• Syntax trees are a form of intermediate representation; they are commonly used during
syntax and semantic analysis.
• This intermediate representation should have two important properties:
• It should be easy to produce and
• It should be easy to translate into the target machine.

Code Optimization
• The machine-independent code-optimization phase attempts to improve the
intermediate code so that better target code will result.
• A simple intermediate code generation algorithm followed by code optimization is a
reasonable way to generate good target code

Code Generator
• The code generator takes as input an intermediate representation of the source program
and maps it into the target language
• A crucial aspect of code generation is the judicious assignment of registers to hold
variables
• Important issue of storage allocation for the identifiers in the source program
Symbol Table Management
• The symbol table is a data structure containing a record for each variable name, with
fields for the attributes of the name. The data structure should be designed to allow
the compiler to find the record for each name quickly and to
store or retrieve data from that record quickly

Grouping of Phases into Passes


• In an implementation, activities from several phases may be grouped together into a
pass that reads an input file and writes an output file.

Compiler Control Tools


• Tools have been created to help implement various phases of a compiler. These tools
use specialized languages for specifying and implementing specific components, and
many use quite sophisticated algorithms
Phases Of Compiler
Some commonly used compiler-construction tools include:

1. Parser generators that automatically produce syntax analysers from a


grammatical description of a programming language.
2. Scanner generators that produce lexical analysers from a regular-expression
description of the tokens of a language.
3. Syntax-directed translation engines that produce collections of routines for
walking a parse tree and generating intermediate code.
4. Code-generator generators that produce a code generator from a collection
of rules for translating each operation of the intermediate language into the
machine language for a target machine.
5. Data- flow analysis engines that facilitate the gathering of information about
how values are transmitted from one part of a program to each other part.
Data- flow analysis is a key part of code optimization.
6. Compiler-construction toolkits that provide an integrated set of routines for
constructing various phases of a compiler.
We shall describe many of these tools in the next

You might also like