Compilers Flashcards

1
Q

What is a compiler?

A

A language processor that translates a program written in some language into efficient, executable code.

Source language -> Target language - an undecidable problem!

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

What is a compiler responsible for?

A

Generate target program equivalent to source - preserve semantics.
Report errors.

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

What is the structure of a compiler?

A

Source program -> Preprocessor
Modified source program -> Compiler
Target assembly program -> Assembler
Relocatable machine code + Library files, relocatable object files -> Linker/Loader

-> Target machine code

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

What does the analysis (frontend) part of the compiler do?

A

Read + analyse source code.
Generate intermediate representation of code.

Errors reported at any stage.
Information gathered during process (e.g. type information) is stored in a symbol table.

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

What does the synthesis (backend) part of the compiler do?

A

Turns intermediate representation into target program, using symbol table.

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

What parts make up the frontend of the compiler?

A

Lexical Analysis
Syntax Analysis
Semantic Analysis
Intermediate Code Generation

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

What is lexical analysis?

A

Reads source code as stream of characters, grouping to lexemes.
Extracts tokens (name, value) from lexemes and stores in symbol table.

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

What is syntax analysis?

A

Parsing - reads stream of tokens and produces syntax tree.

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

What is semantic analysis?

A

Checks syntax tree is semantically correct w.r.t. language definition (e.g. type checking) - type info stored in symbol table.

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

What is intermediate code generation?

A

Generates low-level representation of code from syntax tree.
Representation must be easy to produce and generate to translate to target code.

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

What parts makeup the backend of the compiler?

A

Intermediate code optimization (some compilers)
Code generation
Code optimization

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

What is intermediate code optimization?

A

Machine-independent, e.g. eliminate type castings.

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

What is code generation?

A

Generate sequence of machine instructions from intermediate representation.
Typically includes selecting memory locations or registers for variables.

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

What is code optimization?

A

Tries to improve the performance of the generated code.

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

What are lexemes?

A

A sequence of characters.

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

What is a symbol table?

A

Data structure storing information about symbols (e.g. names and types of identifiers.)

17
Q

How do lexers find the longest match for a lexeme?

A

Keep track of the word the last time the Finite Automata was in a final state.

18
Q

How is a lexer built?

A

Given an ordered list of REs e1,…,en (capturing lexemes), and a
word w:
- Find longest prefix of w.
- Repeat until w is fully read.