Stages of compilation Flashcards

1
Q

What are the 4 stages of compilation in order?

A
  • Lexical analysis
  • Syntax analysis
  • Code generation
  • Code optimisation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What happens in lexical analysis of code?

A

The lexer analyses lexemes (words) in the source code, checks if it is valid against a pre defined set of rules and identifies the lexeme with a token (e.g. key words, constants, strings, numbers, operators…)
It then puts these tokens into a symbol table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens in syntax analysis of code?

A

Tokens from lexical analysis are received as inputs, the structure of the inputs are then analysed to ensure it is syntactically correct.
It then builds a parse tree (syntax tree) and updates the symbol table with data types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens in code generation?

A

Machine code is generated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens in code optimisation?

A

The code is analysed to spot:
- Spotting redundant instruction that can be replaced in a more efficient way
- Removing subroutines that are never called
- Removing variables and constants that are never referenced

How well did you know this?
1
Not at all
2
3
4
5
Perfectly