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.
  • Both A & B

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
  • improve the register allocation
  • 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

  • the information from the front end cannot otherwise be used for optimization
  • 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. An optimizing Compiler?

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

10. 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

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

  • Structure
  • Syntax
  • Semantics
  • Code

12. Syntax directed translation scheme is desirable because

  • it is based on the syntax
  • its description is independent of any implementation
  • it is easy to modify
  • all of these

13. The flow of control in a program of activation tree can be represented by

  • Breadth-first traversal
  • B-tree
  • Depth-first traversal
  • Depth-first traversal

14. What does a Syntactic Analyser do?

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

15. Which of these is not a stage in the compilation process:

  • LEXICAL ANALYSIS
  • CODE OPTIMISATION
  • OBJECT CODE GENERATION
  • SOURCE CODE GENERATION

16. A compiler is a

  • Translator
  • System Software
  • Above 2
  • Inerpreter

17. Removal of left recursion is necessary because?

  • It causes recursive decent parser to loop forever
  • It generates an ambiguous grammar
  • Both a and b
  • None of these

18. 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
  • All of above

19. 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

20. A system program that set-up an executable program in main memory ready for execution is

  • loader
  • linker
  • assembler
  • None of the above

21. Compilers, assemblers and interpreters are examples of this.

  • Translator
  • Run time environment
  • Editor
  • Error diagnostics

22. A basic block can be analyzed by?

  • Flowgraph
  • A graph with cycles
  • DAG
  • Both A & B

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

  • Text Editor
  • Assembler
  • Linker
  • Loader

24. Type checking is normally done during?

  • Lexical Analysis
  • Syntax Analysis
  • Syntax Directed Translation
  • Code generation

25. Consider the following grammar. Which of the following is true regarding LL (1) grammar?

  • No ambiguous or left recursive grammar can be LL(1)
  • No ambiguous but left recursive grammar can be LL(1)
  • No left recursive but ambiguous grammar can be LL(1)
  • No ambiguous or left recursive grammar can be LL(1)

26. Replacement of an expensive operation by a cheaper one is termed as?

  • Reduction in strength
  • Code motion
  • Loop invariant computation
  • All of above

27. The output of a lexical analyzer is

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

28. Access time is minimum for accessing the symbol table which uses?

  • Hash table
  • Search tree
  • Self-organizing list
  • Hash table

29. What is the problem writing machine code?

  • Quick to learn
  • Easy to debug
  • Easy to read
  • Hard to remember the binary codes Hard to remember the binary codes

30. In a syntax directed translation scheme, if value of an attribute of a node is a function of the values of the attributes of its children, then it is called

  • synthesized attribute
  • inherited attribute
  • canonical attribute
  • None of the above

31. Compilers translate high-level language into machine code.

  • True
  • False

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

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

33. Consider the following grammar: A → cAd A → ab/ac/a For Input string cad, how many times the recursive descent parser will backtrack ?

  • 2
  • 3
  • 4
  • 2

34. Number of states require to accept string ends with 10.

  • 3
  • 2
  • 1
  • can’t be represented.

35. It is known as the front-end of the compiler.

  • Analysis Phase
  • Synthesis

36. The lexical analysis for a modern computer language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?

  • Finite state automata
  • Deterministic pushdown automata
  • Non-Deterministic pushdown automata
  • All of above

37. Which of the following parsers is the most powerful?

  • SLR(1)
  • CLR(1)
  • LALR(1)
  • Operator Precedence

38. For DAG interior nodes represents

  • Names
  • Identifiers
  • Constants
  • Operator

39. A parse tree showing attribute value at each node is called?

  • Concrete tree
  • Syntax tree
  • Annotated parse tree
  • All of above

40. Local and loop optimization in turn provides motivation for?

  • Data flow Analysis
  • Peephole optimization
  • DRA and constant folding
  • All of above

41. Inherited attribute is a natural choice in

  • keeping track of variable declaration
  • checking for the correct use of L-values and R-values
  • both (a) and (b)
  • None of these

42. Output file of Lex is _____ the input file is Myfile?

  • Myfile.e
  • Myfile.yy.c
  • Myfile.lex
  • Myfile.obj

43. In SLR parsing for the grammar E’-->E , E--> aEbE|bEaE|ε, In state 0, for inputs ‘a’ and ‘b’

  • Both will have shift-reduce conflict
  • Only ‘a’ will have shift-reduce conflict
  • Only ‘b’ will have shift-reduce conflict
  • Neither of the other option

44. The grammar {E-->E+T|T, T-->T*F|F, F-->id} is

  • Ambiguous
  • Unambiguous
  • Partially ambiguous
  • None of the other options

45. The symbol table implementation is based on the property of locality of reference is -

  • Hash Table
  • Self Organisation
  • Linear list
  • None of the above

46. For a context-free grammar, left hand side of production rules should contain

  • Single nonterminal
  • Set of both terminals and nonterminals
  • Set of terminals
  • None of the other options

47. The regular expression (0|1)*(0|1) represents a language with

  • Odd nonempty strings
  • Even nonempty strings
  • Empty and nonempty binary strings
  • Nonempty binary strings

48. Directly executable by the CPU. Written in 1's and 0's or Hex.

  • Machine Code
  • High Level Language
  • Assembly Language
  • VB.net

49. In some phase of a compiler: Input: temp1: = int to real (60) temp2: = id3 * temp1 temp3: = id2 * temp2 id1: = temp3 Output: temp1: = id3 * 60.0 id1: = id2 + temp1 Where temp1, temp2, temp3 are temporary storage id1, id2, id3 are identifiers. “int to real” is converting int 60 to a real number. The above phase is

  • Code optimizer
  • Code generator
  • Intermediate code generator
  • Code optimizer

50. Consider the following grammar. For Input string cad, how many times the recursive descent parser will back track?

  • 2
  • 3
  • 4
  • 2

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.