translators interpreters and compilers

15
The Functions and The Functions and Purposes of Purposes of Translators Translators Translators, Translators, Interpreters and Compilers Interpreters and Compilers - High Level Languages - High Level Languages

Upload: chazzverma

Post on 23-May-2017

249 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Translators Interpreters and Compilers

The Functions and The Functions and Purposes of TranslatorsPurposes of Translators

Translators,Translators,Interpreters and CompilersInterpreters and Compilers

- High Level Languages- High Level Languages

Page 2: Translators Interpreters and Compilers

Learning ObjectivesLearning Objectives

Describe, with the aid of examples, the characteristics of high level languages.Explain the need for translators.Describe the difference between interpretation and compilation.

Page 3: Translators Interpreters and Compilers

Machine CodeMachine CodeComputers work and understand only machine Computers work and understand only machine code.code.Simple instructions represented by a binary Simple instructions represented by a binary pattern in the computer. pattern in the computer. Programming in machine code takes a long time Programming in machine code takes a long time and is prone to errors.and is prone to errors.Each instruction contains a code for the Each instruction contains a code for the operation to be carried out and a binary operation to be carried out and a binary representation of the value to be representation of the value to be manipulated/address of the value to be manipulated/address of the value to be manipulated manipulated e.g. e.g. 0100 01010100 0101

– – where 0100 means “Jump” and 0101 is the address to jump to.where 0100 means “Jump” and 0101 is the address to jump to.

Page 4: Translators Interpreters and Compilers

Assembly LanguageAssembly Language

Developed to improve program writing. Developed to improve program writing. Use of mnemonics for machine code instructions Use of mnemonics for machine code instructions and names for locations in memory. and names for locations in memory. Each assembly instruction represents a single Each assembly instruction represents a single machine instruction which means that it is fairly machine instruction which means that it is fairly easy to translate a program written in assembly easy to translate a program written in assembly language to machine code. language to machine code. Assemblers which are loaded into the computer Assemblers which are loaded into the computer translate the assembly language to machine code. translate the assembly language to machine code. Writing programs in assembly language, although Writing programs in assembly language, although easier than using machine code, is still tedious and easier than using machine code, is still tedious and takes a long time.takes a long time.

Page 5: Translators Interpreters and Compilers

HHigh - igh - LLevel evel LLanguages (anguages (HLL)HLL)Similar to human languages and developed for Similar to human languages and developed for specific applications. specific applications. FORTRAN (FORmula TRANslation) developed for FORTRAN (FORmula TRANslation) developed for

science and engineering programs and it used science and engineering programs and it used formulae in the same way as would scientists and formulae in the same way as would scientists and engineers. engineers.

COBOL (Common Business Oriented Language) was COBOL (Common Business Oriented Language) was developed for business applications.developed for business applications.

Much easier for humans to program in HLL but Much easier for humans to program in HLL but as computers only understand machine code as computers only understand machine code programs written in HLLs need to be translated programs written in HLLs need to be translated into machine code before they can be executed.into machine code before they can be executed.

Page 6: Translators Interpreters and Compilers

CompilerCompilerTranslate high-level languages into machine code.Translate high-level languages into machine code.The machine code version can be loaded into the machine The machine code version can be loaded into the machine and run without any further help as it is complete in itself. and run without any further help as it is complete in itself. The high-level language version of the program is called The high-level language version of the program is called the source code and the resulting machine code program the source code and the resulting machine code program is called the object code. is called the object code.

Page 7: Translators Interpreters and Compilers

Disadvantages Of CompilersDisadvantages Of Compilers

Use a lot of computer resources. Use a lot of computer resources. Has to be loaded in the computer's memory at Has to be loaded in the computer's memory at the same time as the source code and there has the same time as the source code and there has to be sufficient memory to hold the object code. to be sufficient memory to hold the object code. Has to be sufficient memory for working storage Has to be sufficient memory for working storage while the translation is taking place. while the translation is taking place. Errors in the original program are difficult to pin-Errors in the original program are difficult to pin-point.point.

Page 8: Translators Interpreters and Compilers

InterpretersInterpretersTake each instruction in turn and translates it Take each instruction in turn and translates it into machine code. into machine code. Executes the translated instruction before the Executes the translated instruction before the next instruction is translated. next instruction is translated.

Page 9: Translators Interpreters and Compilers

InterpretersInterpretersAdvantages:Advantages:

Need less memory than compilers (useful in early Need less memory than compilers (useful in early computers which had limited power and memory).computers which had limited power and memory).

Continual compilation of whole code is wasteful / time Continual compilation of whole code is wasteful / time consuming during testing particularly if very minor consuming during testing particularly if very minor changes have been made.changes have been made.

During testing translator diagnostics will be more During testing translator diagnostics will be more complete as error messages will be produced in complete as error messages will be produced in relation to the HLL being used and not the machine relation to the HLL being used and not the machine code.code.

As each error message is produced on the line where As each error message is produced on the line where the error was encountered, it is easier to identify / the error was encountered, it is easier to identify / isolate the instruction which is causing the problem.isolate the instruction which is causing the problem.

Individual segments can be run without needing Individual segments can be run without needing compile the whole program.compile the whole program.

Page 10: Translators Interpreters and Compilers

InterpretersInterpreters

Disadvantages:Disadvantages: Slow execution compared to that of a Slow execution compared to that of a

compiled program because:compiled program because:The original program has to be translated every The original program has to be translated every time it is executed. time it is executed. Instructions inside a loop have to be translated Instructions inside a loop have to be translated each time the loop is entered.each time the loop is entered.

Page 11: Translators Interpreters and Compilers

Interpreters & CompilersInterpreters & Compilers

Many high-level languages use both. Many high-level languages use both. Programmers use the interpreter during Programmers use the interpreter during program development and, when the program development and, when the program is fully working, use a compiler to program is fully working, use a compiler to translate it into machine code. translate it into machine code. This machine code version can then be This machine code version can then be distributed to users who do not have distributed to users who do not have access to the original code.access to the original code.

Page 12: Translators Interpreters and Compilers

PlenaryPlenary

Why does a program, written in a high Why does a program, written in a high level language, need to be translated level language, need to be translated before it can be run on a computer?before it can be run on a computer?

Page 13: Translators Interpreters and Compilers

PlenaryPlenary

Computers only understand binary.Computers only understand binary.HLL is written in language close to HLL is written in language close to human language.human language.Translator needed to turn one into the Translator needed to turn one into the other.other.

Page 14: Translators Interpreters and Compilers

PlenaryPlenary

Describe the difference between Describe the difference between interpretation and compilation.interpretation and compilation.

Page 15: Translators Interpreters and Compilers

PlenaryPlenary

Interpreter translates line of code and Interpreter translates line of code and then runs it.then runs it.Compiler translates entire program Compiler translates entire program before run.before run.Compiler creates an object code.Compiler creates an object code.Interpreter retains source code.Interpreter retains source code.Compiler must be present for translation.Compiler must be present for translation.Interpreter must be present for run.Interpreter must be present for run.