Topic 1.8 - Program Construction Flashcards
What is the function of translation programs?
The translation program converts the high level source code into low level assembly language (or machine code) ready for execution.
What is the purpose of an assembler?
An assembler converts code written in assembly language into object code (machine code or binary) ready for execution by the computer.
What is the difference between a compiler and an interpreter?
A compiler compiles all the code in one go by converting it from high level language to a file object code before executing. (Use for publishing and all-round)
An interpreter converts each line of code into machine code one at a time before executing it. After one line has been converted, the next line can be translated. (Usually used for debugging and testing)
What are the 4 stages of compilation?
- Lexical Analysis
- Syntax Analysis
- Semantic Analysis
- Code Generation
What happens during lexical analysis?
- Input stream broken into tokens
- Comments removed
- Necessary spaces are removed
- Error messages created if appropriate
What happens during syntax analysis?
- A symbol table/dictionary is created
- Tokens are checked against grammar rules (BNF)
- If tokens are invalid, error messages are produced
What happens during semantic analysis?
- Checks all variables are declared and used
- Checks that data of the appropriate data types are assigned to values declared as such data types
- Error messages produced if necessary
- Checks that all operations are legal (reverse polish notation is used)
What happens during code generation?
- Machine code is generated
- Code optimisation may take place
What is a subprogram library?
This is a library which contains subprograms and subroutines. The main program can then call these subroutines from the library by importing (linking) the library.
What is a link loader?
This is a piece of software which can load parts of programs stored in different locations and link them together.
Name and describe two translation errors
Syntax error - Where code has been written outside the grammar of the language
Run-time error - e.g Trying to divide by 0 when the program is running