1.2.2 stages of compilation Flashcards
What are the four stages of compilation?
- lexical analysis
- syntax analysis
-code generation and optimisation
What is a lexer?
A lexer is a program that convert source into tokens, which are the smallest syntactic unit of a language.
what does the lexer do?
- it scan the source letter by letter, when it counter a white space, operator symbol or special symbol, it decide that the work is complete.
- it check each word to see if it valid as a token using pre identified rules.
what happens Syntax analysis section
- it receive it input as tokens from lexical analysis.
- check the syntactical structure of the input checking if it is in the correct syntax.
- it does this by analysing tokens against production rules.
What happen when the tokens are analysed against production rules?
2 things are accomplished:
- check for errors and reporting them.
- building an abstract syntax tree.
what happen in optimisation phase?
in this stage the compilation search for areas in the code where it can be more efficient.
optimisation aim to make the code execute faster although this stage add to the overall time taken.
what happens in Code generation?
the abstracted syntax tree is used to to produce machine code.