# Compiler Design MCQ Computer Science

50 Questions 30 Mins

Following are some of the multiple choice questions on the Compiler Design with answers that will help the students in developing their knowledge.

## Compiler Design MCQ

### 1. DAG means

• Directed Acyclic Graph
• Deterministic Acyclic graph
• Directed Automated Graph
• Deterministic Automated graph

### 2. What is the output of lexical analyzer?

• A parse tree
• A list of tokens
• Intermediate code
• Machine code

### 3. LR stands for

• left to right scanning
• left to right reduction
• leftmost to rightmost derivation
• left to right scanning and right most derivation in reverse

### 4. What is machine code?

• Instructions and data in binary
• Serial number of the CPU
• Instructions and data in human readable form
• Instructions and data in assembly code mnemonics

### 5. Which one of the following statements is FALSE ?

• Context-free grammar can be used to specify both lexical and syntax rules.
• Type checking is done before parsing.
• High-level language programs can be translated to different Intermediate Representations.
• Type checking is done before parsing.

### 6. One of the purposes of using intermediate code in compilers is to

• make parsing and semantic analysis simpler
• improve error recovery and error reporting
• increase the chances of reusing the machine-independent code optimizer in other compilers
• increase the chances of reusing the machine-independent code optimizer in other compilers

### 7. Which one of the following is FALSE?

• A basic block is a sequence of instructions where control enters the sequence at the beginning and exits at the end
• Available expression analysis can be used for common subexpression elimination
• Live variable analysis can be used for dead code elimination
• x = 4 ∗ 5 => x = 20 is an example of common subexpression elimination

### 8. Some code optimizations are carried out on the intermediate code because

• they enhance the portability of the compiler to other target processors
• program analysis is more accurate on intermediate code than on machine code
• the information from dataflow analysis cannot otherwise be used for optimization
• they enhance the portability of the compiler to other target processors

### 9. The output of a lexical analyzer is

• A parse tree
• Intermediate code
• Machine code
• A stream of tokens

### 10. An optimizing Compiler?

• Is optimized to occupy less space
• Optimizes the code
• Is optimized to take less time for execution
• Optimizes the code

• Structure

### 12. What does a Syntactic Analyser do?

• Maintain Symbol Table
• Collect type of information
• Create parse tree
• None of the mentioned

### 13. A compiler is a

• Translator
• System Software
• Above 2
• Inerpreter

### 14. A parse tree showing the value of attributes at each node

• annotated parse tree
• syntax tree
• semantic tree
• all of the above

• Text Editor
• Assembler

### 17. The role of predictive parsing is

• To construct a top-down parser that never backtracks
• To construct a top-down parser that backtracks
• To construct a bottom-up parser that never backtracks
• To construct a top-down parser that never backtracks

### 18. Int arr[4.5]; Which phase reports compilation error?

• Lexical Analysis
• Syntax Analysis
• Semantic Analysis
• Intermediate Code Generation

• I and II
• I and IV
• III and IV
• I and IV

### 20. Match all items in Group 1 with correct options from those given in Group 2.Group 1 Group 2P. Regular expression 1. Syntax analysisQ. Pushdown automata 2. Code generationR. Dataflow analysis 3. Lexical analysisS. Register allocation 4. Code optimization

• P-4. Q-1, R-2, S-3
• P-3, Q-1, R-4, S-2
• P-3, Q-4, R-1, S-2
• P-3, Q-1, R-4, S-2

### 21. Multiplication of a positive integer by a power of two can be replaced by left shift, which executes faster on most machines, this is an example of?

• Strength Reduction
• Peephole optimization
• Loop unwinding
• Strength Reduction

• dollar

### 37. If state In contains A⟶α⋅A\longrightarrow\alpha\cdotA⟶α⋅ and B→α.βB\rightarrow\alpha.\betaB→α.β then it will lead to ...............conflict in LR parser

• Shift-Shift
• Shift-Reduce
• Reduce-Reduce
• Action-Goto

### 38. Given the following expression grammar:E -> E * F | F+E | FF -> F-F | idwhich of the following is true?

• * has higher precedence than +
• – has higher precedence than *
• + and — have same precedence
• + has higher precedence than *

### 39. Consider the grammar defined by the following production rules: S --> T * P T --> U | T * U P --> Q + P | Q Q --> Id U --> IdWhich one of the following is TRUE?

• + is left associative, while ∗ is right associative
• + is right associative, while ∗ is left associative
• Both + and ∗ are right associative
• Both + and ∗ are left associative

### 40. Consider the following two sets of LR (1) items of an LR (1) grammar. X -> c.X, c/d X -> .cX, c/d X -> .d, c/d X -> c.X, $X -> .cX,$ X -> .d, \$Which one is true?1. Cannot be merged since look ahead’s 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.

• 1 only
• 2 only
• 1 and 4 only
• 1, 2, 3 and 4 only

### 41. Simplify the given grammar:S->aXbX->aXb | \epsilonϵ

• S->aXb | ab, X-> aXb | ab
• S->X | ab, X-> aXb | ab
• S->aXb | ab, X-> S | ab
• None of the mentioned

• 6
• 7
• 5
• 8

### 43. In context to the process of removing useless symbols, which of the following is correct?

• We remove the Nullable variables
• We eliminate the unit productions
• We eliminate products which yield no terminals/strings
• All of the mentioned

### 44. Left Factoring of A→αβ1 ∣αβ2∣aβ3∣....aβn∣A\rightarrow\alpha\beta1\ \left|\alpha\beta2\right|a\beta3\left|....a\beta n\right|A→αβ1 ∣αβ2∣aβ3∣....aβn∣ yields to..........

•  A→β1∣β2∣β3∣....∣βnA\rightarrow\beta1\left|\beta2\left|\beta3\right|....\right|\beta nA→β1∣β2∣β3∣....∣βn   A′→αA′A'\rightarrow\alpha A'A′→αA′
•  A→αA′A\rightarrow\alpha A'A→αA′  A′→β1∣β2∣β3∣....βn∣A'\rightarrow\beta1\left|\beta2\left|\beta3\right|....\beta n\right|A′→β1∣β2∣β3∣....βn∣

### 45. The First of S isS->ABC A->aA| \epsilonϵ B->bC | \epsilonϵ C-> ea|dbC| \epsilonϵ

• {a, \epsilonϵ  }
• {a}
• {a,b,e,d}
• {a,b,d,e, \epsilonϵ  }

### 46. LR(1) item=___________ + ______________

• LR(0) item + First(S')
• LR(0) item + Action
• LR(0) item + Follow(S')

• Assembler
• Compiler

### 48. If we are able to generate the same string using both leftmost derivation and rightmost derivation, the grammar is said to be ___

• Ambiguous
• Non-deterministic
• Left recursive
• Unambiguous

• Top-down
• Bottom-up

### 50. Consider the grammar defined by the following production rules, with two operators ∗ and + S --> T * P T --> U | T * U P --> Q + P | Q Q --> Id U --> IdWhich one of the following is TRUE?

• + is left associative, while ∗ is right associative
• + is right associative, while ∗ is left associative
• Both + and ∗ are right associative
• + is right associative, while ∗ is left associative