Translation and Errors Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Translator

A

A program that converts source code into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do compilers do?

A

They take the whole source code and translate it into machine code all in one go. Once converted, the object code can be run unassisted at any time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the advantages of compilers?

A

Compiled programs run quickly, because they’ve already been translated.

A compiled program can be supplied as an executable file. An executable file is a file that is ready to run. Since an executable file cannot be easily modified, programmers prefer to supply executables rather than source code.

Compilers optimise code. Optimised code can run quicker and take up less memory space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the disadvantages of compilers?

A

Because the source code is translated as a whole, there must be enough memory space to hold the source code, the compiler and the generated object code. There also needs to be temporary working space for the compiler to perform the translation. Modern systems either have enough memory or use virtual memory to hold all the data.

Source code compiled on one platform will not run on another - the machine code is specific to the processor’s architecture.

The source code must be re-compiled every time the programmer changes the program.

Compilers do not usually spot errors - the program has to be compiled and run before errors are encountered. This makes it harder to see where the errors lie.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an interpreter?

A

An interpreter translates source code into machine code one instruction at a time (one line at a time). The resulting machine code is then executed immediately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the advantages of interpreters?

A

Instructions are executed as soon as they are translated.

Errors can be quickly spotted - once an error is found, the program stops running and the user is notified at which part of the program the interpretation has failed. This makes interpreters extremely useful when developing programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the disadvantages of interpreters?

A

Interpreted programs run slowly as the processor has to wait for each instruction to be translated before it can be executed.

Additionally, the program has to be translated every time it is run.

Interpreters do not produce an executable file that can be distributed. As a result, the source code program has to be supplied, and this could be modified without permission.

Interpreters do not optimise code - the translated code is executed as it is.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an assembler?

A

Assemblers are a third type of translator. The purpose of an assembler is to translate assembly language into machine code.

Assemblers create one machine code instruction for each assembly instruction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Name the stages of compiling a program.

A
lexical analysis
symbol table construction
syntax analysis
semantic analysis
code generation
optimisation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens in lexical analysis?

A

Comments and unnecessary spaces are removed.

Keywords, constants and identifiers are replaced by ‘tokens’, which are symbolic strings to identify what the elements are.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens in symbol table construction?

A

A table stores the names and addresses of all variables, constants and arrays.

Variables are checked to make sure they have been declared and to determine the data types used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens in syntax analysis?

A

Tokens are checked to see if they match the syntax of the programming language.

If syntax errors are found, error messages are produced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What happens in semantic analysis?

A

Variables are checked to make sure they have been correctly declared and contain the correct data type.

Operations are checked to ensure that they are appropriate for the type of variable being used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens in code generation?

A

Machine code is generated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is optimisation?

A

Code optimisation makes the program more efficient so it runs faster and uses fewer resources.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Name all the types of errors that can occur when writing programs.

A
syntax
runtime/execution
logical
linking
rounding
truncation
17
Q

What is a syntax error?

A

A syntax error is an error in the rules of a sequence of characters that have been written in a particular programming language.

For example, there could be a missing speech mark or bracket, or a grammatical symbol such as a semicolon or equals sign may be included where it is not expected.

18
Q

What is a runtime/execution error?

A

These are errors that occur only during the execution of a program.

Errors include running out of memory.

19
Q

What is a logical error?

A

These occur when the program is running, specifically when there is a problem with the logic.

This might be using the < symbol instead of the > symbol, or using AND instead of OR.

Logical errors might not cause an error message or stop a program from running, so they can be hard to find.

20
Q

What is a linking error?

A

A linking error occurs when a function or library that is needed by the program cannot be found.

This might be because it has not been imported or because a file has been moved.

21
Q

What is a rounding error?

A

A rounding error is the difference between the number that is stored by a computer program and the actual number. Data types are often limited in the number of decimal places that they can store so a rounding error might occur if a number needs to be cut short.

An example of this is pi (π) being limited to 3.14 when it is rounded to two decimal places.

22
Q

What is a truncation error?

A

Similar to a rounding error, a truncation error is when a large number is reduced to fit a data type. The difference between rounding and truncation is that truncation cuts off the extra decimal places without changing the final digit.

For example, 5.369 rounded to two decimal places is 5.37, but when truncated to two decimal places it is 5.36.