Chapter 16.2 Flashcards

"Translation Software"

1
Q

interpreter

A

an interpreter examines source code one statement at a time
executes code line by line before producing a completely translated version of it.
also produces intermediate code but executes per line.

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

how does an interpreter execute a program

A

an interpreter examines and
checks each line for errors,
if no error is found the line is executed
if an error is found this is reported and the interpreter halts,
interpretation has to be repeated every time the program is run

interpretation is repeated for every iteration in loops

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

compiler

A

takes the whole code in as input and translates high-level language programs into object code. produces an executable file
has front-end analysis and back-end analysis stages.

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

assembler

A

translates assembly language into machine language

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

compilation stages

A

lexical analysis
syntax analysis
(intermediate) code generation
code optimisation

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

lexical analysis

A

first stage
converts a sequence of characters into a sequence of tokens

removes comments and whitespace
tokenises code (changes each line into a series of tokens) and categorizes lexemes (e.g. keywords and identifiers) by checking against a predefined set of rules

a symbol table (keeps track of variables and their meanings) and a keyword table is created (see respective pages) to create a sequence of tokens

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

symbol table

A

records the names and attributes of an identifier
identifier name, data type, role (variable, constant, procedure etc.)
identifier value or location

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

keyword table

A

used to recognize certain keywords in a language
- the reserved words used
- the operators used
- their matching tokens

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

syntax analysis

A

second stage
uses parsing algorithms to interpret the meaning of a sequence of tokens

  • constructs parse tree
  • check syntax or grammar through syntax diagram
  • produce error report - if errors are found, each token is output but code generation is not run
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

syntax diagram

A

breaks down the grammar and syntax rules of a variable or constant

rectangle = variable/identifier
rectangle with repeated arrow going around = can be repeated as many times
circle = a value which cannot further be broken down

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

code generation

A

converts the intermediate code produced by previous stages into an executable form

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

code optimisation

A

produces an efficient object program, aims to use the minimum amount of resources

to have fewer instructions, occupy less space in memory, reduce execution time.

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

BNF notation

A

another way to represent syntax/grammar rules. a set of recursive rules

<> = surrounds each variable
(letters or numbers by themselves do NOT have <>)
::= means “is defined as”
|= separates individual options. “or”

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

Reverse Polish Notation (RPN)

A

a postfix notation which never requires brackets and has no rules of precedence

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

why is RPN used to carry out the evaluation of expressions?

A

RPN provides an unambiguous method of representing an expression,
reads from left to right,
without needing brackets,
without precedence rules.

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

why are stacks used to evaluate an expression in RPN

A
  • the operands are popped from the stack in the reverse order to how they were pushed
  • evaluates from left to right
  • pushes each element of the expression onto the stack until it comes across an operator
  • pops the last two elements and applies the operator
  • push the result onto the stack
  • repeats and effectively evaluates the whole expression
17
Q

back-end analysis

A

takes the intermediate code as input and produces the object code

18
Q

front-end analysis

A

performs analysis of source code and produces intermediate codes expressing completely the code’s semantics - its meaning