Compilers Flashcards

1
Q

What are the three stages used with compilers

A

front end
optimiser
back end

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

what does the front end of compiling entail

A

converts source code into an intermediate representation

uses a lexer
uses a parser to build an abstract syntax tree
AST is an intermediate representation

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

what does a parser do and how

A

builds an abstract syntax tree
uses nodes for statements and expressions
aso builds a symbol table which contains all the variable names and information about them i.e type and scope

uses heirarchy to ensure local variables are used over global provided the same name

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

what does a lexer do

A

breaks input string into tokens

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

what does the optimisation stage entail

A

the IR transformations

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

what does the back end entail

A

converts IR into machine code
specific to architecture

register allocation
determie the location of variables in memoyr

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

what is common sub expression elimination

A

a = 2b +cd
e = 2b+f+g
–>
temp = 2b
a = temp+c+d
e = temp+f+g

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

what is dead code elimination

A

removes code that cannot be reached

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

what is constant foldin

A

combines all the constants in an equation into one
i.e
2 pi r^2 -> 6.28.. *r^2

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

what is hoisting loop invariants

A

if something is true every iteration of the loop take it outside the loop
i.e if x and y dont change

for i in range(1,10):
z +=x+y

–>
temp = x+y
for i in range(1,10):
z +=temp

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

what is function inlining

A

compiler rmeoves subroutine call by inlining the function (only done if small)

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

what is strength reduction

A

replaces expensive operations with cheaper operations

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