Stages of compilation Flashcards
Lexical Analysis
In the first stage of compilation, whitespace and comments are removed from the code.
The remaining code is analysed for keywords and names of variables and constants. These are replaced with tokens and information about the token associated with each keyword or identifier is stored in a symbol table.
Syntax Analysis
In this stage, tokens are analysed against the grammar
and rules of the programming language. Any tokens that break the rules of the programming language are flagged up as syntax errors and added to a list of errors.
eg : undeclared variable type, incomplete set of brackets.
Code Generation
The abstract syntax tree produced in the syntax analysis stage is used to produce machine code.
Optimisation
searches through the code for areas it could be made more
efficient. The aim of optimisation is to make the code faster to execute although this stage can significantly add to the overall time taken for compilation.