Component 1.8 - Program Construction (Finished) Flashcards

1
Q

What is an assembler?

A

An assembler is a program that converts assembly code into machine code

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

How does does an assembler converts assembley code to machine code?

A

By converting one word assembley instructions into computer executable code (opcode) e.g. AND to 0010. It also allocates memory to variables

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

What does an interpreter do?

A

An interpreter translates code into machine code, line by line ready to be executed by the CPU. The CPU executes each instruction before the interpreter moves on to translate the next instruction.

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

What is an advantage of interpreters only showing an error when they hit the line it is on?

A

It makes the code easier to debug

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

What is the disadvantage of interpreted code compared to compiled code?

A

An interpreter does not create an independent final set of source code - source code is created each time it runs so interpreted code is slower to execute than compiled code.

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

What does a compiler do?

A

A compiler translates the whole program into machine code before the program is run

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

What are the four main stages of compilation?

A

Lexical analysis, syntax analysis, semantic analysis, code generation

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

What is done during the lexical analysis stage of compiling? (First stage)

A
  • Comments + unneeded spaces removed
  • Key words, constants, identifiers replaced by ‘tokens’
  • Symbol table created holding variable addresses, labels and subroutines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is done during the syntax analysis stage of compiling (second stage)?

A
  • Tokens are checked to see if the expected spelling and grammar is matched (correct syntax used)
  • If syntax errors are found error messages are produced
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is done during the semantic stage of compiling? (Third stage)

A
  • Variables checked to ensure they were properly declared/used, and that they are of the correct type
  • Operations are checked to ensure that they are usable for the type of variable used
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is done during the code generation stage of compiling? (Fourth stage)

A
  • Machine code is generated

- Code optimisation can be employed

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

What does a translator do?

A

A translator changes a program written in one language to an equivalent program in a different language

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

Name 3 different computer errors?

A

Syntax, runtime, logical, linking, rounding, truncation

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

What is a syntax error?

A

A syntax error is an error that occurs when a command does not follow the expected syntax of the language (e.g. id not if)

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

What is a runtime / exclusion error?

A

A runtime error is an error that occurs while a program is running. It is difficult to see before the program is compiled/run

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

Give an example of a runtime error?

A

The program requests more memory than available, crashing

17
Q

What is a logical error?

A

A logical error is an error that causes a program to output an incorrect answer, which does not necessarily crash the program (e.g. age calculator gives -ive ages)

18
Q

What is a linking error?

A

A linking error is an error that occurs when a programmer calls a function within a program, but the correct library has not been linked

19
Q

Give an example of a linking error?

A

When the randint function has been called but random library has not been imported/linked

20
Q

What is a rounding error?

A

A rounding error is when a number is approximated to the nearest whole number/tenth/hundredth etc (e.g. 34.5 rounded up to 35)

21
Q

What is a truncation error?

A

errorA truncation error is when a number is approximated to a whole number/tenth etc nearer zero (e.g. 34.9 to 34). Put simply, the decimal point is chopped off ass opposed to rounding where it is rounded