Stages of Compilation Flashcards
What are the four stages of compiling a program
Lexical Analysis
Syntax Analysis
Code Generation
Code Optimisation
Explain the lexical analysis stage
Remove white space
Create tokens from the code
Add all the tokens into a symbol table.
Explain the Syntax analysis stage
The tokenised code from the lexical analysis is compared to the rules of the programming language.
If a part of the code is found to not fit, an error is generated.
A full error report is given to the user once all of the errors are found.
Explain the code generation stage
Once the code has successfully passed the first two stages, it’s time to generate the code.
Generate object or machine code.
Explain the code optimisation stage
After the code is generated, it is optimised for efficiency.
The purpose is to make the binary footprint as small as possible and remove procedures and variables that are written into the code, but never used.