☑ MCQ PRACTICE

Compiler Design Unit 2

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

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

Compiler Design MCQs - Unit 2

1

A context-free grammar consists of terminals, non-terminals, a start symbol and

A tokens
B lexemes
C registers
D productions
Correct Answer productions
2

A grammar is ambiguous if

A it has no start symbol
B some string has more than one parse tree
C it has no terminals
D every string has exactly one parse tree
Correct Answer some string has more than one parse tree
3

Left recursion in a grammar causes a top-down parser to

A run faster
B go into an infinite loop
C stop immediately with success
D skip tokens
Correct Answer go into an infinite loop
4

Eliminating immediate left recursion from A → Aα | β gives

A A → αA and A → β
B A → βA′ and A′ → αA′ | ε
C A → Aβ | α
D A → ε
Correct Answer A → βA′ and A′ → αA′ | ε
5

Left factoring is used to

A make a grammar ambiguous
B remove all terminals
C make a grammar suitable for predictive parsing
D increase the number of states
Correct Answer make a grammar suitable for predictive parsing
6

Top-down parsing constructs the parse tree

A from the leaves up to the root
B from the middle outwards
C without any tree
D from the root down to the leaves
Correct Answer from the root down to the leaves
7

Bottom-up parsing corresponds to a

A leftmost derivation
B rightmost derivation in reverse
C random derivation
D no derivation
Correct Answer rightmost derivation in reverse
8

In LL(1), the first L stands for scanning the input

A from left to right
B from right to left
C in the middle only
D at random
Correct Answer from left to right
9

A predictive parser uses

A only a queue
B only a hash table
C no data structure
D a parsing table and a stack
Correct Answer a parsing table and a stack
10

FIRST(A) is the set of

A terminals that can begin strings derived from A
B terminals that can end strings derived from A
C all non-terminals
D all productions of A
Correct Answer terminals that can begin strings derived from A
11

FOLLOW(A) is the set of

A terminals that begin A
B terminals that can appear immediately to the right of A
C non-terminals only
D productions of A
Correct Answer terminals that can appear immediately to the right of A
12

FOLLOW of the start symbol always contains

A ε
B $ (the end marker)
C the first terminal
D the empty set
Correct Answer $ (the end marker)
13

The actions of a shift-reduce parser are shift, reduce, accept and

A error
B jump
C load
D store
Correct Answer error
14

A handle is a substring that

A matches the left side of every production
B is always a terminal
C is always the empty string
D matches the right side of a production and whose reduction is a step in a reverse rightmost derivation
Correct Answer matches the right side of a production and whose reduction is a step in a reverse rightmost derivation
15

In LR(k), the letter R stands for

A constructing a rightmost derivation in reverse
B reading the input from right to left
C recursion
D repetition
Correct Answer constructing a rightmost derivation in reverse
16

Which of the following is the most powerful LR parser?

A SLR
B Canonical LR (CLR)
C LALR
D LL(1)
Correct Answer Canonical LR (CLR)
17

LALR parsing merges LR(1) states that have the same

A lookahead only
B core
C name
D number of items
Correct Answer core
18

SLR parsers decide reduce actions using

A FIRST sets only
B random choice
C FOLLOW sets
D the input length
Correct Answer FOLLOW sets
19

Yacc is a

A lexical analyzer generator
B code optimizer
C linker
D parser generator
Correct Answer parser generator
20

A shift-reduce conflict occurs when

A the input is empty
B the stack is empty
C the parser cannot decide whether to shift or to reduce
D the grammar has no productions
Correct Answer the parser cannot decide whether to shift or to reduce
21

Ambiguity in a grammar can be resolved in Yacc by declaring

A precedence and associativity of operators
B more terminals
C a longer input
D extra comments
Correct Answer precedence and associativity of operators
22

Which of the following is a bottom-up parser?

A Recursive-descent parser
B LL(1) parser
C Predictive parser
D SLR parser
Correct Answer SLR parser
23

A recursive-descent parser consists of

A a single table only
B only one variable
C a set of procedures, one for each non-terminal
D a symbol table only
Correct Answer a set of procedures, one for each non-terminal
24

In panic-mode error recovery, the parser

A discards input symbols until a synchronizing token is found
B stops the compilation immediately
C inserts random code
D restarts from the first line
Correct Answer discards input symbols until a synchronizing token is found
25

A grammar that is suitable for LL(1) parsing must not be

A left-recursive or ambiguous
B context-free
C written with terminals
D written with productions
Correct Answer left-recursive or ambiguous

Fill in the Blanks

26 A context-free grammar consists of terminals, non-terminals, a start symbol and ______.
Correct Answer productions
27 A grammar that produces more than one parse tree for some string is called ______.
Correct Answer ambiguous
28 Eliminating left recursion from A → Aα | β gives A′ → αA′ | ______.
Correct Answer ε
29 In LL(1), the second L stands for a ______ derivation.
Correct Answer leftmost
30 The ______ of the start symbol always contains the end marker $.
Correct Answer FOLLOW
31 Bottom-up parsing produces a rightmost derivation in ______.
Correct Answer reverse
32 A substring that matches the right side of a production and can be reduced is called a ______.
Correct Answer handle
33 The actions of a shift-reduce parser are shift, reduce, accept and ______.
Correct Answer error
34 SLR parsers use ______ sets to decide where to place reduce actions.
Correct Answer FOLLOW
35 Of SLR, LALR and CLR, the most powerful parser is ______.
Correct Answer CLR (canonical LR)
36 LALR parsers merge LR(1) states that have the same ______.
Correct Answer core
37 ______ is a widely used LALR parser generator.
Correct Answer Yacc
38 A ______ conflict occurs when the parser cannot decide whether to shift or reduce.
Correct Answer shift-reduce
39 A recursive-descent parser has one ______ for each non-terminal.
Correct Answer procedure
40 In panic-mode recovery, the parser discards input ______ until a synchronizing token is found.
Correct Answer symbols (tokens)
← Back to All MCQs