About Compiler Design

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

11. A grammar for a programming language is a formal description of

  • 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

15. Which of the following system software resides in the main memory always

  • Text Editor
  • Assembler
  • Linker
  • Loader

16. Which compiler is used for python

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

19. Which of the following statements are TRUE?I. There exist parsing algorithms for some programming languages whose complexities are less than O(n^3).II. A programming language which allows recursion can be implemented with static storage allocation.III. No L-attributed definition can be evaluated in The framework of bottom-up parsing.IV. Code improving transformations can be performed at both source language and intermediate code level.

  • 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

22. 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 of the following statements related to merging of the two sets in the corresponding LALR parser 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.

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

23. What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon- and unit-production (i.e., of type A -> є and A -> a) to parse a string with n tokens?

  • n/2
  • n-1
  • 2n-1
  • n-1

24. In a compiler, keywords of a language are recognized during

  • parsing of the program
  • the code generation
  • the lexical analysis of the program
  • the lexical analysis of the program

25. The number of tokens in the following C statement isprintf("i = %d, &i = %x", i, &i);

  • 3
  • 26
  • 10
  • 10

26. We have two statements S1 and S2 whose definition are as follows:S1 – {02n In ≥ I} is a regular language.S2 – {0m 1n 0 1m+n I m=1 and n≥1I is a regular language.

  • Both S1 and S2 are correct
  • Only S2 is correct
  • Only S1 is correct
  • Neither S1 nor S2 is correct

27. Consider the regular expression 0 * (10 *) which is similar to the same set as

  • 0 + (0 + 10) *
  • (0 +1) * 10 (0 + 1) *
  • (1 * 0) * 1*
  • None of the above

28. Given: ∑= {a, b}L= {xϵ∑*|x is a string combination} ∑4 represents which among the following?

  • {aa, ab, ba, bb}
  • {aaaa, abab, ε, abaa, aabb}
  • {aaa, aab, aba, bbb}
  • All of the above

29. The number of elements in the set for the Language L={xϵ(∑r) *|length if x is at most 2} and ∑={0,1} is_________

  • 7
  • 6
  • 8
  • 5

30. The minimum number of states required to recognize an octal number divisible by 3 are/is:

  • 1
  • 3
  • 5
  • 7

31. The non- Kleene Star operation accepts the following string of finite length over set A = {0,1} | where string s contains even number of 0 and 1

  • 01,0011,010101
  • 0011,11001100
  • ε,0011,11001100
  • ε,0011,11001100

32. Let S and T be language over ={a,b} represented by the regular expressions (a+b*)* and (a+b)*, respectively. Which of the following is true?

  • S⊂TS\subset TS⊂T
  • T⊂ST\subset ST⊂S
  • S=TS=TS=T
  • S∩T≡ϕS\cap T\equiv\phiS∩T≡ϕ

33. If two finite state machines are equivalent, they should have the same number of

  • states
  • edges
  • states and edges
  • none of these

34. Consider the languages L1 = and L2 = {a}. Which one of the following represents L1 L2* U L1*

  • {ø}
  • { ϵ\epsilonϵ }
  • a*
  • { ϵ,\epsilon,ϵ, a }

35. Which among the following looks similar to the given expression?((0+1). (0+1)) *

  • {xϵ {0,1} *|x is all binary number with even length}
  • {xϵ {0,1} |x is all binary number with even length}
  • {xϵ {0,1} *|x is all binary number with odd length}
  • {xϵ {0,1} |x is all binary number with odd length}

36. The Lookahead of Augmented grammar symbol(S') is always...............

  • $
  • 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

42. For the given grammar G:S->ABaCA->BCB->b| \epsilonϵ C->D| \epsilonϵ D-> d

  • 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 + Lookahead
  • LR(0) item + Follow(S')

47. It is a computer program that links and merges various object files together in order to make an executable file.

  • Assembler
  • Compiler
  • Linker
  • Loader

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

49. Operator Precedence Parser is ___ parser

  • 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

Enjoyed the Quiz. Share this with friends

Comments

Add Your Review

Your email address will not be published.

Subscribe to Newsletter!

Subscribe to get latest updates and information.