250+ TOP MCQs on Error Recovery in LR phase and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Error Recovery in LR phase”.

1. The grammar S → aSa | bS | c is?
a) LL(1) but not LR(1)
b) LR(1) but not LR(1)
c) Both LL(1) but not LR(1) & LR(1) but not LR(1)
d) None of the mentioned

Answer: c
Clarification:
First(aSa) = a
First(bS) = b
First(c) = c
LR parsers are more powerful than LL (1) parsers and LR (1).

2. Recursive descent parsing is an example of ____________
a) Top down parsing
b) Bottom up parsing
c) Predictive parsing
d) None of the mentioned

Answer: a
Clarification: Top down is the answer.

3. LR stands for ___________
a) Left to right
b) Left to right reduction
c) Right to left
d) Right most derivation and Left to right and a in reverse

Answer: d
Clarification: Right most derivation and left to right and in reverse is used for LR.

4. Which is the most powerful parser?
a) SLR
b) LALR
c) Canonical LR
d) Operator-precedence

Answer: c
Clarification: Canonical tops all other parsers.

250+ TOP MCQs on Regular Expression and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Regular Expression”.

1. The RE in which any number of 0′s is followed by any number of 1′s followed by any number of 2′s is?
a) (0+1+2)*
b) 0*1*2*
c) 0* + 1 + 2
d) (0+1)*2*

Answer: b
Clarification: The order for the desired string is 012 and for any number of 0s we write 0* for any number of 1s we denote it by 1* and similarly for 2*.Thus 0*1*2*.

2. The regular expression have all strings of 0′s and 1′s with no two consecutive 0′s is?
a) (0+1)
b) (0+1)*
c) (0+∈) (1+10)*
d) (0+1)* 011

Answer: c
Clarification: From the former bracket we choose 0 or epsilon. Then from the latter part 1 or 10 which can be followed by 1 or 10.

3. The regular expression with all strings of 0′s and 1′s with at least two consecutive 0′s is?
a) 1 + (10)*
b) (0+1)*00(0+1)*
c) (0+1)*011
d) 0*1*2*

Answer: b
Clarification: The expression (0+1)*00(0+1)* is where either it initially takes 0 or 1 or 00 followed by string of combination of 0 and 1.

4. Which of the following is NOT the set of regular expression R = (ab + abb)* bbab?
a) ababbbbab
b) abbbab
c) ababbabbbab
d) abababab

Answer: a
Clarification: ab followed by abb which is followed by bbab.

5. String generated by following expression is?

S->aS/bA, A->d/ccA

a) aabccd
b) adabcca
c) abcca
d) abababd

Answer: a
Clarification: S->aS (substitute S->aS)
S->aaS (substitute S->bA)
S->aabA (substitute A->ccA)
S->aabccA (substitute A->d)
S->aabccd.

6. Consider the production of the grammar S->AA A->aa A->bb Describe the language specified by the production grammar.
a) L = {aaaa,aabb,bbaa,bbbb}
b) L = {abab,abaa,aaab,baaa}
c) L = {aaab,baba,bbaa,bbbb}
d) L = {aaaa,abab,bbaa,aaab}

Answer: a
Clarification: S->AA (substitute A->aa)
S->aaaa
S->AA (substitute A->aa )
S->aaA (substitute A->bb)
S->aabb
S->AA (substitute A->bb the A->aa)
S->bbaa
S->AA (substitute A->bb)
S->bbbb.

7. If R is regular language and Q is any language (regular/ non regular), then Pref (Q in R) is _____________
a) Non-regular
b) Equal
c) Infinite
d) Regular

Answer: d
Clarification: So says the definition of Regular Grammar.

8. The production of the form no terminal → Λ is said to be null production.
a) False
b) True

Answer: b
Clarification: Here the non terminal that gives null will said to have a null production.

250+ TOP MCQs on Obtaining the regular Expression from the Finite automata

Compilers test on “Obtaining the Regular Expression from the Finite Automata”.

1. Which of the following identity is true?
a) Ɛ + RR* = R* = ɛ + R*R
b) (R1R2)*R1 = R1 (R2R1)*
c) R*R* = R*
d) All of the mentioned

