1.2.2.e Stages of Compilation Flashcards

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

What does source code need to be?

A

Close to the English language
Easy to read, modify, and interpret.

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

What does a processor need to convert source code to, and what is this process called?

A

The machine code needs to be converted into machine code, by a translator. This is called compilation, and is carried out by a compiler.

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

What are the 4 stages of compilation?

A

Stage 1 - Lexical Analysis
Stage 2 - Syntax Analysis
Stage 3 - Code Generation
Stage 4 - Code Optimisation

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

Summarise the lexical analysis stage of compilation.

A

Comments and white spaces are removed.
Remaining code turned into tokens.
Symbol table is created to keep track of variables and subroutines.

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

Summarise the syntax analysis stage of compilation.

A

Parse tree is built from tokens.
Errors are generated is any tokens break syntax of the language.

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

Summarise the code generation stage of compilation.

A

Parse tree converted to object code, which is the machine code before the linker is run.

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

Summarise the code optimisation stage of compilation.

A

Code is tweaked so it will be time and memory efficient.

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

Describe the stages of lexical analysis.

A

1) The lexer starts by converting lexemes in the source code into a series of tokens.
2) When the lexer encounters a whitespace, operator symbol, or special symbol, it decides that a word (lexeme) is complete.
3) The lexer checks if each lexeme is valid using its predefined set of rules. This allows every lexeme to be identified as a valid token.
4) Token streams are created from the token class (from the predefined rules) and the lexeme, and these are inputted into a symbol table.

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

What would be considered to be a token class within the predefined set of rules?

A

Keywords, constants, identifiers, strings, numbers, operators, punctuation, Quotes, Boolean, Datatypes, Identifiers are all examples of token classes.

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

Give an example of what a token would look like. (The format).

A

[Token class: lexeme/token]
Many of these tokens create a token stream.

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

What are the side effects, or the consequences, or lexical analysis?

A

White spaces and comments are removed from source code.

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

What would a symbol table look like?

A

[Index] [Token] [Token Class] [Datatype]

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

What is the advantage of multiple symbol tables being created?

A

It allows variables to have the same name in a program, but allows each variable to have a different scope within the program.

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

What else could be created in addition to the symbol table, and what is the advantage of this?

A

A strings table could be created.
It makes later stages of compilation more efficient.

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

Why is the symbol table usually stored as a hash table?

A

Using a hash table means that hashing can be used as the indexing. This allows for efficient lookup during the syntax analysis stage.

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