1.2.2 stages of compilation Flashcards

1
Q

What are the four stages of compilation?

A
  • lexical analysis
  • syntax analysis
    -code generation and optimisation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a lexer?

A

A lexer is a program that convert source into tokens, which are the smallest syntactic unit of a language.

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

what does the lexer do?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what happens Syntax analysis section

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happen when the tokens are analysed against production rules?

A

2 things are accomplished:
- check for errors and reporting them.
- building an abstract syntax tree.

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

what happen in optimisation phase?

A

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.

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

what happens in Code generation?

A

the abstracted syntax tree is used to to produce machine code.

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