1.2.2.6 Stages of Compilation Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the 4 stages of compilation?

A

1) Lexical analysis

2) Syntax analysis

3) Code generation

4) Code optimisation

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

What happens in the lexical analysis stage?

A
  • The Lexer starts by converting lexemes from the source code into a series of tokens
  • Scanned spaces, symbols are taken as indicators that word is complete
  • It then checks if the lexeme is valid using a predefined set of rules that allow every lexeme to be identified as a valid token
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What can be considered a token?

A

Keywords, constants, identifiers, strings, numbers, operators and punctuation symbols

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

What happens in the syntax analysis stage?

A
  • Receives its inputs in the form of tokens from lexical analysers.
  • Analyses the syntactical structure of the input, checking if it is in the correct syntax of the programming language it has been written in.
  • It does this by analysing the token stream against production rules to detect any errors in the code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the syntax analysis accomplish?

A
  • Checking for errors and reporting them.
  • Building an abstract syntax tree (parse tree)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does code optimisation do?

A
  • Spotting redundant instructions and producing object code that achieves the same effect as the source program but not necessarily by the same means.
  • 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