wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Chapter 10 - Programming language translators

Total questions: 27

Worksheet time: 14mins

Name
Class
Date
1.

What is the role of an assembler in programming language translation?

a)

An assembler translates assembly code into machine code or intermediate bytecode.

b)

An assembler translates high-level code into assembly language.

c)

An assembler translates machine code into high-level language.

d)

An assembler translates pseudo code into flowcharts.

2.

What is the difference between source code and object code?

a)

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.

b)

Source code is the machine code executed by the computer, while object code is the code written by the programmer.

c)

Source code and object code are both written in high-level languages but serve different purposes.

d)

Source code is the output of the compiler, while object code is the input to the compiler.

3.

Which of the following best describes a compiler?

a)

Translates high-level language into machine code

b)

Translates machine code into high-level language

c)

Translates assembly code into high-level language

d)

Translates bytecode into source code

4.

Before an assembly code program can be executed, it must be translated into the equivalent machine code, or an intermediate form called ________.

a)

bytecode

b)

source code

c)

hexadecimal code

d)

object-oriented code

5.

The input to the assembler is called the ________ and the output (machine code) is the ________.

a)

source code, object code

b)

object code, source code

c)

binary code, assembly code

d)

assembly code, binary code

6.

Describe the stages of compilation: lexical analysis, syntax analysis, code generation and optimisation.

a)

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).

b)

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).

c)

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).

d)

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).

7.

What are the three main stages shown in the diagram?

a)

Input (Source code), Process (Compile), Output (Object code)

b)

Input (Object code), Process (Compile), Output (Source code)

c)

Input (Source code), Process (Execute), Output (Object code)

d)

Input (Source code), Process (Debug), Output (Object code)

8.

Based on the passage, what does an interpreter do when it encounters a syntax error in a program?

a)

It skips the error and continues running the program

b)

It translates the program into machine code and runs it

c)

It stops and reports the error without running the program

d)

It ignores the error and produces output

9.

What error does the interpreter produce when this program runs?

a)

NameError: name 'n' is not defined

b)

TypeError: unsupported operand type(s)

c)

SyntaxError: invalid syntax

d)

IndexError: list index out of range

10.

When a syntax error is present in a program, such as a missing closing bracket, what does the interpreter do before executing any code?

a)

The interpreter scans through the whole program checking for certain types of error before executing any of it.

b)

The interpreter ignores the error and continues execution.

c)

The interpreter automatically corrects the error and runs the program.

d)

The interpreter executes only the lines before the error and skips the rest.

11.

What type of error is indicated by the interpreter in the screenshot?

a)

SyntaxError: invalid syntax

b)

TypeError: unsupported operand type(s)

c)

NameError: name 'x' is not defined

d)

IndentationError: unexpected indent

12.

A company or an individual programmer may not want to distribute the source code when they sell a software package because:

a)

They want to protect their intellectual property and prevent unauthorized copying or modification.

b)

They want to make the software open source.

c)

They want to encourage users to modify the software.

d)

They want to provide free access to the code.

13.

Which of the following is NOT a stage of compilation?

a)

A) Lexical analysis

b)

B) Syntax analysis

c)

C) Code generation and optimisation

d)

D) Program execution

14.

Lexical analysis performs which of the following functions?

a)

Removes superfluous spaces

b)

Removes all comments

c)

Performs some error-checking

d)

All of the above

15.

Fill in the blank: In lexical analysis, all comments, identified for example by # or //, will be ______ from the program.

a)

removed

b)

executed

c)

highlighted

d)

compiled

16.

The lexical analyser will detect misspelt keywords or undeclared variables.

a)

True

b)

False

17.

The main role of the symbol table in the compilation process is:

a)

To store information about variables, functions, and objects used in the program

b)

To generate machine code from source code

c)

To optimize the code for better performance

d)

To handle input and output operations

18.

According to the symbol table, what is the run-time address or value of 'pi'?

a)

3.14159

b)

0x7ffeefbff5c8

c)

42

d)

NULL

19.

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?

a)

circumference, pi, radius

b)

circumference, 2, pi, radius

c)

circumference, 2, *, pi, *, radius

d)

circumference, =, 2, *, pi, *, radius

20.

Which of the following is an example of a semantic error?

a)

Using the wrong variable name in a calculation

b)

Misspelling a keyword

c)

Forgetting a semicolon

d)

Incorrectly nesting loops

21.

Which of the following best describes how a library is invoked by a program?

a)

By calling its functions or routines in the code

b)

By copying its code into the program manually

c)

By renaming the library file

d)

By deleting the library after use

22.

Which of the following best describes the function of the lexical analyser in the compilation process?

a)

It links different program modules together.

b)

It converts the source code into tokens and removes comments and unnecessary spaces.

c)

It generates the final machine code for execution.

d)

It executes the program line by line.

23.

What is the primary purpose of code optimisation during compilation?

a)

To translate high-level code into assembly language

b)

To remove all comments from the program

c)

To improve the efficiency and performance of the generated machine code

d)

To check for syntax errors in the source code

24.

Which of the following errors would most likely be detected during syntax analysis?

a)

Incorrect output formatting

b)

Dividing a number by zero

c)

Using an undefined variable in a calculation

d)

Missing closing parenthesis in an expression

25.

Which stage of the compilation process is responsible for checking the grammatical structure of the source code?

a)

Linking

b)

Code generation

c)

Lexical analysis

d)

Syntax analysis

26.

What is the main function of a linker in the process of program translation?

a)

To remove all comments from the source code

b)

To execute the program line by line

c)

To convert high-level code into tokens

d)

To combine object code modules and resolve references between them

27.

Which of the following best describes an interpreter?

a)

Executes source code line by line and stops at errors

b)

Translates the entire program into machine code before execution

c)

Optimizes the code for better performance

d)

Links different program modules together