0% found this document useful (0 votes)
13 views21 pages

5.2 Language Translators 1

The document discusses language translators, including assemblers, compilers, and interpreters, highlighting their functions, benefits, and drawbacks. It explains how assemblers convert assembly language to machine code, compilers translate high-level languages into machine code, and interpreters execute high-level code line by line without generating machine code. Additionally, it covers Integrated Development Environments (IDEs) that support programming through features like error detection, debugging, and code presentation.

Uploaded by

jaibirminecraft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views21 pages

5.2 Language Translators 1

The document discusses language translators, including assemblers, compilers, and interpreters, highlighting their functions, benefits, and drawbacks. It explains how assemblers convert assembly language to machine code, compilers translate high-level languages into machine code, and interpreters execute high-level code line by line without generating machine code. Additionally, it covers Integrated Development Environments (IDEs) that support programming through features like error detection, debugging, and code presentation.

Uploaded by

jaibirminecraft
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

5.

2 LANGUAGE
TRANSLATORS
5 – SYSTEM SOFTWARE
LANGUAGE TRANSLATORS – PRE-TOPIC UNDERSTANDING

Key Terms:
 Translator  Single

 Compiler
stepping
 Breakpoint
 Interpreter
 Report
 Assembler
window
 Prettyprintin
g
 IDE

 Syntax error

 Logic error

 Debugging
LANGUAGE TRANSLATORS – HIERARCHY
LANGUAGE TRANSLATORS – ASSEMBLER
 Assembly language is a low-level
programming language based on
mnemonics that allow the programmer to
communicate efficiently with hardware.
 Assemblers translate assembly language
into machine code (binary).
 Translated programs are either stored
directly in main memory for immediate
execution or in secondary storage for later
use. A loader program is needed if stored in
the latter way.
 Stored translated programs do not need to
be translated for each use. What is machine code? – Machine code is
binary. Everything we see on the computer
 Each chip has its own machine code and
screen has to be translated into binary at some
assembly language and are not portable
stage so that the processor can understand.
from device to device.
LANGUAGE TRANSLATORS – COMPILERS
 Compilers translate whole programs written in
high-level languages into machine code.
 Compilers often store a translated program onto a
storage medium for later use.
 A loader program is required to load the stored
program, but once the program is translated, it
can be executed many times without retranslation.
 If changes are made to the source code, the
program will need to be retranslated.
 Compilers translate entire programs, but they still
analyse each line of code. If an error is found, it
is recorded otherwise the line is converted into
code. The compiler then moves on to the next line.
 Once the entire program is analysed either a list of
errors will be produced, or if no errors are found,
the source code is converted into object code.
LANGUAGE TRANSLATORS – INTERPRETERS

 Interpreters also work with high-level


languages, but translate and execute
programs line by line.
 No translated program is generated in main
memory, nor stored for later use.
 Each line in the program is interpreted and
then executed each time the program is run.
 If an error is found on a line, the interpreter
halts execution of the program.

NOTE – High-level language program are portable


between machines meaning they can be run on
any type of computer provided there is a compiler
or interpreter
LANGUAGE TRANSLATORS – COMPARISON

Assembler Compiler Interpreter


Source program Assembly language High-level language High-level language
written in…

Machine Yes No No
dependant?
(Portable?)
Object program Yes, stored on disk Yes, stored on disk No, instructions are
generated? or in main memory or in main memory executed under the
control of the
interpreter
Each line of One machine code Many machine code Many machine code
source code instruction, one to instructions, instructions,
generates… one translation instruction instruction
explosion explosion
LANGUAGE TRANSLATORS – COMPARISON
LANGUAGE TRANSLATORS – BENEFITS AND DRAWBACK OF
COMPILERS AND INTERPRETERS
Compiler advantages Interpreter disadvantages

The end user only needs the executable code – End user will need to purchase a compiler or
benefitting end user interpreter to translate the source code before use
The developer keeps the source code so it cannot The developer relinquishes control of the source
be altered or extended by the end user – benefitting code, making it more difficult to charge for
developer as upgrades and alterations can be upgrades and alterations. IP could be abused by
charged for end user
Shorter amount of time to execute as translation Can take longer to execute as each line must be
has been completed and machine code generated translated before execution every time the program
and possibly optimised is run
No syntax or semantic errors May still contain syntax or semantic errors if part of
the program has not been fully tested – will require
debugging
Source program can be translated on one type of Cannot be translated on one type of computer and
computer and then executed on another type of run on another
computer
LANGUAGE TRANSLATORS – BENEFITS AND DRAWBACK OF
COMPILERS AND INTERPRETERS
Compiler disadvantages Interpreter advantages

