Вы находитесь на странице: 1из 13

Language Processing = Analysis of Source

Program

+
Synthesis of Target
Program

ctd..

Language Processor
Source
Program

Analysis Phase

Synthesis
Phase

Errors

Errors

Target
Program

Analysis phase of Language processing

The specification consists of following


components

Lexical rules which govern the formation


of valid lexical units in the source language.

Syntax rules which govern the formation


of the valid statements in the source
language.

Semantic rules which associate meaning


with the valid statements of the language.

Analysis phase of Language processing

Accordingly, analysis phase of a language


processor subjects a statement to

Lexical Analysis
Syntax Analysis
Semantic Analysis

Example
Analysis of Source statement
consider the statement
percent_profit = (profit*100) / cost_price;
Lexical Analysis: identification of =,*, / as a operators
percent_profit ,profit and cost_price as a
identifiers
and 100 as a constant
Syntax Analysis: Reveals the statement to be an assignment
statement
with percent_profit as the variable on left
hand side
and (profit*100) / cost_price as the
expression of
right hand side
Semantic Analysis: Deduces the meaning of the statement to be

Synthesis phase of Language processing

The synthesis phase is concerned with the


construction of target language statement which
have same meaning as a source statement.
Typically it consists of two main tasks
memory allocation
Code generation

Example
Source Statement: percent_profit = (profit*100) / cost_price;
Target Program:
MOVER
AREG, PROFIT
MULT
AREG, HUNDRED
DIV
AREG, COST_PRICE
MOVEM
AREG, PERCENT_PROFIT

PERCENT_PROFIT
DW
1
PROFIT
DW
1
COST_PRICE
DW
1
HUNDRED
DC
100

Multi-Pass Organization of Language


Processor
statement by-statement execution
Language
Language Processor
Processor

Source
Program

Analysis Phase

Errors

Synthesis
Synthesis Phase
Phase

Target
Program

Errors

statement by-statement execution i.e. Analysis of


source statement immediately followed by synthesis of
equivalent target statements, may not be feasible due
to following two reasons

Forward Reference
statement by-statement execution requires more memory

A forward reference of a program entity is


a reference to the entity in some
statements of the program that occurs
before the statement containing the
definition or declaration of the entity
percent_profit = (profit*100) / cost_price;
long profit;

Applying Multi-Pass Organization

Language processor pass: A language


processor pass is the processing of every
statement in a source program, or its
equivalent representation, to perform a
language processing function.

Example
A Language Processor having two passes

Pass I: Perform analysis of the source program and


note
the deduced information
Pass II: Perform synthesis of the target program

To avoid duplication of program generated after Pass I, we use


Intermediate Representation
Language Processor
Source
Program

Front end

Back end

Intermediate
representation
(IR)

Target
Program

Intermediate
representation(IR):
An
intermediate
representation is a representation of a source program which
reflects the effect of some, but not all, analysis and synthesis
functions performed during language processing.

Вам также может понравиться