Compilers Flashcards

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

4 stages of compilers / translation

A
  • Lexical analysis
  • Syntax analysis
  • Code generation
  • Code optimisation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Lexical analysis

A

The process of breaking a string of program into a token list

  • Spaces and comments are removed
  • Goes through the code and tries to identify the following elements:
  1. Identifiers (Variable names)
  2. Keywords (Names built into the programming language e.g. if , while)
  3. Separators(Punctuation)
  4. Operators(+ , - , . =…….)
  5. Literals(numbers)
  6. Comments

These are formed in pairs knows as Tokens

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

Lexemes

A

Invisible blocks of text that the compiler recognises

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

Syntax analysis

A

Takes the tokenized code and applies the rules of the language to it
- Produces parse tree (also knows as an abstract syntax tree)
- Unnecessary details have been removed
- Here you will get error reports for incorrect code
-Tokens checked against rules

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

Code generation

A

Abstract syntax tree is converted into object code (almost like machine code)
-addresses and scopes of variables are established

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

Optimasation

A

Object code is converted into Optimised object code
- Requires to be parsed again (identify any inefficiencies)

Why this process is slow

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

Libraries

A

Pre written code that can be called to add functionality to the programs

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

Linkers

A

Copy compiled library code into the program
- adds to file size
- If library is referenced multiple times , the library code will be copied several times (leads to bloated programs)
- If libraries are updated the program will still keep the older version

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

Loaders

A

Copies a reference of the compiled library code
- have not copied code so can not bloating code is not a problem
- several references will not increase file size
- updates to library can make code unstable

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

Translators

A

Converts from source code (high / low level) to object code (machine / executable)

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

Intermediate code

A

Code that is halfway between machine code and object code
- This is independent of the processor architecture so can be runacross different machines and operating systems.

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