Stages of Compilation Flashcards
(6 cards)
What is compilation?
process that translates a program written in a high level language into machine code
What are the four stages in compilation?
Lexical Analysis
Syntax Analysis Code Generation Optimisation
What happens in Lexical analysis
This stage involves identifying lexical ‘tokens’ in the code such as while, if etc.
White space and comments are ignored completely
What happens in code generation?
Takes the Abstract syntax tree and traverses it to generate object code that can be executed by the computer
What happens in syntax analysis?
Makes sure all tokens follow the syntax rules of the language.
Flag up any errors.
If the code passes the syntax analysis then the compiler creates an Abstract Syntax Tree
What happens in optimisation?
modifies the code to make it more efficient without changing its functionality.
it reduces the memory required to run the code, which leads to faster execution.
for example removing duplicate code