Answer: d
Clarification: The former Re can be produced from the latter one.

2. The set of all strings over ∑ = {a,b} in which all strings having bbbb as substring is?
a) (a+b)* bbbb (a+b)*
b) (a+b)* bb (a+b)*bb
c) bbb(a+b)*
d) bb (a+b)*

Answer: a
Clarification: Out of all RE mentioned only the first string certainly has bbbb as substring. Rest all just have a possibility of having it.

3. The set of all strings over ∑ ={a,b} in which a single a is followed by any number of b’s a single b followed by any number of a’s is?
a) ab* + ba*
b) ab*ba*
c) a*b + b*a
d) None of the mentioned

Answer: a
Clarification: ab*+ba* is the expression in which a single a is followed by any number of b’s a single b followed by any number of a’s.

4. Regular expressions are used to represent which language?
a) Recursive language
b) Context free language
c) Regular language
d) All of the mentioned

Answer: c
Clarification: Regular expression is represented by regular language.

5. The set of all strings over ∑ = {a,b} in which strings consisting a’s and b’s and ending with in bb is?
a) ab
b) a*bbb
c) (a+b)* bb
d) All of the mentioned

Answer: c
Clarification: Only this expression ends with bb only.

6. If P, Q, R are three regular expressions and if P does not contain a then the equation R = R + RP has a unique solution given by?
a) R = QP*
b) R = P*Q
c) R = RP
d) None of the mentioned

Answer: a
Clarification: It is an important law primarily used in conversion.

7. If L1 and L2 are regular languages is/are also regular language(s).
a) L1 + L2
b) L1L2
c) L1
d) All of the mentioned

Answer: d
Clarification: All these expression give us a regular grammar when L1 and L2 are regular.

8. Which of the following regular expression denotes zero or more instances of an a or b?
a) a/b
b) (a/b)*
c) (ab)*
d) a*Ib

Answer: b
Clarification: This expression gives o or more instances of a or b.

9. The string (a)|((b)*(c)) is equivalent to ______________
a) Empty
b) abcabc
c) b*c|a
d) None of the mentioned

Answer: c
Clarification: Either b or a can lead followed by c this expression can be achieved by C as well.

250+ TOP MCQs on Handle of Right sentinel Grammar and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Handle of Right sentinel Grammar”.

1. DAG representation of a basic block allows __________
a) Automatic detection of local common sub expressions
b) Detection of induction variables
c) Automatic detection of loop variant
d) None of the mentioned

Answer: a
Clarification: It detects local sub expression.

2. Inherited attribute is a natural choice in __________
a) Tracking declaration of a variable
b) Correct use of L and R values
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: These attribute keep a check on variable declaration.

3. An intermediate code form is __________
a) Postfix notation
b) Syntax Trees
c) Three Address code
d) All of the mentioned

Answer: d
Clarification: Intermediate code generator receives input from its predecessor phase, semantic analyzer, in the form of an annotated syntax tree.

4. Which of the following actions an operator precedence parser may take to recover from an error?
a) Insert symbols onto the stack
b) Delete symbols from the stack
c) Inserting or deleting symbols from the input
d) All of the mentioned

Answer: d
Clarification: All these symbols are used to recover operator precedence parser from an error.

5. What is the output of lexical analyzer?
a) A set of regular expression
b) Syntax tress
c) Set of Token
d) String of Characters

Answer: c
Clarification: Lexical analysis is the process of converting a sequence of characters into a sequence of tokens.

6. Which of the following is used for grouping of characters into tokens?
a) Parser
b) Code optimization
c) Code generator
d) Lexical analyser

Answer: d
Clarification: Lexical analysis is the process of converting a sequence of characters into a sequence of tokens.

7. Shift reduce parsers are __________
a) Top down parser
b) Bottom up parser
c) Maybe both
d) None of the mentioned

Answer: b
Clarification: This corresponds to starting at the leaves of the parse tree. It can be thought of a process of reducing the string in question to the start symbol of the grammar. Bottom-up parsing is also known as shift-reduce parsing.

8. A bottom up parser generates __________
a) Right most derivation
b) Right most derivation in reverse
c) Left most derivation
d) Left most derivation in reverse

