☑ MCQ PRACTICE

Compiler Design Unit 1

Practice objective questions for quick revision and examination preparation. Try answering each question before revealing the answer.

📚 Compiler Design
📖 Unit 1
🎯 MCQs
Compiler Design MCQs - Unit 1

Compiler Design MCQs - Unit 1

1

The first phase of a compiler is

A lexical analysis
B syntax analysis
C semantic analysis
D code generation
Correct Answer lexical analysis
2

The output of the lexical analyzer is a stream of

A parse trees
B tokens
C machine instructions
D symbol tables
Correct Answer tokens
3

The output of the syntax analyzer (parser) is a

A parse tree (syntax tree)
B stream of characters
C object file
D list of tokens
Correct Answer parse tree (syntax tree)
4

Type checking is performed during

A lexical analysis
B code generation
C linking
D semantic analysis
Correct Answer semantic analysis
5

Three-address code is an example of

A target machine code
B intermediate representation
C source code
D a token
Correct Answer intermediate representation
6

The symbol table is used to

A store the machine code
B store the source file
C store the compiler's own code
D store information about identifiers such as name, type and scope
Correct Answer store information about identifiers such as name, type and scope
7

A compiler differs from an interpreter in that a compiler

A executes the source statement by statement
B never produces output
C translates the whole source program into a target program
D works only on assembly code
Correct Answer translates the whole source program into a target program
8

Which of the following belongs to the back end of a compiler?

A Lexical analysis
B Syntax analysis
C Semantic analysis
D Code generation
Correct Answer Code generation
9

A sequence of characters in the source program that matches the pattern for a token is called a

A pattern
B lexeme
C grammar
D production
Correct Answer lexeme
10

A description of the form that the lexemes of a token may take is called a

A pattern
B lexeme
C symbol
D handle
Correct Answer pattern
11

Besides producing tokens, the lexical analyzer also removes

A white space and comments
B all identifiers
C all operators
D all keywords
Correct Answer white space and comments
12

In input buffering, a sentinel is used to

A encrypt the input
B store tokens
C generate code
D reduce the number of tests needed to detect the end of the buffer
Correct Answer reduce the number of tests needed to detect the end of the buffer
13

Lex is a tool used to generate

A parsers
B lexical analyzers
C code generators
D linkers
Correct Answer lexical analyzers
14

A Lex program consists of how many sections separated by %%?

A one
B three (declarations, translation rules, auxiliary functions)
C two
D five
Correct Answer three (declarations, translation rules, auxiliary functions)
15

The regular expression (a|b)* denotes

A all strings of a's and b's, including the empty string
B only the string ab
C only strings of a's
D only non-empty strings
Correct Answer all strings of a's and b's, including the empty string
16

A DFA differs from an NFA in that a DFA has

A exactly one transition for each input symbol from each state
B ε-transitions
C more than one start state
D no final states
Correct Answer exactly one transition for each input symbol from each state
17

An NFA may contain

A exactly one transition per symbol
B no transitions
C only one state
D ε-transitions and multiple transitions on the same symbol
Correct Answer ε-transitions and multiple transitions on the same symbol
18

The algorithm used to convert an NFA into a DFA is

A Thompson's construction
B subset construction
C Kleene's closure
D Huffman coding
Correct Answer subset construction
19

The algorithm used to convert a regular expression into an NFA is

A Thompson's construction
B subset construction
C LR construction
D Prim's algorithm
Correct Answer Thompson's construction
20

DFA minimization is done to

A increase the number of states
B add ε-transitions
C reduce the number of states
D remove the start state
Correct Answer reduce the number of states
21

To build a DFA directly from a regular expression, which function is used?

A FOLLOW of a grammar symbol
B gotopos
C shiftpos
D followpos
Correct Answer followpos
22

The ε-closure of a state is the set of states

A reachable from it using ε-transitions only
B reachable using any one symbol
C that are final only
D that have no outgoing edges
Correct Answer reachable from it using ε-transitions only
23

Which of the following is detected as a lexical error?

A A type mismatch
B A missing return value
C An undefined function call
D An illegal character in the source program
Correct Answer An illegal character in the source program
24

The number of tokens in the statement int a = b + 1; is

A 7
B 5
C 6
D 9
Correct Answer 7
25

Scope that is determined at compile time from the structure of the program text is called

A dynamic scope
B global scope only
C static (lexical) scope
D run-time scope
Correct Answer static (lexical) scope

Fill in the Blanks

26 The first phase of a compiler is ______ analysis.
Correct Answer lexical
27 A sequence of characters in the source program that matches the pattern of a token is called a ______.
Correct Answer lexeme
28 ______ is a tool that generates lexical analyzers.
Correct Answer Lex
29 An NFA is converted into a DFA using the ______ construction.
Correct Answer subset
30 A regular expression is converted into an NFA using ______ construction.
Correct Answer Thompson's
31 The ______ of a state is the set of states reachable from it using only ε-transitions.
Correct Answer ε-closure
32 The ______ table stores information about the identifiers in the source program.
Correct Answer symbol
33 In input buffering, a ______ character marks the end of a buffer.
Correct Answer sentinel
34 The lexical analyzer reads the ______ program and produces a stream of tokens.
Correct Answer source
35 DFA minimization reduces the number of ______.
Correct Answer states
36 The output of the lexical analyzer is a stream of ______.
Correct Answer tokens
37 A compiler that runs on one machine and produces code for a different machine is called a ______ compiler.
Correct Answer cross
38 The analysis part (front end) of a compiler is independent of the ______ machine.
Correct Answer target
39 An ______ translates and executes the source program statement by statement.
Correct Answer interpreter
40 Scope that is determined from the program text at compile time is called ______ scope.
Correct Answer static (lexical)
← Back to All MCQs