Component 1.8 - Program Construction (Finished) Flashcards
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