Explore topic-wise MCQs in Compilers.

This section includes 17 Mcqs, each offering curated multiple-choice questions to sharpen your Compilers knowledge and support exam preparation. Choose a topic below to get started.

1.

Given the following expression grammar :E → E ⋆ F | F + E | FF→ F - F| idWhich of the following is true?

A. ⋆ has higher precedence than +
B. - has higher precedence than ⋆
C. + and - have same precedence
D. + has higher precedence than ⋆
Answer» C. + and - have same precedence
2.

Consider the following grammarS → m | mn | mnoChoose correct statement from the following:

A. The grammar is LL (2)
B. The grammar is LL (4)
C. The grammar is LL (1)
D. The grammar is LL (3)
Answer» E.
3.

Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a, b}.S → aA {print 1}S → a {print 2}A → Sb {print 3}Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:

A. 1 3 2
B. 2 2 3
C. 2 3 1
D. syntax error
Answer» D. syntax error
4.

Consider the following statements.S1 : Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).S2 : For any context-free grammar, there is a parser that takes at most O(n3) time to parse a string of length n.Which one of the following option is correct?

A. S1 is true and S2 is false
B. S1 is false and S2 is true
C. S1 is true and S2 is true
D. S1 is false and S2 is false
Answer» D. S1 is false and S2 is false
5.

Consider the following two sets of LR(1) items of an LR(1) grammar.X → c.X, c/d X → c.X, $X → .cX, c/d X → .cX, $X → .x, c/d X → .d, $Which of the following statements related to merging of the two sets in the corresponding LALRparser is/are FALSE?1. Cannot be merged since look aheads are different.2. Can be merged but will result in S-R conflict.3. Can be merged but will result in R-R conflict.4. Cannot be merged since goto on c will lead to two different sets.

A. 1 only
B. 2 only
C. 1 and 4 only
D. 1, 2, 3 and 4
Answer» E.
6.

Among simple LR (SLR), canonical LR, and look – ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the most powerful, in that order?

A. SLR, LALR
B. Canonical LR, LALR
C. SLR, canonical LR
D. LALR, canonical LR
Answer» D. LALR, canonical LR
7.

In LR(k) parsing, when the value of k is omitted, it is assumed to be ______.

A. 1
B. 2
C. 3
D. 8
Answer» B. 2
8.

A top-down parser generates

A. Rightmost derivation
B. Rightmost derivation in reverse
C. Leftmost derivation
D. Leftmost derivation in reverse
Answer» D. Leftmost derivation in reverse
9.

Match the following:(P)Lexical analysis(i)Leftmost derivation(Q)Top down parsing(ii)Type checking(R)Semantic analysis(iii)Regular expressions(S)Runtime environments(iv)Activation records

A. P – i, Q – ii, R – iv, S - iii
B. P – iii, Q – i, R – ii, S - iv
C. P – ii, Q – iii, R – I, S - iv
D. P – iv, Q – I, R – ii, S - iii
Answer» C. P – ii, Q – iii, R – I, S - iv
10.

Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is :

A. n1 is necessarily less than n2
B. n1 is necessarily equal to n2
C. n1 is necessarily greater than n2
D. none of the options
Answer» C. n1 is necessarily greater than n2
11.

Consider the following parse tree for the expression a # b $ c $ d # e # f, involving two binary operators $ and #.Which one of the following is correct for the given parse tree?

A. $ has higher precedence and is left associative; # is right associative.
B. # has higher precedence and is left associative; $ is right associative
C. $ has higher precedence and is left associative; # is left associative
D. # has higher precedence and is right associative; $ is left associative
Answer» B. # has higher precedence and is left associative; $ is right associative
12.

Consider the following grammar GS → F | HF → p | cH → d | cWhere S, F, and H are non-terminal symbols, p, d, and c are terminal symbols. Which of the following statement(s) is/are correct?S1. LL(1) can parse all strings that are generated using grammar GS2. LR(1) can parse all string that are generated using grammar G

A. Only S1
B. Only S2
C. Both S1 and S2
D. Neither S1 nor S2
Answer» E.
13.

Consider the following context-free grammar where the set of terminals is {a, b, c, d, f}.S → d a T | R fT → a S | b a T | ϵR → c a T R | ϵThe following is a partially-filled LL(1) parsing table.Which one of the following choices represents the correct combination for the numbered cells in the parsing table ("blank" denotes that the corresponding cell is empty)?

A. (1) S → R f (2) S → R f (3) T → ϵ (4) T → ϵ
B. (1) blank (2) S → R f (3) blank (4) blank
C. (1) S → R f (2) blank (3) blank (4) T → ϵ
D. (1) blank (2) S → R f (3) T → ϵ (4) T → ϵ
Answer» B. (1) blank (2) S → R f (3) blank (4) blank
14.

A canonical set of items is given belowS → L. > RQ → R.On input symbol < the set has

A. a shift-reduce conflict and a reduce-reduce conflict
B. a shift-reduce conflict but not a reduce-reduce conflict
C. a reduce-reduce conflict but not a shift-reduce conflict.
D. neither a shift-reduce nor a reduce-reduce conflict
Answer» E.
15.

UNIFORM_SYMBOL_TABLE?$

A. Has all constants in the program
B. Permanent table of rules in the form of patterns for matching with the uniform symbol table to discover syntactic structure
C. Consists of full or partial list of the tokens as they appear in the program created by Lexical analysis and used for syntax analysis and interpretation
D. A permanent table which has all key words and special symbols of the language in symbolic form
Answer» D. A permanent table which has all key words and special symbols of the language in symbolic form
16.

Assembler_is_a_program_that$

A. Puts programs into memory and executes them
B. Translates the assembly language into machine language
C. Writes in high level language and produces an object program
D. None of the mentioned
Answer» C. Writes in high level language and produces an object program
17.

Advantage of incorporating the macro-processor into pass 1 is that

A. Many functions have to be implemented twice
B. Functions are combined not necessarily creating intermediate files as output from the macro-processor and input to the assembler
C. More flexibility is provided to the programmer in that he may use all the features of the assembler in conjunction with macros
D. All of the mentioned
Answer» E.