F453 - functions and purpose of translators Flashcards
Describe assembly language
a language related closely to the computer being programmed/low level language/machine specific
uses descriptive names (for data stores)
uses mnemonics (for instructions)
uses labels to allow selection
each instruction is generally translated into one machine code instruction may use macros
Describe machine code
binary notation
set of all instructions available
to the architecture/which depend on the hardware design of the processor instructions operate on bytes of data
What tasks are performed by the assembler when producing machine code?
reserves storage for instructions and data
replaces mnemonic opcodes by machine codes
replaces symbolic addresses by numeric addresses
creates symbol table to match labels to addresses
checks syntax/offers diagnostics for errors
What are the features of the interpreter?
translates one line/statement…
…then allows it to be run before translation of next line reports one error at a time…
…nd stops
What are the features of a compiler?
translates the whole program as a unit
creates an executable program/intermediate program may report a number of errors at the same time optimisation
Describe lexical analysis
source program is used as the input
tokens are created from individual symbols and from…
…he reserved words in the program
a token is a fixed length string of binary digits
variable names are loaded into a look-up table / symbol table redundant characters (eg spaces) are removed
comments are removed
error diagnostics are given
prepares code for syntax analysis
What is the purpose of a translator?
convert from source code… …to object code
detect errors in source code
Why may intermediate code may be more useful than executable code?
can run on a variety of computers
same intermediate code can be obtained from different high level languages
improves portability
What additional software is needed to run intermediate code?
interpreter / virtual machine
What is a disadvantage of using intermediate code?
the program runs more slowly/has to be translated each time it is run / need additional software
What does code optimisation do?
makes code as efficient as possible increases processing speed reduces number of instructions
Describe syntax analysis
accepts output from lexical analysis
statements/arithmetic expressions/tokens are checked…
…against the rules of the language/valid example given eg matching brackets errors are reported as a list (at the end of compilation)
diagnostics may be given
(if no errors) code is passed to code generation
further detail is added to the symbol table…
…eg data type /scope/address
What’s intermediate code, and it’s use?
simplified code / partly translated code…
…which can be run on any computer/virtual machine/improves portability… …using an interpreter
sections of program can be written in different languages
runs more slowly than executable code
What software converts source code into object code?
translator
What is source code?
the original code/code written by the programmer… …often in a high level language
may be in assembly language
source code can be understood by people…
…but cannot be executed (until translated)