Exam code: 9618
1/680Still learning
Know0
Define interpreter.
An interpreter is a type of translator that executes high-level code line by line.

Join for free to unlock a full flashcard set, track what you know,
and turn revision into real progress.
Does an interpreter produce a machine code file?
No. It does not generate a standalone executable or machine code file. Only immediate execution happens.
True or False?
An interpreter produces a standalone executable file.
False.
There is no output file. The code runs as it is interpreted.
Was this flashcard helpful?
Define interpreter.
An interpreter is a type of translator that executes high-level code line by line.
Does an interpreter produce a machine code file?
No. It does not generate a standalone executable or machine code file. Only immediate execution happens.
True or False?
An interpreter produces a standalone executable file.
False.
There is no output file. The code runs as it is interpreted.
How does an interpreter process source code?
The source code is read, analysed and executed one line at a time.
What happens when an interpreter finds an error in a line?
Execution stops, and the error is reported immediately.
Why is interpreted execution slower?
Each line is translated every time the program runs.
Why is an interpreter useful during development?
It is good for testing and debugging while coding.
Give two example uses of an interpreter.
Educational tools, such as Python shells or BASIC interpreters, and rapid prototyping where frequent changes are made.
Define compilation.
Compilation is a process that translates a program written in a high-level programming language into machine code.
Why is compilation necessary?
Because only machine code can be executed by a computer.
Name the four stages of compilation.
Lexical analysis, syntax analysis, code generation and optimisation.
What does lexical analysis do?
It identifies lexical 'tokens' in the code, studying the words or vocabulary of the language.
Name the four types of token.
Keywords, identifiers, operators and separators.
Give two examples of a keyword token.
var, const, function, for, while and if.
Give two examples of a separator token.
,, ;, {, }, ( and ).
What is ignored during lexical analysis?
Comments and whitespace.
What is the result of lexical analysis?
A token table.
What does syntax analysis do?
It makes sure the tokens all adhere to the syntax rules of the programming language.
A symbol such as could be a valid token but not a valid character in a language, so it breaks the syntax rules.
A symbol such as $ could be a valid token but not a valid character in a language, so it breaks the syntax rules.
Give two common syntax errors.
Mismatched parentheses and missing semicolons.
Define Abstract Syntax Tree (AST).
An AST is a graph-based representation of the code being compiled, created once the code has passed syntax analysis.
If the code passes syntax analysis, the compiler creates an Syntax Tree.
If the code passes syntax analysis, the compiler creates an Abstract Syntax Tree.
Why is an AST useful?
It is an efficient way to represent the code for the next stage of compilation.
What happens at the code generation stage?
It takes the AST and traverses it to generate object code that can be executed by the computer.
What does the optimisation stage do?
It modifies the code to make it more efficient without changing its functionality.
True or False?
Optimisation changes what the program does.
False.
Optimisation makes the code more efficient without changing its functionality.
Give a common optimisation action.
Removing duplicate code. If an 'add' function is written twice in the source code, a sophisticated compiler includes it only once in the object code.
Define syntax.
Syntax is the set of strict rules that define how code must be written.
Do all programming languages share the same syntax?
No. Each language has its own syntax. For example, Python uses indentation and Java uses semicolons.
Why must syntax be precisely defined?
To avoid ambiguity, so that translators can correctly convert the program into a form the CPU can understand.
What are regular expressions used for?
To describe simple patterns in text or syntax, such as variable names or simple statements.
Why are regular expressions not always enough?
Some aspects of a programming language are too complex for regular expressions alone.
True or False?
Every aspect of a programming language can be described by regular expressions.
False.
Some aspects are too complex, which is why a meta-language such as BNF is needed.
Define meta-language.
A meta-language is a language used to describe the structure of another language.
When regular expressions are not enough, we use a .
When regular expressions are not enough, we use a meta-language.
Name two meta-languages.
Backus-Naur Form (BNF) and syntax diagrams.
What three things do meta-languages let you define?
Full grammar rules, nested structures and hierarchical syntax.
Define Backus-Naur Form (BNF).
BNF is a meta-language, a way of writing rules that define the syntax of programming languages or data structures.
Name three things BNF is used for.
To describe formal grammar, to define how statements and expressions are structured, and to ensure syntax rules are unambiguous and machine-readable.
Define non-terminal in BNF.
A non-terminal is a category or component, such as <digit> or <identifier>.
Define terminal in BNF.
A terminal is an actual value or symbol, such as 0, 1, + or if.
True or False?
A terminal in BNF is a category such as <digit>.
False.
That is a non-terminal. A terminal is an actual value or symbol, such as 0 or if.
What does ::= mean in BNF?
'Is defined as'. It separates the name from its definition.
What does | mean in BNF?
'Or'. It gives alternative definitions.
Write the BNF rule for <digit>.
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
What does <number> ::= <digit> | <digit> <number> define?
A number as a single digit, or a digit followed by another number, which gives one or more digits.
Why is the <number> rule recursive?
Because it refers to itself, which is how a definition of one or more items is written in BNF.
What does <IDcode> ::= <number><letter> | <number><number> define?
An IDcode as a number followed by either a letter or another number.
Define syntax diagram.
A syntax diagram is a graphical representation of BNF, using symbols that map directly to the structure of BNF.
On a syntax diagram, a terminal element is drawn in a .
On a syntax diagram, a terminal element is drawn in a circle.
Define Reverse Polish Notation (RPN).
RPN is a method of writing mathematical expressions where the operator comes after the operands.
What is RPN also known as?
Postfix notation.
In RPN, the operator comes the operands.
In RPN, the operator comes after the operands.
Write 3 + 4 in RPN.
3 4 +
Give three reasons to use RPN.
No need for brackets, easier for computers to evaluate using a stack, and it is always unambiguous.
What determines the order of operations in RPN?
Position, not parentheses.
True or False?
RPN needs brackets to show precedence.
False.
RPN follows the evaluation order naturally, so there is no need for brackets or precedence rules.
Which data structure is used to evaluate RPN?
A stack.
What are the four steps of evaluating an RPN expression?
Read left to right; push numbers onto the stack; when an operator is read, pop the top two values, apply the operator and push the result back; when the expression ends, the result is at the top of the stack.
What happens when an operator is read?
The top two values are popped from the stack, the operator is applied, and the result is pushed back onto the stack.
True or False?
In RPN, an operator is applied to the bottom two values of the stack.
False.
It is applied to the top two values, which are popped from the stack.
Where is the final result of an RPN evaluation found?
At the top of the stack.
Evaluate 3 4 + 2 x.
Push 3, push 4, add to give 7, push 2, multiply to give 14. The result is 14.
In 3 4 + 2 x, what is on the stack after the + has been read?
7
Convert (7 - 2 + 8) to RPN.
7 2 - 8 +
Convert (9 - 5) to RPN.
9 5 -
Convert (7 - 2 + 8) / (9 - 5) to RPN.
7 2 - 8 + 9 5 - /
What is the method for converting an infix expression to RPN?
Work from inside brackets out, convert each sub-expression, and add the operator after its operands.
By signing up you agree to our Terms and Privacy Policy