Finds ALL errors in a program. One error detected Easier to develop and debug programs as errors can
can mean that other dependant errors are found be corrected on each line and the program
later in the program that will not be errors when the restarted from that place
first is corrected. Number of errors found may be
more than actual number of errors
Untested programs with errors may cause the Untested programs with errors should not cause the
program to crash program to crash
The developer needs to write special routines in Partial results can be viewed in development,
order to view partial results during development enabling the developer to make informed decisions
making it more difficult to assess the quality of about a section of code, for example, whether to
particular code sections continue, modify, scrap or start again.
End users do not have access to the source code End users have all the source code and libraries
and libraries, meaning they are unable to make enabling the program to be modified as required
modifications and are reliant on the developer for without further payment to the developer
edits and upgrades
LANGUAGE TRANSLATORS – BENEFITS AND DRAWBACK OF
COMPILERS AND INTERPRETERS
LANGUAGE TRANSLATORS – BENEFITS AND DRAWBACK OF
COMPILERS AND INTERPRETERS
LANGUAGE TRANSLATORS – PARTIAL COMPILING AND
INTERPRETING
To reduce execution times, some HLL use virtual machines that allow for partial compilation and partial
interpretation. This is done by:
 Source code is checked and translated by compiler into object code.

 This object code is low-level machine independent code call intermediate code, p-code or bytecode.

 To execute this program either a compiler or interpreter can be used.

In Java and Python, programs are compiled into a set of instructions for a virtual machine. These bytecode
instructions are then interpreted.

Source code: This is a sample piece of


print (“Hello World”) source code written in Python
and its corresponding
Bytecode: bytecode.
1 0 LOAD_NAME 0 (print)
2 LOAD_CONST 0 (‘Hello World’)
VB also has an interpreter for
4 CALL_FUNCTION 1 (1 positional, 0 keyboard pair)
bytecode. Try to find or work
6 RETURN_VALUE
out the VB bytecode for the
LANGUAGE TRANSLATORS – PARTIAL COMPILING AND
INTERPRETING (JAVA)
LANGUAGE TRANSLATORS – PARTIAL COMPILING AND
INTERPRETING (JAVA)
LANGUAGE TRANSLATORS – INTEGRATED DEVELOPMENT
ENVIRONMENT (IDE)
The IDE is used by programmers to support the development of programs and there are many
options available that can specialise in one or many languages.

Some examples are:


 NetBeans

 PyCharm

 Visual Studio

 SharpDevelop

 BlueJay

TASK: In small groups, spend five minutes looking up the features of these or other IDEs. Compare in
your groups and report back to the class after. Consider differences and similarities.
LANGUAGE TRANSLATORS – INTEGRATED DEVELOPMENT
ENVIRONMENT (IDE)
IDEs commonly allow for the following:
 Coding – including context-sensitive prompts

 Initial error detection – including dynamic syntax checks

 Presentation – including prettyprinting and collapsible code blocks

 Debugging – including single stepping and breakpoints


LANGUAGE TRANSLATORS – INTEGRATED DEVELOPMENT
ENVIRONMENT (IDE)
The source code editor is the space in which the programmer will write their code. This space usually
comprises of several useful features in the development of code. The interpreter will be used for
development and the compiler to produce the final version.

A prettyprinter is the appearance of code that is displayed in a colour coded system. Function calls,
comments, strings and identifiers can all be colour coded by a prettyprinter in an IDE. Prettyprinting also
incorporates automatic indentation where necessary. This makes presentation much more clear to
developers.

Context-sensitive prompts are also common features of an IDE. As the developer begins typing, a list of
related keywords or identifiers are displayed allowing the developer to save time by autocompleting a
line of code. Along with the prompted options, some IDEs also offer explanations to key commands.

One other common feature of an IDE in relation presentation is expanding and collapsing code blocks.
This avoids large amounts of scrolling and segments of code can be collapsed into tidy sections.
LANGUAGE TRANSLATORS – INTEGRATED DEVELOPMENT
ENVIRONMENT (IDE)
LANGUAGE TRANSLATORS – INTEGRATED DEVELOPMENT
ENVIRONMENT (IDE)
IDEs support programming development by way of error checking and debugging.

As the programmer is coding, the IDE will constantly run a dynamic syntax check. This system
highlights immediately any errors in spellings, punctuation or structure. Usually these errors will be
underlined or highlighted and hovering your mouse over the errors can display an explanation.

Many IDEs include debuggers. A debugger assists in finding logic errors in a program by tracing
through the algorithm. A debugger allows the programmer to single step through a program one
line at a time (single-stepping) or to set a breakpoint to stop the execution of a program.

A report window will then show the contents of variables and allow the programmer to check if the
program is running the way it is supposed to. Variables will be displayed with type and contents
and we can compare that to what we were expecting prior to debugging.
LANGUAGE TRANSLATORS – QUESTIONS

1 a i) Describe the difference between a compiler and an assembler


ii) Describe the difference between a compiler and an interpreter
b State two benefits and two drawbacks of using an interpreter.

2 A new program is to be written in a high-level language. The programmer has decided to use an
IDE to develop the new program.
a Explain what is meant by an IDE.
b Describe three features of an IDE.

You might also like