11.1 Compilers Flashcards

1
Q

What is the purpose of a compiler

A

Translates source code into machine code

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

What are the 3 components of a compiler (and their functions)

A

Pipeline as follows:

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

Why may it be useful to break up a compiler into separate parts

A

Allows it to be maintained separately and reused on different platforms etc.

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

What are the 2 parts of a compiler front-end and their function

A
  1. Lexer => Tokens (symplify parsing stage)
  2. Parser => builds AST (intermediate representation) and symbol table
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the lexer responsible for (and what are tokens)

A
  • Lexer: Breaks program into semantic tokens (reading character by character, ignoring whitespace and comments)
  • Tokens: smallest unit of meaning within program (ie words of the language)
  • Tokens may be labeled based on meaning
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the Parser responsible for (and what is the difference between statement and expression)

A
  • Parser: Builds abstract syntax tree from tokens
  • Statement: No return val ie while. Expressions ie arithmatic expr.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What would the AST for this look like

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

How does a recursive decent parser work?

A
  • Program is a series of statements
  • Recursively expand statement into parts
  • Build AST
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is some example psuedocode for a recursive descent parser

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

What is a symbol table and its use (parser)

A
  • Keep track of variable names and scope to avoid context
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the purpose of the compiler backend / what does it do

A
  • Intermediate rep (ie AST) => Machine Code (object files in binary, use linker to link together)
  • Optimisations (best ISA instructions, ordering etc.)
  • Memory allocation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are some potential compiler backend optimisations

A
  • Pipelining
  • Ordering
  • Instruction choice
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the concept of bootstrapping (compilers)?

A
  • Creating a compiler that can compile itself
  • Ie how to make the first compiler for lang / arch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Tombstone diagram (for bootstrapping)

A
  • Shows source to output process (using compiler written in implementation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How would you bootstrap a compiler for hex-8 (show using tombstone diagram)

A
  • Create minimal compiler in Hex 8 assembly (perhaps only subset of features)
  • Use that to compile the X compiler
  • Use X compiler to compile itself (good for testing and self optimisation)
  • Can now create new versions of X compiler to add more features using itself.
  • Can now compile from X to Hex-8
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Outline how cross compiling works (use Tombstone diagrams)

A
  • Cross-compiling is used for new atchitectures
  • Cross compiler runs on old architecture and builds compiler binary for new architecture
  • Can then use that compiler to recompile itself