What is an assembler?
An assembler is a program that converts assembly code into machine code
How does does an assembler converts assembley code to machine code?
By converting one word assembley instructions into computer executable code (opcode) e.g. AND to 0010. It also allocates memory to variables
What does an interpreter do?
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.
What is an advantage of interpreters only showing an error when they hit the line it is on?
It makes the code easier to debug
What is the disadvantage of interpreted code compared to compiled code?
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.
What does a compiler do?
A compiler translates the whole program into machine code before the program is run
What are the four main stages of compilation?
Lexical analysis, syntax analysis, semantic analysis, code generation
What is done during the lexical analysis stage of compiling? (First stage)
- Comments + unneeded spaces removed
- Key words, constants, identifiers replaced by ‘tokens’
- Symbol table created holding variable addresses, labels and subroutines
What is done during the syntax analysis stage of compiling (second stage)?
- 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
What is done during the semantic stage of compiling? (Third stage)
- 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
What is done during the code generation stage of compiling? (Fourth stage)
- Machine code is generated
- Code optimisation can be employed
What does a translator do?
A translator changes a program written in one language to an equivalent program in a different language
Name 3 different computer errors?
Syntax, runtime, logical, linking, rounding, truncation
What is a syntax error?
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)
What is a runtime / exclusion error?
A runtime error is an error that occurs while a program is running. It is difficult to see before the program is compiled/run
Give an example of a runtime error?
The program requests more memory than available, crashing
What is a logical error?
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)
What is a linking error?
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
Give an example of a linking error?
When the randint function has been called but random library has not been imported/linked
What is a rounding error?
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)
What is a truncation error?
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