5.2 Language Translators 1
5.2 Language Translators 1
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
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.
In Java and Python, programs are compiled into a set of instructions for a virtual machine. These bytecode
instructions are then interpreted.
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
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
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.