Answer: b
Clarification: This corresponds to starting at the leaves of the parse tree. It can be thought of. A process of reducing the string in question to the start symbol of the grammar. Bottom-up parsing is also known as shift-reduce parsing.

9. What is garbage?
a) Unallocated storage
b) Allocated storage whose access paths are destroyed?
c) Allocated storage
d) Uninitialized storage

Answer: b
Clarification: These are more like memory loacations with values whose pointers have been revoked.

10. An optimizing compiler __________
a) Is optimized to occupy less space
b) Is optimized to take less time for execution
c) Optimized the code
d) None of the mentioned

Answer: c
Clarification: As the name suggests that it optimizes the code.

250+ TOP MCQs on SDT Schemes to Specify Translation of various Programming Language Construct Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “SDT Schemes to Specify Translation of various Programming Language Construct – 1”.

1. Which of the following is not a feature of the compiler?
a) Converts it into machine code
b) None of the mentioned
c) Slow for debugging
d) Execution time is more

Answer: d
Clarification: No specified execution time.

2. A programming language is to be designed to run on a machine that does not have a big memory.
a) Prefer a 2 pass compiler
b) Prefer an interpreter
c) Not support recursion
d) All of the mentioned

Answer: d
Clarification: If a language designed to run on a machine then recursion should not be followed it should prefer 2 pass assembler and prefer an interpreter to a compiler.

3. What is linker?
a) Is same as the loader
b) Create a load module
c) Is same as the loader & Create a load module
d) None of the mentioned

Answer: b
Clarification: It creates a module to be loaded.

4. Predictive parsers can be __________
a) Recursive
b) Constructive
c) Non recursive
d) Both Recursive and Constructive

Answer: a
Clarification: The nature of predictive parsers can be Recursive.

5. Producer consumer problem can be solved using __________
a) Semaphores
b) Event counters
c) Monitors
d) All of the mentioned

Answer: d
Clarification: The famous producer consumer problem can be solved by a semaphores event counters as well as monitors.

6. Bottom up parsing involves __________
a) Shift reduce
b) Handle pruning
c) Shift reduce & Handle pruning
d) None of the mentioned

Answer: c
Clarification: The bottom up parsing involves Shift reduce operation and Handle pruning.

7. What is an example of intermediate language?
a) SNOBOL
b) PASCAL
c) COBOL
d) UNCOL

Answer: d
Clarification: Others are HLL.

8. In a two pass assembler the object code generation is done during the __________
a) Second pass
b) First pass
c) Zeroth pass
d) Not done by assembler

Answer: a
Clarification: I second pass object code is generated.

250+ TOP MCQs on Compilers Relations and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Relations”.

1. (a,b) what is a?
a) Domain
b) Range
c) Domain & Range
d) None of the mentioned

Answer: a
Clarification: A is called the domain.

2. (a,b) what is b?
a) Domain
b) Range
c) Domain & Range
d) None of the mentioned

Answer: b
Clarification: B is called the Range.

3. R is said to be reflexive if aRa is true for every a in A.
a) True
b) False

Answer: a
Clarification: All the elements of A are related with itself by relation R, hence it is a reflexive relation.

4. If every aRb implies bRa then a relation R will be a symmetric relation.
a) True
b) False

Answer: a
Clarification: a is related to b by R, and if b is also related to a by the same relation R.

5. If every aRb and bRc implies aRc, then the relation is transitive.
a) True
b) False

Answer: a
Clarification: a is related to b by R, and b is related to c by R, and similarly for a and c.

6. The smallest set A such that A ∪ {1, 2} = {1, 2, 3, 5, 9} is?
a) {2,3,5}
b) {1, 2, 5, 9}
c) {3, 5, 9}
d) None of the mentioned

Answer: c
Clarification: Given A ∪ {1, 2} = {1, 2, 3, 5, 9}. Hence A = {3,5,9}.

7. If a set A has n elements, then the total number of subsets of A is?
a) N
b) 2n
c) N2
d) 2n

Answer: b
Clarification: Number of subsets of A = nC0 + nC1 + . . . . . + nCn = 2n.