Sie sind auf Seite 1von 24

Compilers

LANGUAGE PROCESSING SYSTEM


Preprocessor
A preprocessor produce input to compilers. They may perform the
following functions.

● Macro processing: A preprocessor may allow a user to define macros


that are short hands for longer constructs.
● File inclusion: A preprocessor may include header files into the
program text.
● Rational preprocessor: these preprocessors augment older languages
with more modern flow-of-control and data structuring facilities.
● Language Extensions: These preprocessor attempts to add
capabilities to the language by certain amounts to build-in macro
Compiler
Compiler is a translator program that translates a program written in
(HLL) the source program and translate it into an equivalent program
in (MLL) the target program.

Source Target
Pgm Pgm
Compiler

Error
Message
Interpreter
An Interpreter directly executes instructions written in a
programming or scripting language without previously converting
them to an object code or machine code.

Examples of interpreted languages are Perl, Python and Matlab


Assembler
An assembler is a type of computer program that interprets software
programs written in assembly language into machine language, code
and instructions that can be executed by a computer.

An assembler is sometimes referred to as the compiler of assembly


language.
Linker/Loader
● Linker intakes the object codes generated by the assembler and
combine them to generate the executable module.
● Loader loads this executable module to the main memory for
execution.
Phases of a Compiler

Error Handler
Translation of a statement
THE GROUPING OF PHASES
● Each phases deals with the logical organization of a compiler.
● Activities of several phases may be grouped together into a pass that reads an
input file and writes an output file.
● The front-end phases of lexical analysis, syntax analysis, semantic analysis, and
intermediate code generation might be grouped together into one pass.
● Code optimization might be an optional pass.
● A back end pass consisting of code generation for a particular target machine.
Compiler Construction Tools
● Scanner generators [Lexical Analysis]

● Parser generators [Syntax Analysis]

● Syntax-directed translation engines [Intermediate Code]

● Data-flow analysis engines [Code Optimization]

● Code-generator generators [Code Generation]

● Compiler-construction toolkits [For all phases]


Scanner Generators
● Scanner generators that produce lexical analyzers from a regular-expression
description of the tokens of a language.

● Unix has a tool for Scanner generator called LEX.


Parser Generators
● Parser generators automatically produce syntax analyzers (parse tree) from a
grammatical description of a programming language.

● Unix has a tool called YACC which is a parser generator.


Syntax - Directed Translation Engines
● Produces collections of routines for walking a parse tree and generating
intermediate code.

● It generates intermediate code with three address format from the input that
consists of a parse tree.

● Each node of the parse tree is associated with one or more translations.
Data - Flow Analysis Engines
● Data-flow analysis engines 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.


Code - Generator Generators
● Produces a code generator from a collection of rules for translating each
operation of the intermediate language into the machine language for a target
machine.

● Template matching process is used.

● An intermediate language statement is replaced by its equivalent machine


language statement using templates.
Compiler-Construction Toolkits

● Provides an integrated set of routines for constructing various phases of a


compiler
Lexical Analysis
● Lexical Analysis is the first phase of compiler. It reads the input characters
from left to right, one character at a time, from the source program.
Needs / Roles / Functions of lexical analyzer
● It produces stream of tokens.
● It eliminates comments and whitespace.
● It keeps track of line numbers.
● It reports the error encountered while generating tokens.
● It stores information about identifiers, keywords, constants
and so on into symbol table.
Input Buffering

Das könnte Ihnen auch gefallen