Stages of compilation Flashcards

1
Q

What happens in the lexical analysis stage of compilation?

A

Converts Lexemes in the source code into a series of tokens

Scans code letter for letter

Remove whitespace and comments

Simple error checking - e.g illegal identifiers flagged as errors

Each line of code is read and each element is “tokenised”

Purpose of the code is identified.

Each token is added to a symbol table. The symbol table is used by the compiler to keep track of all the elements.

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

What happens in the syntax analysis stage of compilation?

A

Receives inputs in as tokens from the lexical analysis.

The compiler checks that the tokens are in the correct order and that they follow the rules of the programming language being used.

The syntax analysis will check for errors and report them and build an Abstract Syntax Tree.

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

What happens code generation stage of compilation?

A

The code that is generated in a binary representation of the source code, this is known as object code. This is the executable version of the code, before linked libraries are included.

Binary file is intended to be read by the computer.

Compilers generate a separate executable file whereas interpreters won’t.

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

What happens in the code optimisation stage of compilation?

A

At this stage, the compiler will identify redundant or repeated code, and remove or rearrange the code as necessary.

It will either support speed or memory optimisation as its very tricky to achieve both in real life programs.

Can increase compilation times.

It will

  Spot redundant instructions

  Remove subroutines that are                     never called

  Remove variables and constants that are never referenced.

  Remove unreachable code that   is never accessed (may be coded by programmer accidently).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly