Translators: Interpreters, compilers and assemblers, stages of compilation (lexical analysis, syntax analysis, code generation and optimisation) Flashcards

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

What is a translator?

A

A translator is a program that converts high-level source code into low-level object code, which is then ready to be executed by a computer

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

What are 3 translators?

A
  • Compilers
  • Interpreters
  • Assemblers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are compilers?

A

Converts high-level source code into object code which can be saved and run without a translator

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

Features of compilers/compiled code?

A
  • Different hardware platform will require different compilers, since the resulting object code will be hardware specific
  • Once compiled does not need to go through a interpreter
  • Takes longer to compile (translation) but execution is faster
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are interpreters?

A

Translates and executes source code line by line (high level language)

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

Features of interpreters?

A
  • Does not produce code which can run without a translator so can be slower to run
  • E.g. Using Idle python, executes code line by line
  • Faster to compile but execution is slower
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are assemblers?

A

Converts low level assembly code into machine code instructions

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

Features of assemblers/assembly code?

A
  • Only used on assembly code not on high level languages (e.g. python)
  • Must be translated into the equivalent machine code, or an intermediate form called bytecode
  • The output of the assembler (machine code) is called the object code (platform specific)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens during lexical analysis?

A
  • The lexer starts by converting lexemes in the source code into a series of tokes
  • The lexer reads (parsing) the source code, it scans the code letter by letter
  • Encounters a white space, operator symbol or special symbol it decides that a word (lexeme) is complete
  • Checks if the lexeme is valid using a predefined set of rules that allow every lexeme to be identified as a valid token (operator + is considered a token)
  • White space and comments have been removed because they are simply passed over by the lexer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why does the length of variable names and amount of comments in a program’s source makes no difference to the size of a compiled program?

A
  • Comments only relevant in the source code
  • There is no performance difference, since those names don’t matter at the machine level, a compiler will process those names away so it won’t make a difference to the program at all
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is meant by syntax/syntax analysis?

A
  • Syntax is the set of rules a programming language requires code to follow
  • Syntax analysis is making sure the code follows the rules
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens during syntax analysis?

A
  • It receives its inputs in the form of tokens from lexical analysis
  • Analyses the syntactical structure of the input, checking if it’s in the correct syntax of the programming language it has been written in
    Analyses the token stream against production rules to detect any errors in the code, accomplishes two tasks:
  • Checks for errors and reporting them
  • Building an abstract syntax tree (parse tree)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What happens during code generation?

A

Code generation the compiler takes the parse tree and converts it into machine code

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

What happens during code optimisation?

A

Code optimisation attempts to reduce the execution time of the program by:

  • Spotting redundant instructions and producing object code that achieves the same effect as the source program
  • Removing subroutines that are never called
  • Removing variables and constants that are never referenced
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the aim of code optimisation?

A

The aim of optimisation is to make the code faster to execute, optimisation tweaks the code so it will run as quickly and use as little memory as possible

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

What is the job of a linker?

A
  • Once compiled, any separately compiled subroutines must be linked into the object code (E.g. random number generator)
  • It is the job of the linker to put the appropriate machine addresses in all the external call and return instructions so that the modules are linked together correctly
17
Q

What is the job of a loader?

A

A relocating loader can load the object code anywhere in memory (providing the programmer has used no absolute addresses and the object code is in relocate format)

18
Q

Explain why programmers could use intermediate code for the final product?

A
  • Intermediate code can be used in a virtual machine
  • Portable/can be used on any machine
  • Protects the source code from being copied