NEW
Font size
WorksheetsChapter 10 - Programming language translators
Total questions: 27
Worksheet time: 14mins
What is the role of an assembler in programming language translation?
An assembler translates assembly code into machine code or intermediate bytecode.
An assembler translates high-level code into assembly language.
An assembler translates machine code into high-level language.
An assembler translates pseudo code into flowcharts.
What is the difference between source code and object code?
Source code is the code written by the programmer in a high-level or assembly language, while object code is the machine code output produced after translation by a compiler or assembler.
Source code is the machine code executed by the computer, while object code is the code written by the programmer.
Source code and object code are both written in high-level languages but serve different purposes.
Source code is the output of the compiler, while object code is the input to the compiler.
Which of the following best describes a compiler?
Translates high-level language into machine code
Translates machine code into high-level language
Translates assembly code into high-level language
Translates bytecode into source code
Before an assembly code program can be executed, it must be translated into the equivalent machine code, or an intermediate form called ________.
bytecode
source code
hexadecimal code
object-oriented code
The input to the assembler is called the ________ and the output (machine code) is the ________.
source code, object code
object code, source code
binary code, assembly code
assembly code, binary code
Describe the stages of compilation: lexical analysis, syntax analysis, code generation and optimisation.
The stages of compilation are lexical analysis (breaking code into tokens), syntax analysis (parsing tokens into grammatical structure), code generation (producing machine code), and optimisation (improving code efficiency).
The stages of compilation are syntax analysis (breaking code into tokens), lexical analysis (parsing tokens into grammatical structure), code generation (producing machine code), and optimisation (removing all comments).
The stages of compilation are code generation (breaking code into tokens), optimisation (parsing tokens into grammatical structure), lexical analysis (producing machine code), and syntax analysis (improving code efficiency).
The stages of compilation are optimisation (breaking code into tokens), code generation (parsing tokens into grammatical structure), syntax analysis (producing machine code), and lexical analysis (improving code efficiency).
What are the three main stages shown in the diagram?
Input (Source code), Process (Compile), Output (Object code)
Input (Object code), Process (Compile), Output (Source code)
Input (Source code), Process (Execute), Output (Object code)
Input (Source code), Process (Debug), Output (Object code)
Based on the passage, what does an interpreter do when it encounters a syntax error in a program?
It skips the error and continues running the program
It translates the program into machine code and runs it
It stops and reports the error without running the program
It ignores the error and produces output
What error does the interpreter produce when this program runs?
NameError: name 'n' is not defined
TypeError: unsupported operand type(s)
SyntaxError: invalid syntax
IndexError: list index out of range
When a syntax error is present in a program, such as a missing closing bracket, what does the interpreter do before executing any code?
The interpreter scans through the whole program checking for certain types of error before executing any of it.
The interpreter ignores the error and continues execution.
The interpreter automatically corrects the error and runs the program.
The interpreter executes only the lines before the error and skips the rest.
What type of error is indicated by the interpreter in the screenshot?
SyntaxError: invalid syntax
TypeError: unsupported operand type(s)
NameError: name 'x' is not defined
IndentationError: unexpected indent
A company or an individual programmer may not want to distribute the source code when they sell a software package because:
They want to protect their intellectual property and prevent unauthorized copying or modification.
They want to make the software open source.
They want to encourage users to modify the software.
They want to provide free access to the code.
Which of the following is NOT a stage of compilation?
A) Lexical analysis
B) Syntax analysis
C) Code generation and optimisation
D) Program execution
Lexical analysis performs which of the following functions?
Removes superfluous spaces
Removes all comments
Performs some error-checking
All of the above
Fill in the blank: In lexical analysis, all comments, identified for example by # or //, will be ______ from the program.
removed
executed
highlighted
compiled
The lexical analyser will detect misspelt keywords or undeclared variables.
True
False
The main role of the symbol table in the compilation process is:
To store information about variables, functions, and objects used in the program
To generate machine code from source code
To optimize the code for better performance
To handle input and output operations
According to the symbol table, what is the run-time address or value of 'pi'?
3.14159
0x7ffeefbff5c8
42
NULL
What further entries to the symbol table will the lexical analyser make on encountering the statement: circumference = 2 * pi * radius? Which of the following lists the correct entries to be added to the symbol table?
circumference, pi, radius
circumference, 2, pi, radius
circumference, 2, *, pi, *, radius
circumference, =, 2, *, pi, *, radius
Which of the following is an example of a semantic error?
Using the wrong variable name in a calculation
Misspelling a keyword
Forgetting a semicolon
Incorrectly nesting loops
Which of the following best describes how a library is invoked by a program?
By calling its functions or routines in the code
By copying its code into the program manually
By renaming the library file
By deleting the library after use
Which of the following best describes the function of the lexical analyser in the compilation process?
It links different program modules together.
It converts the source code into tokens and removes comments and unnecessary spaces.
It generates the final machine code for execution.
It executes the program line by line.
What is the primary purpose of code optimisation during compilation?
To translate high-level code into assembly language
To remove all comments from the program
To improve the efficiency and performance of the generated machine code
To check for syntax errors in the source code
Which of the following errors would most likely be detected during syntax analysis?
Incorrect output formatting
Dividing a number by zero
Using an undefined variable in a calculation
Missing closing parenthesis in an expression
Which stage of the compilation process is responsible for checking the grammatical structure of the source code?
Linking
Code generation
Lexical analysis
Syntax analysis
What is the main function of a linker in the process of program translation?
To remove all comments from the source code
To execute the program line by line
To convert high-level code into tokens
To combine object code modules and resolve references between them
Which of the following best describes an interpreter?
Executes source code line by line and stops at errors
Translates the entire program into machine code before execution
Optimizes the code for better performance
Links different program modules together
