Translators

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/28

flashcard set

Earn XP

Description and Tags

Made with Ada Comp. Sci. and P.M.T.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

29 Terms

1
New cards

Translator

Piece of software that converts a computer program into a form that can be executed by the processor

2
New cards

Types of translator

  • Interpreter

  • Compiler

  • Assembler

3
New cards

Interpreters and their translation process

  • Translates and executess each line of source code one by one. For each line:

    • Checks syntax, and if theres an error it is reported and the program halts

    • If no errors found, the line of code is converted to its machine code equivelent and is executed

    • If a runtime error occurs, the program crashes

4
New cards

Advantages of interpreters

  • Line-by-line approach allows quick identification and correction of each errors as it occurs, without having to translate the whole program each time.

    • This makes ____ very useful during developement of a program

  • More portable - the same source code (or byte code) can be executed on a range of platforms as long as the right ____ is available.

    • This makes them useful when the platform on which a program will run is unkown

5
New cards

Disadvantages of interpreters

  • Every time the program is run it must be translated again. This means it will run more slowly than an executable file produced by compilation.

  • Requires interpreter to be installed on the computer for the program to run

6
New cards

Compilers

  • Translates code all at once

  • Produce an executable file, but does not execute the code

  • Executable file produced is machine code suitable for a specific instruction set architecture

  • Errors reported at end of compilation process

7
New cards

Advantages of compilers

  • Once successfully compiled, the executable file wont neet to be tranlated again (unless the code is changed)

    • Code can be run without a translator being present

    • Executes more quickly than interpreted code once compiled

  • Provides protection of source code - useful for closed source software where you don’t want the source code to be publicly accessible

8
New cards

Disadvantages of compilers

  • Errors are reported at the end of the compilation process

    • Any erros require the program to be corrected and recompiled until no errors are present

  • Produces machine code specific to a processor type and operation system

9
New cards

Stages of compilation (first to last)

  • Lexical analysis

  • Syntax analysis

  • Code generation

  • Code optimisation

10
New cards

What happens in lexical analysis

  • Non-program elements (e.g. comments & whitespace) are removed

  • Reserved words / keywords are tokenized

  • Identifier names are added to a symbol table - this allows the compiler to keep track of all the identifiers that have been declared in the program

11
New cards

What happens in syntax analysis

  • Checks code tokens follow the grammatical rules of the language

  • An abstract syntax tree is created

    • Can be used to check no code tokens are missing

  • Checks code tokens are in correct order

  • If a syntax error is found it is added to a list of erros and will be reported at the end of compilation. Error diagnostics will be given with the list.

  • Adds detail to the symbol table - e.g. data type or scope of variable

  • Semantic analysis occurs - highlights certain types of logic errors in the program (e.g. list index is out of range)

12
New cards

Abstract syntax tree

  • Maps the structure of the program

  • Used to check syntax is correct

  • Dependant on syntax so is different for each programming language

13
New cards

Code generation

  • Abstract syntax tree is used to creates object code

14
New cards

Object code

  • Binary represeentation of source code

  • Executable file before linked libraries have been included

15
New cards

Code optimisation

  • Occurs throughout compilation process, but especially in the code generation stage

  • May identify redundant or repeated code

  • Can remove and rearrange code as necessary

16
New cards

Purpose of code optimisation

  • To make the program run faster/ code is more efficient

  • To make the program use fewer resources/less memory

17
New cards

Assemblers and their translation process

  • Translate assembly code into executable code

  • Assembly code is platform specifc and as such ____ are as well

  • Code is translated on an almost one to one basis - each line of assembly code is equivelent to almost one line of machine code

  • Comments in the assembly program are removed

  • Symbolic references are replaced with actual addresses

18
New cards

Linkers

Piece of code the links programs to software libraries to create a single executable file

19
New cards

Static linker

  • Combines code and libraries directly into one file. This increases the size of the file

  • External updates to libraries wont affect the program - this allows specific versions of a library to be used

20
New cards

Dynamic linker

  • Adds the addresses to libraries (and modules) where they are used in the executable file

  • Keeps the file size small and allows external updates to libraries to feed through to the main file

21
New cards

Why are linkers needed?

  • The user running the program will not necessarily have the library installed on their machine

  • Therefore the relevant code needs to be included within the final executable

  • It is the job of the linker to combine this code.

22
New cards

Loaders

  • Provided by the operating system

  • When the program is executed, the ____ :

    • Copies the executable code from secondary storage into main memory

    • Loads the required software libraries

23
New cards

(Software) Libraries

  • Sections of code written by other authors containing useful routines

  • Are often precompiled

24
New cards

Advantages of useing libraries

  • Saves time as there is no need to rewrite code

  • Allows you to use the expertise of others to…

    • … complete tasks that require specialist knowledge

    • … abstract away complexity

  • If it’s from a reliable source, it has usually been thoroughly tested and therefore is efficient and reliable. This:

    • Makes debugging easier

    • Saves time

25
New cards

Disadvantages of libraries

  • May (significantly) increase size of compiled file as library contains many routines that aren't being used.

  • Not written by the programmer so introduces uncertainty.

    • Programmer needs to spend time familiarising themselves with it

    • May require further testing

26
New cards

What is bytecode / intermediate code

  • Source code that has been compiled into low-level code designed to be run on a virtual machine (the interpreter).

  • It is partially compiled code

27
New cards

How is byte code / intermdediate code used

  • The source code is compiled into low-level ____

  • This can then be executed by any machine that has the suitable virtual machine (interpreter) installed on it

  • As such the ____ can be distributed as a ready to run program

28
New cards

Advantages of bytecode / intermediate code

  • Speeds up translation process

  • Executable on a wide range of platforms as long as suitble virtual machine (interpreter) is installed on the machine

29
New cards

Disadvantages of bytecode / intermediate code

  • Slower execution than fully compiled code

  • Less protection of source code that fully compiled language