Language processing system.pdf

773 views 17 slides Nov 09, 2022
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

Xyz


Slide Content

Introduction toCompiler
1

Compiler
•Programminglanguagesarenotationsfordescribingcomputationstopeople
andtomachines.Theworldasweknowitdependsonprogramming
languages,becauseallthesoftwarerunningonallthecomputerswas
writteninsomeprogramminglanguage.But,beforeaprogramcanberun,it
firstmustbetranslatedintoaforminwhichitcanbeexecutedbya
computer.Thesoftwaresystemsthatdothistranslationarecalledcompilers.
•Acompilerisaprogramthatcanreadaprograminonelanguage-the
sourcelanguage-andtranslateitintoanequivalentprograminanother
language-thetargetlanguage;Animportantroleofthecompileristo
reportanyerrorsinthesourceprogramthatitdetectsduringthe
translationprocess.
2

3

•If the target program is an executable machine-language program, it can then
be called by the user to process inputs and produce outputs.
4

Interpreter
Aninterpreterisanothercommonkindoflanguageprocessor.Insteadof
producingatargetprogramasatranslation,aninterpreterappearstodirectly
executetheoperationsspecifiedinthesourceprogramoninputssuppliedby
theuser.
5

•Themachine-languagetargetprogramproducedbyacompilerisusuallymuch
fasterthananinterpreteratmappinginputstooutputs.Aninterpreter,however,
canusuallygivebettererrordiagnosticsthanacompiler,becauseitexecutes
thesourceprogramstatementbystatement.
•Javalanguageprocessorscombinecompilationandinterpretation,asshownin
Fig.1.4.AJavasourceprogrammayfirstbecompiledintoanintermediateform
calledbytecodes.Thebytecodesaretheninterpretedbyavirtualmachine.A
benefitofthisarrangementisthatbytecodescompiledononemachinecanbe
interpretedonanothermachine,perhapsacrossanetwork.
6

7

Compiler & Interpreter
8

9

Interpreter Compiler
Translates program one
statement at a time.
Scans the entire
program and translates
it as a whole into
machine code.
It takes less amount of
time to analyze the
source code but the
overall execution time is
slower.
It takes a large amount
of time to analyze the
source code but the
overall execution time is
comparatively faster.
No intermediate object
code is generated,
hence are memory
efficient.
Generates intermediate
object code which
further requires linking,
hence requires more
memory.
Interpreter Compiler
Continues translating the
program until the first
error is met, in which
case it stops. Hence
debugging is easy.
It generates the error
message only after
scanning the whole
program. Hence
debugging is
comparatively hard.
Programming languages
like Python, Ruby use
interpreters.
Programming languages
like C, C++, Java use
compilers.
Difference between Interpreter and Compiler
10

Key Differences Between Compiler and Interpreter
Let’s look at major differences between Compiler and Interpreter:
1.Thecompilertakesaprogramasawholeandtranslatesit,butinterpretertranslatesa
programstatementbystatement.
2.Intermediatecodeortargetcodeisgeneratedincaseofacompiler.Asagainst
interpreterdoesn’tcreateintermediatecode.
3.AcompileriscomparativelyfasterthanInterpreterasthecompilertakethewhole
programatonegowhereasinterpreterscompileeachlineofcodeaftertheother.
4.Thecompilerrequiresmorememorythaninterpreterbecauseofthegenerationof
objectcode.
5.Compilerpresentsallerrorsconcurrently,andit’sdifficulttodetecttheerrorsin
contrastinterpreterdisplayerrorsofeachstatementonebyone,andit’seasierto
detecterrors.
6.Incompilerwhenanerroroccursintheprogram,itstopsitstranslationandafter
removingerrorwholeprogramistranslatedagain.Onthecontrary,whenanerrortakes
placeintheinterpreter,itpreventsitstranslationandafterremovingtheerror,
translationresumes.
11

7.Inacompiler,theprocessrequirestwostepsinwhichfirstlysourcecodeistranslatedto
targetprogramthenexecuted.WhileinInterpreterIt’saone-stepprocessinwhichSource
codeiscompiledandexecutedatthesametime.
8.ThecompilerisusedinprogramminglanguageslikeC,C++,C#,Scala,etc.Ontheother
InterpreterisemployedinlanguageslikePHP,Ruby,Python,etc.
12

WeknowacomputerisalogicalassemblyofSoftwareandHardware.The
hardwareknowsalanguage,thatishardforustounderstand,consequentlywe
tendtowriteprogramsinhigh-levellanguage,thatismuchlesscomplicatedforus
tocomprehendandmaintaininthoughts.Nowtheseprogramsgothroughaseries
oftransformationsothattheycanreadilybeusedinmachines.Thisiswhere
languageproceduresystemscomehandy.
13
Language ProcessingSystem

Language ProcessingSystem
14

•HighLevelLanguage–Ifaprogramcontains#defineor
#includedirectivessuchas#includeor#defineitiscalledHLL.
Theyareclosertohumansbutfarfrommachines.These(#)
tagsarecalledpre-processordirectives.Theydirectthepre-
processoraboutwhattodo.
•Pre-Processor–Thepre-processorremovesallthe#include
directivesbyincludingthefilescalledfileinclusionandallthe
#definedirectivesusingmacroexpansion.Itperformsfile
inclusion,augmentation,macro-processingetc.
•AssemblyLanguage–Itsneitherinbinaryformnorhigh
level.Itisanintermediatestatethatisacombinationof
machineinstructionsandsomeotherusefuldataneededfor
execution.
•Assembler–Foreveryplatform(Hardware+OS)wewillhave
aassembler.Theyarenotuniversalsinceforeachplatformwe
haveone.Theoutputofassembleriscalledobjectfile.Its
translatesassemblylanguagetomachinecode.
15

•Interpreter–Aninterpreterconvertshighlevellanguageinto
lowlevelmachinelanguage,justlikeacompiler.Buttheyare
differentinthewaytheyreadtheinput.TheCompilerinonego
readstheinputs,doestheprocessingandexecutesthesource
codewhereastheinterpreterdoesthesamelinebyline.
Compilerscanstheentireprogramandtranslatesitasawhole
intomachinecodewhereasaninterpretertranslatesthe
programonestatementatatime.Interpretedprogramsare
usuallyslowerwithrespecttocompiledones.
•RelocatableMachineCode–Itcanbeloadedatanypointand
canberun.Theaddresswithintheprogramwillbeinsucha
waythatitwillcooperatefortheprogrammovement.
•Loader/Linker–Itconvertstherelocatablecodeintoabsolute
codeandtriestoruntheprogramresultinginarunning
programoranerrormessage(orsometimesbothcanhappen).
Linkerloadsavarietyofobjectfilesintoasinglefiletomakeit
executable.Thenloaderloadsitinmemoryandexecutesit.
16

THANK YOU
17