= " Pvekhopkaw
— ci cose).
Un | lhanquage Wwe g
Psocessay .
Language Processor
A tanguoage Processor IS a system Paya
Theat bwdqes yne Sap beteween pow oF
Oser descmhbes a ComP otot on - we coll it
a Speer Fl caHen she Cocetpy tq om. $ how
A Comprvier £xKddrren a PVOGra™
4 ikinads of Language Processors
A langeage Psecessea— 15 a Aefhoere whidds
bwdqes a Speciercatton oy exceurHion gu? -
— 7 Seen one t Kew ton
a>
Programming © -
____Nangdage demain Permetrny
Pig Qpecigicattom 4 Execust'an $oPs——
na eer Dopware engi veering P2eep 5 thot
C Concesn Jus are as Poltecos +
NYA Of 25 APPIcanton, propan,
as coding | me eee mt ae
He Pro grepeo es ts eee
' a) langeage 7 Freensaing acre,
Inte hoe Megowies -
Freya. genertHon ————
FOTO) execute n =
CcePxs He Apecificahem fo A Proqrany
D “Some PPeeiftcaven JIUwJrage 4 geperoten
(oD Prqram 19 tre sarqet forg. het Fol) CIty
He ApeuPrcanons ark ie
= Use & “peogwroun Petco Tipmreden q new
Aommairy callect +e pweram 4erererter” recs
betes ee ee od
___langsagye clomains
7 othe Speci@fcation geo Aacedl 5,
an copplicattion PFOqraM 1S 1S 790
j te deaiqgoer— |
Are appl? doma'a fF me proqren | gare
ale main.
Wc clema'n st “pe target p> raprsmming eyes
Fe, prograns generate | domais a eloseh
e apy domain the Sper fiedhory gap +s a
@ Progam 4 genevatou +o apea cic “Aer y=
_Demas'y iy : s =
i paps the feaal
efoo volwe.
oieyes cr >Eimoinjee came [eh
- 10
: ; ecihicaniory | Senerarr | ~ -ealeger pl
——sreatntcatian
Sar
Tay ret el Execuw
—Gomel) fenerater — darmaln ——-
olemain—
a9 prearamn generating ® Sthne mah
preqaam penne dene,
_pavqram i> _—_—
be “henget lenges?
a0
— —-gpectOleu Hm
“eg “purpose projram qenerdin
- (Sas)POC.
sae eee DES 1p por ° tbe Fellous),7
|__ Kbe | Components”: : ms
qe Peer ee
Pefinihonl dined opervatny Ft dota,
JH? Spearicahen be WDroqeany 8 be
~feneta esl. { Serre)
See : bo terol
Cet ai
Preyrenso iene colon, | \
on.
i PPP cheans laos
Te psqeany rer lttton med el badges
cares Execwjw+Hon Sep By chewnsleting A preqrany
_ Os HeR Q poo Poing ~)809—~catled toe
SOv7TCe program into OW $9 vivalent Preqrans
10 Me Machine o- assembly (ang. ne
Cormmperce System, Called nk teeges PRET
AD eer
Se ES Ee pela
4 Pers 12 y ar
sae role 18] Soest -
mie lang. Pg
Ben ILD,
FAUde PrBgrany transletin modes
“The Proqram translanen Medd bar ine,
Following chawacterissics | oT
LAr Ps eT mes4 abel translated before 1+ con be
txXewted.
2. mMochine lang, Par Jenerarrd by the rei rslatey—
meray be Saved. jn a HI€. so tear/ It can +e-
lodded inte +he Cenpoter Meme St weeetec/
Whenever cdcsierg
This Scheme Makes it oHnecessary +O Funeiare
the ss -P- Sven Hime 1S to be Fxceoped
{Be [Link] Tarsla ty
oF tet Pea aBi BAA SP ys Medea! the medi elee Pregrem mest
joe deanSldted . befewe It COD be FKeutra.
ey
e— e cau id aS Aollowi Og & Medi Gay,
A Prothral Arrangemers
PRD LASL ON
e prose Peeper He :
An inteepreret Execotes 9 Proqran eerie A
__ qerenmatnn: ( asyarge Prova -
-_7ro vederstand how 2)
jer. considesithe Aim)i\am
ae ole 1etrg. PeRIe
@ Cpe 2 a. compory” _ aoe
the pexk machines
= Execomen ¢ the ppoq=om.
et pcated! Pex forming. + ane iostev (He exe)
= steps
cycle whic consisis: 6 whe follow!"
is fe be _ Exe
|. Fetth me IY STO CH OTD het
De tot 4bd\ WEA cH Fe 7 —
1s +o be peerommed ) eo
ineica Fe an CIT A an ©:
te
opeeaHon
Operaads Are -
code Jo and. is invealrel
3 (Pecfow +he >E OPERAHOO. ys
i eeePretation
) éxecoH on fale
we can ster Fy the Feliswing chorocter—
IN ME Preteution, PeOM tne Schematic
“e the Sp ig Pteuned IN Seow eR tor, —
jee (sino 7
“cenvenmey us g tangeh Programs,
. A Gen
wPent Le an.
refed clering Js"
ITE prFrasin,
2-Aaly ais g Sonne
Processing Awa xis
Lorgeage = torrmesié ater:
15 ZA Lang. pressor
= & cyntnesis PHYS B
- - ag @ Fores
ee
SPU MO
lange
(su tyes ls
Sovrte any 3119
< Sg, sam Pellocs')
“ls 4 SesQe prog za ae a
an
sp ecleicoHon cone sts 8
ster] Comp pers10 the seuyce language sven as
aAtoos , identelews f Constant s
valid
ends jO +HE SOO*TE pa0gvVere_
emanne Dwiles associate meanings eth valid y
Ig wpe Pevrce jangraae :
Peal § PASS erganication g, Langease processes, eS
ee
Sjaiement by Statement reresss prs -
Mesence program 3 nel Pass ie deve >?
¢
Zz
EA language
ah cretemen! by —Hesement Process!© 2
q
(Sou,ce pragxram ¢ Aeqeire TIO+e, eee Py,
“Sapan 1s Ss avelitabie a tts Opetatt en
“ibs peegeamy “Hbar 2 Koes
befere be Siaterhen containin ape deAinipero”
Coss oy 1S the poocessIn > Every
ina aq source Progxom
pA having +.o0 passes
“pass T) PerfOern analyses q tre source Poa,
tha deduced intvmanen i
*PD Srotpesis p tpe espe,
Progra |z . oe
Se eical Seales Govern Formation 4g. valid level 7%
tA tHe LoUrcE lanqvagr¢ sech as
Aters, idenh ers iene
DINAH OD, vet d
Dweles associate meanings wlth valid vc
sernents ® ape Poorce jangvage ye
fe — et
ert FASS arganikation q, Langvase processes,
Tosyatement by Statemans Tenens ore
ee role dee, >>
3
Besoerce PIeqvam eS
Tae Following Roa) [BCAsSens ', A
AeSooxre Pega rn monn Conta Forusard &
Diqine MEP ences ro rE
fig SA lanqoage procession” tht peetexnes -
= Miasement Process!6 q a
Exe qi Cemt rare mrocaayie’
doth operation:
SQ 7efexence fo me ott
19 SOME Stasemen /fL tos Pena thab 0 Coxrs
Secs be en Comaiming sre deAinipoor
sp ordedorse 9 the. errty
ASOIT, Pass | 1 ALlonseea-< -
ASS IS the poocessin every
10 Las
bk SEEPrESenyAHO FO perros 2
_ lanjyoase | precessing Aunuion
T_ongvay e PrOcessO~ faving +00 passes
_ Per fern analycig 9. tre source Prepay
_ ote tha} dedoced \N SMa Ren,
Fass or; Per fered Spothesis pb tee tevre,
a Progecn,Dee” Ihrer mechate repeesemadtier CER ) es
— AN FR isa Aepresertatlon 9 a S
Aer lects aye e Pech b
letinguage i
T2 b eerechue p20 FR shoutet have tne :
Felleceing Ahere Properties
SERGE GD Ose
< Peseastog
i, ene;
Wem
LH THES SR Shoutd
~ Se 48t + dees nok
be Compact
eccery vc
Pass Schematic for } ANGOAge process.”
=e 2Wy LEX, e
SEM ES LAL PROGRAM thet generdhs te xicad
wots esecd with yace payse
the rented. anedices 1S a pgm Hct
Into 4d
asco OTM an _ IAPS sSpean
Seqoene tokens |
1H Sreads~ the Inpur Seay Teprsesres
“Phe source Cocte AS o/ P_thresgh 1mPlemeth
the Iextcel Analy Xow 10 tre CC Progrem
Se oFuncion | PRUE K 1S AS Fellows:
le wiced feat “crates a Proyreens
She OK pesgose Then tex Compe! ter
Te < lex: program f prodores
ogra lex yi c
ae c ‘comptlew HONS Phe, lex: ye: c
bo preduces an object progyem
+ 1S @ lexical analyvenr tral “tronaperms
Sequenre,
s+okens,Sections
b
Cex Soom
2 ce -// becia
A Yo
Simeles s
Loi hei
Svser Sobroayiees =
ed-pe procure 4
He analynek % ?
=~ CALR CO). gxem nm
a rhe uP
IS oe Ole one - peau o
_c program | a dee a
hese “are Some. Ponds abou) Jace:
Pps ee Filey :
ol A_Parsex y. fob-c Cyace). : a
“The olp “ie " ile ourrus! condains. the
Paesing Jables. - Shae
“= tThe_ Pile 4ile. tob-b” Contains deelavrettons
The __parser__called_the_Y7 parse (9
Parser Fppeett to Use a fone called
len [Link] tokens——
“Given in geen:
S toe, YaSe program .
IbS the C Soume Proymam (ota "7 yPce ”
cc _ -
SS | a
Tec,
Cc Compiles
Fr ecedeib ie #1 thar alll parse grammea—Compiler construction tools
‘The compiler writer ean use some specialized tools that help in implementing, various phivses of w
compiler. These tools assist in the creation of an entire compiler or ity parts, Some commonly
used compiler construction tools include:
1. Parser Generator ~ It produces syntux analyzers (parsers) from the input that is based
‘on a grammatical description of programming language or on a context-free grammar, It
w
is useful as the syntax analysis phase is highly complex and consumes more manual and
compilation time. Example: PIC, EQM
tokens
context free —.aEIetIn __ Eds
grammer (DCT lp ‘analyzer,
parse tree
Scanner Generator ~ It generates lexical analyzers from the input that consists of
regular expression description based on tokens of « language. It generates « finite
automaton to recognize the regular expression, Example: Lex
source
program
|
ese
specifications: [Ree
of regular Kefol-tee] ely analyzer
expression :
tokens
Syntax directed translation engines ~ It generates intermediate code with three address
format from the input that consists of a parse tree. ‘These engines have routines to traver
the parse tree and then produces the intermediate code. In this, each node of the parse t
is associated with one or more translations.
‘Automatic code generators ~ It generates the machine language for a target
Each operation of the intermediate language is translated using a collection of rules and
then is taken as an input by the code generator. A template matching process is used. An
intermediate language statement is replaced by its equivalent machine language statement
using templates.
Data-flow analysis engines ~ It is used in code optimization, Data flow analysis is a key
part of the code optimization that gathers the information, that is the values that flow
_Srom one part of a program to another, Refer ~ data flow analysis in Compiler
chine,cow — YvoSvrupileg
¢ \ Ar aepines
AY inclote .
yoCESSoe— J
~ y mndinied s 0. i a
——+
ComiX 7
TT Aeges AY aw PP rOgrensD
Assembler |
Us
Relocarable mm] ec cade
t ‘
,cinkew ®
Coader / tin — Ubsamy ee ot oe;
Sret
y Cosable object
. Ales are worked
. c .
Absoolte 1S. usd, Sater
Sat rewoag
Aled He ent
POM 2b MNiln mer
TR KE wo oD,6. Compiler construction toolkits ~ It provides an integrated set of routines that aids in
building compiler components or in the construction of various phases of compiler.
Features of compiler construction tools :
Lexical Analyzer Generators This too! helps in generating the lexical analyzer or seaner of the
compiler, It takes as input a set of regular expressions that define the syntax of the language
being compiled and produces a program that reads the input source code and tokenizes it based
‘on these regular expressions.
Parser Generator: This tool helps in generating the parser of the compiler. It takes as input a
context-free grammar that defines the syntax of the language being compiled and produces a
program that parses the input tokens and builds an abstract syntax tree.
Code Generation Tools: These tools help in generating the target code for the compiler. They
take as input the abstract syntax tree produced by the parser and produce code that ean be
executed on the target machine.
Optimization Tools: These tools help in optimizing the generated code for efficiency and
performance. They can perform various optimizations such as dead code elimination, loop
‘optimization, and register allocation.
Debugging Tools: These tools help in debugging the compiler itself or the programs that are
being compiled. They can provide debugeing information such as symbol tables, call stacks, and
runtime errors.
Profiling Tools: These tools help in profiling the compiler or the compiled code to identity
performance bottlenecks and optimize the code accordingly.
Documentation Tools: These tools help in generating documentation for the compiler and the
programming language being compiled. They can generate documentation forthe syntax,
semantics, and usage of the language.
Language Support: Compiler construction tools are designed to support a wide range of
programming languages, including high-level languages such as C++, Java, and Python, as well
as low-level languages such as assembly language.
Cross-Platform Support: Compiler construction tools may be designed to work on multiple
platforms, such as Windows, Mac, and Linux,
User Interface: Some compiler construction tools come with a user interface that makes it eas
for developers to work with the compiler and its associated tools.Cousins of Compiler
Converting a high-level language into a low-level language takes multiple steps and involve
many programs apart from the Compiler, Before the compilation can start, our source code needs:
to be preprocessed. After the compilation, our code needs to be converte: ccutable code to
execute on our machine, These essential tasks are performed by the preprocessor, assembler,
Linker, and Loader. They are known as the Cousins of the Compiler, Let's study them in detail,
Let's see who the cousins of Compiler are and what their contributions are in the process of
converting a high-level language into a low-level language.
Preprocessor
‘The preprocessor is one of the cousins of the Compiler. It is a program that performs
preprocessing, It performs processing on the given data and produces an output, ‘The output
‘generated is used as an input for some other program.
“The preprocessor increases the readability of the code by replacing a complex expression with
simpler one by using a macro,
‘A preprocessor performs multiple types of functionality and operations on the data,
Some of them are-
Macro processing
Macro processing is mapping the input to output data based on a certain set of rules and defi
processes. These rules are known as macros.
Rational Preprocessors
Relational preprocessors are the processors that change older languages with some modern flow-
of-control and data-structuring facilities.
File Inclusion
‘The preprocessor is also ‘used to include header files in the program text, A header file is a text
file included in our source program file during compilation. When the preprocessor finds an
include directive in the program, it replaces it with the entire content of the specified header
file.Language extension
Language extension is used to add new capabilities to the existing language. This is done by
including certain libraries in our i i fonalit
i program, which provides extra functionality. An example of this
is Equel, a database query language embedded in C. co“ en
Error Detection
‘Some preprocessors are capable of performing error-checking on the source code that is given as
input to them, For example, it can check if the headers files are included properly and if the
macros are defined correctly of not.
Conditional Compilation
Certain preprocessors are capable of including or excluding certain pieces of code based on the
reuult of condition, They provide more flexibility to the programmers for writing the code as
they allow the programmers to include or exclude certain features of the program based upon
some condition.
‘Assembler
“Assembler is also one of the cousins of the compiler. A compiler takes the preprocessed code
ashen converts it into assembly code. This assembly code is given as input tothe assembler,
and thc assembler convers it into the machine code. Assembler comes into effect in the
‘compilation process after the Compiler has finished its job.
‘There are two types of assemblers-
« One-Pass assembler: They go through the source code (output of Compiler) only once
and assume that all symbols will be defined before any instruction that references them.
«-Two-Pass assembler: Two-pass assemblers work by creating a symbol table with the
symbols and their values in the frst pass, and then using the symbol table in @ second
pass, they generate code.
Linker
Linker takes the output produced by the assembler as input and combines them to create an
‘executable file. It merges two or more object files that might be created by different assemblers
‘and creates a link between them. It also appends all the libraries that will be required for the
execution of the file. A linker's primary function is to search and find referred modules in a
program and establish the memory ‘address where these codes will be loaded.
‘Multiple tasks that can be performed by linkers include-Library Mi : Lit
iry Management: Linkers can be used to add external libraries to our code to add
additional functior i ae
Geo aerges in those 1 pune By adding those libraries, our code can now use the functions
Code Optimization: Linkers are also used to optimize the code generated by the
mpiler by reducing the code size and increasing the program's performance.
Memory Management: Linkers are also responsible for managing the memory
requirement of the executable code. It allocates the memory to the variables used in the
program and ensures they have a consistent memory location when the code is executed.
+ Symbol Resolution: Linkers link multiple object files, and a symbol can be redefined in
multiple files, giving rise to a conflict, The linker resolves these conflicts by choosing
one definition to use.
Loader
‘The loader works after the linker has performed its task and created the executable code. It takes
the input of executable files generated from the linker, loads it to the main memory, and prepares
this loaded code for execution by a computer. It also allocates memory space to the program. The
Toader is also responsible for the execution of programs by allocating RAM to the program and
initializing specific registers.
Following tasks are performed by the loader
+ Loading: The loader loads the executable files in the memory and provides memory for
executing the program.
Relocation: The loader adjusts the memory addresses of the program to relocate its
location in memory.
+ Symbol Resolution: The londer is used to resolve the symbols not defined directly in the
program, They do this by looking for the definition of that symbol in a library linked to
the executable file,
«Dynamic Linking: The loader dynamically links the libraries into the executable file at
runtime to add additional functionality to our program