wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Compiler Review

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the first phase of a compiler?

a)

Lexical Analysis

b)

Code Generation

c)

Syntax Analysis

d)

Semantic Analysis

2.

Which phase of the compiler is responsible for checking the syntax of the source code?

a)

Syntax Analysis

b)

Semantic Analysis

c)

Lexical Analysis

d)

Optimization Phase

3.

What does the Semantic Analysis phase of a compiler do?

a)

Generates machine code directly

b)

Translates the code into assembly language

c)

Checks syntax, structure, and semantics of the code.

d)

Optimizes the code for better performance

4.

Which phase of the compiler is responsible for translating the intermediate code to machine code?

a)

Syntax Analysis

b)

Semantic Analysis

c)

Code Generation

d)

Lexical Analysis

5.

What is the purpose of Code Optimization in a compiler?

a)

To introduce bugs in the compiled code

b)

To improve the efficiency of the generated code.

c)

To slow down the compilation process

d)

To increase the size of the generated code

6.

How does a compiler handle syntax errors in the source code?

a)

The compiler crashes and shuts down when encountering syntax errors

b)

The compiler automatically corrects syntax errors without any notification

c)

The compiler stops the compilation process and displays an error message indicating the location and type of syntax error.

d)

The compiler ignores syntax errors and proceeds with the compilation process

7.

What is the main function of a compiler?

a)

Create new programming languages

b)

Debug software applications

c)

Optimize computer performance

d)

Translate source code into machine code

8.

What is a token in the context of lexical analysis?

a)

A token is a software program that analyzes the syntax of the source code.

b)

A token is a categorized group of characters that represent a unit of meaning in the source code.

c)

A token is a tool used to format the source code for readability.

d)

A token is a type of cryptocurrency used for transactions in source code.

9.

What is the role of a parser in the syntax analysis phase?

a)

To analyze the input code based on grammar rules and create a parse tree or abstract syntax tree.

b)

To optimize the code for better performance

c)

To execute the code line by line

d)

To generate machine code directly

10.

What is the difference between static and dynamic semantics in a programming language?

a)

Static semantics are checked at compile time, while dynamic semantics are checked at runtime.

b)

Static semantics are only relevant for interpreted languages, while dynamic semantics are only relevant for compiled languages.

c)

Static semantics are checked at runtime, while dynamic semantics are checked at compile time.

d)

Static semantics are related to syntax errors, while dynamic semantics are related to logical errors.

11.

What is the target of the code generation phase in a compiler?

a)

Optimize the code for better performance

b)

Translate intermediate representation into target machine code or another high-level language

c)

Generate pseudocode for debugging purposes

d)

Create a graphical user interface for the compiler

12.

What are some common code optimization techniques used by compilers?

a)

Common subexpression elimination, loop unrolling, dead code elimination, etc.

b)

Memory bloating, eliminate lexical errors

c)

Function wrapping, eliminate grammar errors

d)

Variable folding, type checking errors

13.

How does a compiler handle runtime errors in the source code?

a)

During compilation, the compiler generates error messages pointing out the specific lines of code where the runtime errors occur.

b)

The compiler ignores runtime errors

c)

Runtime errors are reported after the program execution

d)

Runtime errors are fixed automatically by the compiler

14.

What are the different types of errors that can occur during compilation?

a)

Syntax errors

b)

Syntax errors, Semantic errors, Logical errors

c)

Runtime errors

d)

Compilation errors

15.

What is a lexer in the context of lexical analysis?

a)

A lexer is a program that compiles code.

b)

A lexer is a program that breaks input text into tokens.

c)

A lexer is a program that optimizes database queries.

d)

A lexer is a program that generates random text.

16.

What is the purpose of constructing a parse tree in syntax analysis?

a)

To visualize the execution flow of the program

b)

To optimize the code for better performance

c)

To check for runtime errors in the code

d)

To represent the syntactic structure of the input code according to the grammar rules.

17.

Why is semantic analysis important in the compilation process?

a)

Semantic analysis is only important for debugging purposes after compilation.

b)

Semantic analysis is used to optimize the compilation process for faster execution.

c)

Semantic analysis ensures code readability by adding comments throughout the code.

d)

Semantic analysis ensures the code's correctness by checking for logical errors, type mismatches, and enforcing language-specific rules.

18.

What is the significance of the 'lex' and 'yacc' tools in the 'ply' module?

a)

They are used for creating graphical user interfaces.

b)

They are used for defining tokens and grammar rules for lexical and syntax analysis.

c)

They are used for optimizing code generation.

d)

They are used for debugging runtime errors.

19.

What is the role of a symbol table in compiler design?

a)

It stores information about the variables, functions, and their attributes in the source code.

b)

It generates machine code directly from the source code.

c)

It optimizes the code for better performance.

d)

It checks for syntax errors in the source code.

20.

What is the purpose of type checking in programming languages?

a)

To ensure that variables are declared before use and have the correct data type.

b)

To optimize the code for better performance.

c)

To generate machine code directly.

d)

To create graphical user interfaces.