SlideShare a Scribd company logo
1 of 69
System Programming
Prof. D. P. Gandhmal
WIT, Solapur
Chapter 1: Language Processor
• Introduction
• Language Processing Activities
• Fundamentals of Language Processing
• Fundamentals of Language Specification
• Language Processing Development Tools
Introduction
• Why Language Processor?
– Difference between the manner in which software
designer describes the ideas (How the s/w should
be) and the manner in which these ideas are
implemented(CPU).
Semantic Gap
Application
Domain
Execution
Domain
Software
Designer
CPU
• Consequences of Semantic Gap
1. Large development times
2. Large development efforts
3. Poor quality of software
• Issues are tackled by Software Engineering
through use of Programming Language.
Application
Domain
Execution
Domain
PL
Domain
Specification Gap Execution Gap
Language Processors
• A Language Processor is a software which
bridges a specification or execution gap.
• Program to input to a LP is referred as a
Source Program and output as Target
Program.
• Languages in which they are written are called
as source language and target languages
respectively.
A Spectrum of Language Processor
• A language translator bridges an execution gap to
the machine language of a computer system.
• A detranslator bridges the same execution gap as
the language translator but in reverse direction.
• A Preprocessor is a language processor which
bridges an execution gap but is not a language
translator.
• A language migrator bridges the specification gap
between two PL’s.
C++
preprocessor
C++
program
C
program
Errors
C++
translator
Errors
C++
program
Machine
language
program
Interpreters
• An interpreter is a language processor which
bridges an execution gap without generating a
machine language program.
• Here execution gap vanishes totally.
Application
Domain
PL
Domain
Execution
Domain
Interpreter
Domain
Application
Domain
Problem Oriented Language
Execution
Domain
PL
Domain
Specification Gap Execution Gap
Application
Domain
Procedure Oriented Language
Execution
Domain
PL
Domain
Specification Gap Execution Gap
Language Processing Activities
• Divided into those that bridge the
specification gap and those that bridge the
execution gap.
1. Program generation activities.
2. Program execution activities.
Program Generation
• It is a software which accepts the specification
of a program to be generated and generates a
program in the target PL.
Program
generator
Program
specification
Program in
target PL
Errors
Application
Domain
Execution
Domain
PL
Domain
Specification Gap
Program
generator
domain
Example
• A screen handling Program
• Specification is given as below
Employee name : char : start(line=2,position=25)
end(line=2,position=80)
Married : char : start(line =10, position=25)
end(line=10,position=27)
default(‘Yes’)
Yes
Employee Name
Address
Married
Age Gender
Figure: Screen displayed by a screen handling program
Program Execution
• Two models of Program Execution
– Program translation
– Program interpretation
Program Translation
• Program translation model bridges the
execution gap by translating a program
written in PL i.e Source Program into machine
language i.e Target Program.
Translator m/c language program
Source
Program
Target
Program
Errors Data
Figure: Program translation model
Program Interpretation
• Interpreter reads the source program and
stores it in its memory.
• During interpretation it determines the
meaning of the statement.
• Instruction Execution Cycle
1. Fetch the instruction
2. Decode the instruction and determine the
operation to be performed.
3. Execute the instruction.
• Interpretation Cycle consists of—
1. Fetch the statement.
2. Analyze the statement and determine its
meaning.
3. Execute the meaning of the statement.
Source
program
+
Data
Interpreter Memory
PC
Machine
language
program
+
Data
CPU Memory
PC
Errors
Figure (a) : Interpretation Figure (b) : Program Execution
• Characteristics of interpretation
1. Source program is retained in the source
form itself i.e no target program.
2. A statement is analyzed during its
interpretation.
Fundamentals of Language Processing
• Lang Processing = Analysis of SP+ Synthesis of TP.
• Analysis consists of three steps
1. Lexical rule identifies the valid lexical units
2. Syntax rules identifies the valid statements
3. Semantic rules associate meaning with valid
statement.
Example:-
percent_profit := (profit * 100) / cost_price;
Lexical analysis identifies-------
:=, * and / as operators
100 as constant
Remaining strings as identifiers.
Syntax analysis identifies the statement as the
assignment statement.
Semantic analysis determines the meaning of
the statement as
profit x 100
cost_price
to percent_profit
• Synthesis Phase
1. Creation of DS
2. Generation of target code
Refered as memory allocation and code
generation, respectively.
MOVER AREG, PROFIT
MULT AREG, 100
DIV AREG, COST_PRICE
MOVEM AREG, PERCENT_PROFIT
-------------------
PERCENT_PROFIT DW 1
PROFIT DW 1
COST_PRICE DW 1
Analysis Phase and Synthesis phase is not
feasible due to
1. Forward References
2. Memory Requirement
Forward Reference
• It is a reference to the entity which precedes
its definition in the program.
percent_profit := (profit * 100) / cost_price;
……..
……..
long profit;
Language Processor Pass
• Pass I : performs analysis of SP and notes
relevant information.
• Pass II: performs synthesis of target program.
Pass I analyses SP and generates IR which is
given as input to Pass II to generate target
code.
Intermediate Representation (IR)
• An IR reflects the effect of some but not all,
analysis and synthesis tasks performed during
language processing.
Front End Back End
Intermediate
Representation (IR)
Source
Program
Target
Program
• Properties
1. Ease of use.
2. Processing efficiency.
3. Memory efficiency.
Toy Compiler
• Front End
Performs lexical, syntax and semantic analysis of
SP.
Analysis involves
1. Determine validity of source stmt.
2. Determine the content of source stmt.
3. Construct a suitable representation.
Output of Front End
1. Tables of information
2. Intermediate code (IC)
IC is a sequence of IC units, represents meaning
of one action in SP
Example
i: integer;
a,b: real;
a := b+i;
Symbol Table.
No. Symbol Type Length Address
1 i int
2 a real
3 b real
4 i* real
5 temp real
• Intermediate code
1. Convert (id, #1) to real, giving (id, #4)
2. Add (id, #4) to (id, #3) giving (id, #5)
3. Store (id, #5) in (Id, #2)
Lexical Analysis (Scanning)
• Identifies lexical units in a source statement.
• Classifies units into different classes e.g id’s,
constants, reserved id’s etc and enters them
into different tables
• Token contains
– Class code and number in class
Code #no Id #10e.g.
• Example
Statement a := b + i;
a := b + i ;
Id #2 Op #5 Id #3 Op #3 Id #1 Op #10
Syntax Analysis (Parsing)
• Determines the statement class such as
assignment statement, if stmt etc.
e.g.:- a , b : real; and a = b + I ;
real
a b
:=
a
+
b i
Semantic Analysis
• Determines the meaning of the SP
• Results in addition of info such as type, length
etc.
• Determines the meaning of the subtree in IC
and adds info to the IC tree.
Stmt a := b +i; proceeds as
1. Type is added to the IC tree
2. Rules of assignment indicate expression on
RHS should be evaluated first.
3. Rules of addition indicate i should be
converted before addition
i. Convert i to real giving i*;
ii. Add i* to b giving temp.
iii. Store temp in a.
:=
a, real +
b, real i, int
:=
a, real +
b, real i*, int
:=
a, real temp, real
(a) (b)
(c)
Scanning
Parsing
Semantic analysis
Symbol table
Constant table
Other table
Source Program
Lexical
errors
Syntax
errors
Semantic
errors
IC
IR
Figure: Front end of a Toy Compiler
tokens
Parse tree
Back End
1. Memory Allocation
Calculated form its type, length and dimentionality.
No. Symbol Type Length Address
1 i int 2000
2 a real 2001
3 b real 2002
• Code generation
1. Determine places where results should be
kept in registers/memory location.
2. Determine which instruction should be used
for type conversion operations.
3. Determine which addressing modes should
be used for accessing variables.
CONV_R AREG, I
ADD_R AREG, B
MOVEM AREG, A
Figure: Target Code
Memory allocation
Code generation
Symbol table
Constants table
Other tables
Target
program
IR
IC
Figure: Back End of the toy compiler
Fundamentals of Language
Specification
• Programming Language grammars.
alphabets
Words / Strings
Sentences/ Statements
Language
Terminal symbols, alphabet and strings
• The alphabet of L is represented by a greek
symbol Σ.
• Such as Σ = {a , b , ….z, 0, 1,…. 9}
• A string is a finite sequence of symbols.
α= axy
Productions
• Also called as rewriting rule
A nonterminal symbol ::= String of T’s and NT’s
e.g.:
<Noun Phrase> ::= <Article> <Noun>
<Article> ::= a| an | the
<Noun> ::= boy | apple
Grammar
• A grammar G of a language LG is a quadruple
(Σ, SNT, S, P) where
– Σ is the alphabet
– SNT is the set of NT’s
– S is the distinguished symbol
– P is the set of productions
Derivation
• Let production P1 of grammar G be of the
form
P1 : A ::= α
And let β be such that β = γAθ
β = γαθ
Example
<Sentence> :: = <Noun Phrase> <Verb Phrase>
<Noun Phrase> ::= <Article> <Noun>
<Verb Phrase> ::= <Verb> <Noun Phrase>
<Article> ::= a| an| the
<Noun> ::= boy | apple
<Verb> ::= ate
<Sentence>
<Noun Phrase> <Verb Phrase>
<Article> <Noun> <Verb Phrase>
<Article> <Noun> <Verb> <Noun Phrase>
the <Noun> <Verb> <Article> <Noun>
the boy <Verb> <Article> <Noun>
the boy ate <Article> <Noun>
the boy ate an <Noun>
the boy ate an apple
Binding and Binding Times
• Program entity pei in program P has a some
attributes. pei
kind
variable procedure Reserved id etc
type dimen Mem addr etc
size
Definition
• A binding is an association of an attribute of a
program entity with a value.
• Binding time is the time at which binding is
performed.
int a;
Different Binding Times
1. Language definition time of L
2. Language implementation time of L
3. Compilation time of P
4. Execution init time of proc
5. Execution time of proc
program bindings(input , output);
var
i : integer;
a,b : real;
procedure proc (x: real; j: integer);
var
info : array[1…10,1…5] of integer;
p : integer;
begin
new (p);
end;
begin
proc(a,i);
end
1. Binding of keywords with its meaning.
e.g.: program, procedure, begin and end.
2. Size of type int is bind to n bytes.
3. Binding of var to its type.
4. Memory addresses are allocated to the variables.
5. Values are binded to memory address.
Types of Binding
• Static Binding:
– Binding is performed before the execution of a
program begins.
• Dynamic Binding:
– Binding is performed after the execution of a
program has begun.
Language Processor Development
Tools (LPDT)
LPDT requires two inputs:
1. Specification of a grammar of language L
2. Specification of semantic actions
Two LPDT’s which are widely used
1. LEX (Lexical analyzer)
2. YACC (Parser Generator)
It contains translation rules of form
<string specification> { <semantic action>}
Front end
generator
Grammar
of L
Semantic
action
Scanning
Parsing
Semantic analysis
Source Program
IR
Front end
Scanner
Parser
LEX
YACC
Source Program in L
IR
Lexical
Specification
Syntax
Specification
LEX
• LEX consists of two components
– Specification of strings such as id’s, constants etc.
– Specification of semantic action
%{
//Symbols definition; 1st section
%}
%%
//translation rules; 2nd section
Specification Action
%%
//Routines; 3rd section
% {
letter [A-Za-z]
digit [0-9]
}%
%%
begin {return(BEGIN);}
end {return(END);}
{letter} ( {letter}|{digit})* {yylval = enter_id();
return(ID);}
{digit}+ {yylval=enter_num();
return(NUM);}
%%
enter_id()
{ /*enters id in symbol table*/ }
enter_num()
{/* enters number in constabts table */}
YACC
• String specification resembles grammar
production.
• YACC performs reductions according to the
grammar.
Example
%%
E : E+T {$$ = gencode(‘+’, $1, $3);}
| T {$$ = $1;}
T : T*V {$$ = gencode(‘*’, $1, $3);}
| V {$$ = $1;}
V : id {$$ = gendesc($1);}
%%
gencode (operator, operand_1, operand_2){ }
gendesc(symbol) { }
Thank You!!!

More Related Content

What's hot

System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
Manoj Patil
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
Manoj Patil
 

What's hot (20)

Macro-processor
Macro-processorMacro-processor
Macro-processor
 
Assemblers
AssemblersAssemblers
Assemblers
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Loaders ( system programming )
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming )
 
Direct linking loaders
Direct linking loadersDirect linking loaders
Direct linking loaders
 
Unit 3 sp assembler
Unit 3 sp assemblerUnit 3 sp assembler
Unit 3 sp assembler
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Pass Structure of Assembler
Pass Structure of AssemblerPass Structure of Assembler
Pass Structure of Assembler
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
Chap 1-language processor
Chap 1-language processorChap 1-language processor
Chap 1-language processor
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Software tools
Software toolsSoftware tools
Software tools
 
System software
System softwareSystem software
System software
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 

Similar to System Programming Overview

Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02
riddhi viradiya
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 

Similar to System Programming Overview (20)

490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
Compilers.pptx
Compilers.pptxCompilers.pptx
Compilers.pptx
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
Compiler design
Compiler designCompiler design
Compiler design
 
Cd econtent link1
Cd econtent link1Cd econtent link1
Cd econtent link1
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdf
 
C programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilC programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakil
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 

More from Dattatray Gandhmal (6)

Lexical analysis-using-lex
Lexical analysis-using-lexLexical analysis-using-lex
Lexical analysis-using-lex
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

System Programming Overview

  • 1. System Programming Prof. D. P. Gandhmal WIT, Solapur
  • 2. Chapter 1: Language Processor • Introduction • Language Processing Activities • Fundamentals of Language Processing • Fundamentals of Language Specification • Language Processing Development Tools
  • 3. Introduction • Why Language Processor? – Difference between the manner in which software designer describes the ideas (How the s/w should be) and the manner in which these ideas are implemented(CPU).
  • 5. • Consequences of Semantic Gap 1. Large development times 2. Large development efforts 3. Poor quality of software • Issues are tackled by Software Engineering through use of Programming Language.
  • 7. Language Processors • A Language Processor is a software which bridges a specification or execution gap. • Program to input to a LP is referred as a Source Program and output as Target Program. • Languages in which they are written are called as source language and target languages respectively.
  • 8. A Spectrum of Language Processor • A language translator bridges an execution gap to the machine language of a computer system. • A detranslator bridges the same execution gap as the language translator but in reverse direction. • A Preprocessor is a language processor which bridges an execution gap but is not a language translator. • A language migrator bridges the specification gap between two PL’s.
  • 10. Interpreters • An interpreter is a language processor which bridges an execution gap without generating a machine language program. • Here execution gap vanishes totally. Application Domain PL Domain Execution Domain Interpreter Domain
  • 13. Language Processing Activities • Divided into those that bridge the specification gap and those that bridge the execution gap. 1. Program generation activities. 2. Program execution activities.
  • 14. Program Generation • It is a software which accepts the specification of a program to be generated and generates a program in the target PL. Program generator Program specification Program in target PL Errors
  • 16. Example • A screen handling Program • Specification is given as below Employee name : char : start(line=2,position=25) end(line=2,position=80) Married : char : start(line =10, position=25) end(line=10,position=27) default(‘Yes’)
  • 17. Yes Employee Name Address Married Age Gender Figure: Screen displayed by a screen handling program
  • 18. Program Execution • Two models of Program Execution – Program translation – Program interpretation
  • 19. Program Translation • Program translation model bridges the execution gap by translating a program written in PL i.e Source Program into machine language i.e Target Program. Translator m/c language program Source Program Target Program Errors Data Figure: Program translation model
  • 20. Program Interpretation • Interpreter reads the source program and stores it in its memory. • During interpretation it determines the meaning of the statement.
  • 21. • Instruction Execution Cycle 1. Fetch the instruction 2. Decode the instruction and determine the operation to be performed. 3. Execute the instruction.
  • 22. • Interpretation Cycle consists of— 1. Fetch the statement. 2. Analyze the statement and determine its meaning. 3. Execute the meaning of the statement.
  • 24. • Characteristics of interpretation 1. Source program is retained in the source form itself i.e no target program. 2. A statement is analyzed during its interpretation.
  • 25. Fundamentals of Language Processing • Lang Processing = Analysis of SP+ Synthesis of TP. • Analysis consists of three steps 1. Lexical rule identifies the valid lexical units 2. Syntax rules identifies the valid statements 3. Semantic rules associate meaning with valid statement.
  • 26. Example:- percent_profit := (profit * 100) / cost_price; Lexical analysis identifies------- :=, * and / as operators 100 as constant Remaining strings as identifiers. Syntax analysis identifies the statement as the assignment statement. Semantic analysis determines the meaning of the statement as profit x 100 cost_price to percent_profit
  • 27. • Synthesis Phase 1. Creation of DS 2. Generation of target code Refered as memory allocation and code generation, respectively. MOVER AREG, PROFIT MULT AREG, 100 DIV AREG, COST_PRICE MOVEM AREG, PERCENT_PROFIT ------------------- PERCENT_PROFIT DW 1 PROFIT DW 1 COST_PRICE DW 1
  • 28. Analysis Phase and Synthesis phase is not feasible due to 1. Forward References 2. Memory Requirement
  • 29. Forward Reference • It is a reference to the entity which precedes its definition in the program. percent_profit := (profit * 100) / cost_price; …….. …….. long profit;
  • 30. Language Processor Pass • Pass I : performs analysis of SP and notes relevant information. • Pass II: performs synthesis of target program. Pass I analyses SP and generates IR which is given as input to Pass II to generate target code.
  • 31. Intermediate Representation (IR) • An IR reflects the effect of some but not all, analysis and synthesis tasks performed during language processing. Front End Back End Intermediate Representation (IR) Source Program Target Program
  • 32. • Properties 1. Ease of use. 2. Processing efficiency. 3. Memory efficiency.
  • 33. Toy Compiler • Front End Performs lexical, syntax and semantic analysis of SP. Analysis involves 1. Determine validity of source stmt. 2. Determine the content of source stmt. 3. Construct a suitable representation.
  • 34. Output of Front End 1. Tables of information 2. Intermediate code (IC) IC is a sequence of IC units, represents meaning of one action in SP
  • 35. Example i: integer; a,b: real; a := b+i; Symbol Table. No. Symbol Type Length Address 1 i int 2 a real 3 b real 4 i* real 5 temp real
  • 36. • Intermediate code 1. Convert (id, #1) to real, giving (id, #4) 2. Add (id, #4) to (id, #3) giving (id, #5) 3. Store (id, #5) in (Id, #2)
  • 37. Lexical Analysis (Scanning) • Identifies lexical units in a source statement. • Classifies units into different classes e.g id’s, constants, reserved id’s etc and enters them into different tables • Token contains – Class code and number in class Code #no Id #10e.g.
  • 38. • Example Statement a := b + i; a := b + i ; Id #2 Op #5 Id #3 Op #3 Id #1 Op #10
  • 39. Syntax Analysis (Parsing) • Determines the statement class such as assignment statement, if stmt etc. e.g.:- a , b : real; and a = b + I ; real a b := a + b i
  • 40. Semantic Analysis • Determines the meaning of the SP • Results in addition of info such as type, length etc. • Determines the meaning of the subtree in IC and adds info to the IC tree.
  • 41. Stmt a := b +i; proceeds as 1. Type is added to the IC tree 2. Rules of assignment indicate expression on RHS should be evaluated first. 3. Rules of addition indicate i should be converted before addition i. Convert i to real giving i*; ii. Add i* to b giving temp. iii. Store temp in a.
  • 42. := a, real + b, real i, int := a, real + b, real i*, int := a, real temp, real (a) (b) (c)
  • 43. Scanning Parsing Semantic analysis Symbol table Constant table Other table Source Program Lexical errors Syntax errors Semantic errors IC IR Figure: Front end of a Toy Compiler tokens Parse tree
  • 44. Back End 1. Memory Allocation Calculated form its type, length and dimentionality. No. Symbol Type Length Address 1 i int 2000 2 a real 2001 3 b real 2002
  • 45. • Code generation 1. Determine places where results should be kept in registers/memory location. 2. Determine which instruction should be used for type conversion operations. 3. Determine which addressing modes should be used for accessing variables.
  • 46. CONV_R AREG, I ADD_R AREG, B MOVEM AREG, A Figure: Target Code
  • 47. Memory allocation Code generation Symbol table Constants table Other tables Target program IR IC Figure: Back End of the toy compiler
  • 48. Fundamentals of Language Specification • Programming Language grammars. alphabets Words / Strings Sentences/ Statements Language
  • 49. Terminal symbols, alphabet and strings • The alphabet of L is represented by a greek symbol Σ. • Such as Σ = {a , b , ….z, 0, 1,…. 9} • A string is a finite sequence of symbols. α= axy
  • 50. Productions • Also called as rewriting rule A nonterminal symbol ::= String of T’s and NT’s e.g.: <Noun Phrase> ::= <Article> <Noun> <Article> ::= a| an | the <Noun> ::= boy | apple
  • 51. Grammar • A grammar G of a language LG is a quadruple (Σ, SNT, S, P) where – Σ is the alphabet – SNT is the set of NT’s – S is the distinguished symbol – P is the set of productions
  • 52. Derivation • Let production P1 of grammar G be of the form P1 : A ::= α And let β be such that β = γAθ β = γαθ
  • 53. Example <Sentence> :: = <Noun Phrase> <Verb Phrase> <Noun Phrase> ::= <Article> <Noun> <Verb Phrase> ::= <Verb> <Noun Phrase> <Article> ::= a| an| the <Noun> ::= boy | apple <Verb> ::= ate
  • 54. <Sentence> <Noun Phrase> <Verb Phrase> <Article> <Noun> <Verb Phrase> <Article> <Noun> <Verb> <Noun Phrase> the <Noun> <Verb> <Article> <Noun> the boy <Verb> <Article> <Noun> the boy ate <Article> <Noun> the boy ate an <Noun> the boy ate an apple
  • 55. Binding and Binding Times • Program entity pei in program P has a some attributes. pei kind variable procedure Reserved id etc type dimen Mem addr etc size
  • 56. Definition • A binding is an association of an attribute of a program entity with a value. • Binding time is the time at which binding is performed. int a;
  • 57. Different Binding Times 1. Language definition time of L 2. Language implementation time of L 3. Compilation time of P 4. Execution init time of proc 5. Execution time of proc
  • 58. program bindings(input , output); var i : integer; a,b : real; procedure proc (x: real; j: integer); var info : array[1…10,1…5] of integer; p : integer; begin new (p); end; begin proc(a,i); end
  • 59. 1. Binding of keywords with its meaning. e.g.: program, procedure, begin and end. 2. Size of type int is bind to n bytes. 3. Binding of var to its type. 4. Memory addresses are allocated to the variables. 5. Values are binded to memory address.
  • 60. Types of Binding • Static Binding: – Binding is performed before the execution of a program begins. • Dynamic Binding: – Binding is performed after the execution of a program has begun.
  • 61. Language Processor Development Tools (LPDT) LPDT requires two inputs: 1. Specification of a grammar of language L 2. Specification of semantic actions Two LPDT’s which are widely used 1. LEX (Lexical analyzer) 2. YACC (Parser Generator)
  • 62. It contains translation rules of form <string specification> { <semantic action>} Front end generator Grammar of L Semantic action Scanning Parsing Semantic analysis Source Program IR Front end
  • 63. Scanner Parser LEX YACC Source Program in L IR Lexical Specification Syntax Specification
  • 64. LEX • LEX consists of two components – Specification of strings such as id’s, constants etc. – Specification of semantic action
  • 65. %{ //Symbols definition; 1st section %} %% //translation rules; 2nd section Specification Action %% //Routines; 3rd section
  • 66. % { letter [A-Za-z] digit [0-9] }% %% begin {return(BEGIN);} end {return(END);} {letter} ( {letter}|{digit})* {yylval = enter_id(); return(ID);} {digit}+ {yylval=enter_num(); return(NUM);} %% enter_id() { /*enters id in symbol table*/ } enter_num() {/* enters number in constabts table */}
  • 67. YACC • String specification resembles grammar production. • YACC performs reductions according to the grammar.
  • 68. Example %% E : E+T {$$ = gencode(‘+’, $1, $3);} | T {$$ = $1;} T : T*V {$$ = gencode(‘*’, $1, $3);} | V {$$ = $1;} V : id {$$ = gendesc($1);} %% gencode (operator, operand_1, operand_2){ } gendesc(symbol) { }