Stages of compilation Flashcards
What happens in the lexical analysis stage of compilation?
Converts Lexemes in the source code into a series of tokens
Scans code letter for letter
Remove whitespace and comments
Simple error checking - e.g illegal identifiers flagged as errors
Each line of code is read and each element is “tokenised”
Purpose of the code is identified.
Each token is added to a symbol table. The symbol table is used by the compiler to keep track of all the elements.
What happens in the syntax analysis stage of compilation?
Receives inputs in as tokens from the lexical analysis.
The compiler checks that the tokens are in the correct order and that they follow the rules of the programming language being used.
The syntax analysis will check for errors and report them and build an Abstract Syntax Tree.
What happens code generation stage of compilation?
The code that is generated in a binary representation of the source code, this is known as object code. This is the executable version of the code, before linked libraries are included.
Binary file is intended to be read by the computer.
Compilers generate a separate executable file whereas interpreters won’t.
What happens in the code optimisation stage of compilation?
At this stage, the compiler will identify redundant or repeated code, and remove or rearrange the code as necessary.
It will either support speed or memory optimisation as its very tricky to achieve both in real life programs.
Can increase compilation times.
It will
Spot redundant instructions Remove subroutines that are never called Remove variables and constants that are never referenced. Remove unreachable code that is never accessed (may be coded by programmer accidently).