Advertising

Compiler Construction and Design MCQ (Multiple Choice Questions)

Compiler Construction and Design MCQ

1) For the C program given below, the statement that does not hold is for (i = 0; i for(j = 0; jif (i%c) { x += (4*j+5*i); y+=(7+4*j); }}}

a. There is a scope strength reduction
b. There is a scope of dead code elimination
c. There is a scope of common sub-expression elimination
d. None of the above

2) In compilers, the generation of intermediate code based on an abstract machine model is helpful because

a. Syntax-directed translations can be written for intermediate code generation
B. Generating code for real machines directly from high-level language programs is impossible
c. Portability of the front end of the Compiler is enhanced
d. Implementation of lexical and syntax analysis is easier

3) Consider the grammar where P, Q, R are not terminals and r, s, t are terminals

a. P-> Q R
b. P-> Q s R
c. P->ε
d. P-> Q t R r

The grammar rules that violate the requirements of an operator grammar is

a. a and c only
b. b and c only
c. a and d only
d. a only

4) Which one of the following statements is false for the SLR (1) and LALR (1) parsing tables for context-free grammar?

a. The reduced entries in both tables may be different
b. The error entries in both tables may be different
c. The go-to part of both tables may be different
d. The shift entries in both tables may be identical

5) We have a grammar with no epsilon and unit production (i.e., type A->ε and A -> a) to parse a string with n tokens. What is the maximum number of reduced moves a bottom-up parser can take for this grammar?

a. 2n – 1
b. 2n
c. n-1
d. n/2

6) Only two registers are available in the processor’s instruction set architecture. The code motion moves the statements from one place to another while preserving correctness. The only allowed compiler optimization is code motion. In the compiled code, the minimum number of spills to memory is

a. 0
b. 1
c. 2
d. 3

7) Assume no optimization other than optimizing register allocation is applied. To compile this code segment without any spill to memory, the minimum number of registers needed in the instruction set architecture of the processor is

a. 3
b. 6
c. 4
d. 5

8) We have the grammar E->E + n I E x n I n. The handles in the right-sentential form of the reduction for a sentence n + n x n are

a. n, n + n and n + n x n
b. n, E + n and E x n
c. n, E + n and E + E x n
d. n, E + n and E + n x n

9) The languages that need heap allocation in the runtime environment are

a. Those that use global variables
b. Those that use dynamic scoping
c. Those that support recursion
d. Those that allow dynamic data structure

10) When is the type checking usually done?

a. During syntax-directed translation
b. During lexical analysis
c. During code optimization
d. During syntax analysis

11) What information must be included in an object module if a linker is given object modules for a set of programs compiled separately?

a. Names and locations of all external symbols defined in the object module
b. Object code
c. Absolute addresses of internal symbols
d. Relocation bits

12) We have two sets of L.R. (1) items of L.R. (1) grammar described below.

X->C.X, c/d X->C.X, $
X->.cX, c/d X->.cX, $
X->.d, c/d X->.d, $

Related to the merging of two sets in the corresponding Parser, the statement that does not hold is

a. Cannot be merged since look aheads are different.
b. Cannot be merged but will result in R-R conflict
c. Cannot be merged but will result in S-R conflict
d. All of the above

13) While compiling a Pascal program, without looking at the next input character, the string that can be said to be a token is

a. b
b. c
c. a
d. All of the above

14) A shift-reduce parser performs the actions specified within braces immediately after reducing with the corresponding grammar rule. Are you using the syntax-directed translation scheme described by the above rule?

a. 11231
b. 11233
c. 23131
d. 33211

15) In some programming languages, L denotes the set of letters, and D represents the digits. An identifier is permitted to be a letter followed by any number of letters or digits. The expression that defines an identifier is

a. (L.D.)*
b. (L + D)*
c. L (L.D.)
d. L (L + D)*

16. What is CFG?
a. Regular Expression
b. Compiler
c. Language expression
d. All of the mentioned
17. Which of the following errors can the Compiler diagnose?
a. Logical errors only
b. Grammatical and logical errors
c. Grammatical errors only
d. All of the mentioned

18. In which of the following compiler phases is Lexical Analyser?
a. Second
b. Third
c. First
d. All of the mentioned

19. Which of the following does an address code involve?
a. No unary operators
b. Exactly three address
c. At most, Three address
d. None of the mentioned

20. An object module for a group of programs compiled separately is handed to a linker. Which of the following about an object module isn’t true?
a. Relocation bits
b. Names and locations of all external symbols denied in the object module
c. Absolute addresses of internal symbols
d. Object code

21. Characters are grouped into tokens. In which of the following phases of the compiler design are they grouped?
a. Code generator
b. Lexical analyzer
c. Parser
d. Code optimization

22. Why is generating intermediate code based on an abstract machine model helpful in compilers?
a. Writing for intermediate code generation
b. Portability of the front end of the Compiler
c. Implementation of linguistic analysis and syntax analysis is made easier
d. All of the mentioned

23. Why are system programs such as compilers designed?
a. They are Serially usable
b. They are Re-enterable
c. They are Non-reusable
d. All of the mentioned

24. Which techniques are used for building cross-compilers for other machines?
a. Canadian Cross

b. Mexican Cross
c. X-cross
d. Brazilian Cross

25. Which of the following can detect an error if a programmer by mistake writes multiplication instead of division?
a. Interpreter
b. Compiler or interpreter test
c. Compiler
d. None of the mentioned
26. Which table is a permanent database with an entry for each terminal symbol?

a. Reductions

b. Identifier table

c. Literal table

d. Terminal table

27. The action of parsing the source program into proper syntactic classes is called

a General syntax analysis

b. Interpretation analysis

c. Syntax analysis

d. Lexical analysis

28. A bottom-up parser generates

a. Left-most derivation in reverse

b. Left-most derivation

c. Right-most derivation in reverse

d. Right –most derivation

29. The bottom-up parsing method is also called

a. Shift reduces parsing

b. Predictive parsing

c. Recursive descent parsing

d. None of these

30. The method which merges the bodies of two loops is

a. Constant folding

b. Loop jamming

c. Loop unrolling

d. None of these

31. The top-down parsing method is also called

a. Operator precedence parsing

b. Recursive descent parsing

c. Shift reduces parsing

d. None of these

32. Which of the following techniques replaces runtime computations with compile-time computations?

a. Constant folding

b. Code hoisting

c. Peephole optimization

d. Invariant computation

33. The most general phase of structured grammar

a. Context sensitive

b. Context free

c. Regular

d. None of these

34. Which of the following classes of statements usually produces no executable code when compiled?

a. Assignment statement

b. Structural statements

c. Input and output statements

d. Declaration

35. A grammar-oriented compiling technique known as————–

a. Syntax-directed translation
b. Data flow translation
c. Two-pass compiler
d. None of the above.

36. Type checking is usually done during———–

a. Lexical analysis
b. Syntax Analysis
c. Syntax-directed translation
d. Code optimization

37. A parse tree showing the value of attributes at each node is called———-

a. Syntax tree

b. Annotated parse tree
c. Semantic tree                                     

d. All of the above.

38. Inherited attribute is a natural choice in———-

a. keeping track of variable declaration
b. checking for the correct use of L-values and R-values
c. both (A) and (B)
d. None of the above.

39. Syntax-directed translation scheme is desirable because——-

a. it is based on the syntax
b. its description is independent of any implementation
c. it is easy to modify
d. All of the above.

40. A synthesized attribute is an attribute whose value at a parse tree node depends on ——-

a. Attributes at the siblings only                         

b. Attributes at parent node only
c. Attributes at children nodes only                   

d. None of the above.

41. An inherited attribute is an attribute whose value at a parse tree node does not depend on——

a. Attributes at the siblings only                     

b. Attributes at parent node only
c. Attributes at children nodes only               

d. None of the above.

42. Attributes whose values are defined in terms of a node’s attributes, node’s siblings, and node’s parent are called——–

a. Inherited attributes                                     

b. Physical attributes
c. Logical attributes                                         

d. Un-synthesized attributes

43. The——–translation statements can be conveniently specified in YACC.

a. Syntax-directed                                           

b. Image-directed
c. Sign-directed                                                

d. Segment-directed

44. In a bottom-up evaluation of a syntax direction definition, inherited attributes can——-

a. always be evaluated
b. be evaluated only if the definition is L –attributed
c. evaluation is only done if the definition has synthesized attributes
d. None of the above.

45. A ——— can easily simulate synthesized attribute

a. L.L. grammar                                                   

b. Ambiguous grammar
c. L.R. grammar                                                   

d. None of the above.

46. In the synthesized attribute, we can evaluate in————order.

a. Bottom-up                                                     

b. Top-down
c. Preorder                                                          

d. None of the above.

47. In inherited attribute, we can evaluate in———order.

a. Bottom-up

b. Top-down
c. post-order                                                      

d. None of the above

48. An SDD without side effects is called ———

a. Context-free grammar
b. Operator grammar
c. Attribute grammar
d. Both A and C

49. An SDD that involves only synthesized attributes is called——–

a. S-attributed

b. L-attributed
c. Both A and B                                                 

d. None of the above.

50. __________________ is a top-down parser

a. Operator precedence parser
b. An LALR (k) parser
c. An L.R. (k) parser
d. Recursive descent Parser

51. Why are the code optimizations carried out on the intermediate code?

a. Because optimization information from the front end cannot be used
b. Because the program is more accurately analyzed on intermediate than machine code.
c. Because optimization information from data flow analysis cannot be used
d. They enhance the compatibility of the Compiler with the other target processor.

52. When are a language’s keyboards recognized in a compiler?

a. During the linguistic analysis of a program
b. During parsing of the program
c. During the code generation
d. During the data flow analysis

53. In a compiler, the data structure responsible for the management of information about variables and their attributes is

a. Semantic stack
b. Parser table
c. Symbol table
d. Abstract syntax-tree

54. The lexical analysis for Java needs _____________ in a necessary and sufficient sense.

a. Turing machine
b. Non-deterministic push down automata
c. Deterministic push down automata
d. Finite state automata

55. Users write the programs in which language?

a. Low-level Language

b. High-Level Language

c. Decimal-Format

d. Middle-Level Language

56. Which computer program accepts the high-level language and converts it into assembly?

a. Interpreter

b. Linker

c. Assembler

d. Compiler

57. Does the compiler program translate the source code in one step?

a. No

b. Depends on the Compiler

c. Don’t Know

d. Yes

58. Which of the following files is an output of the Assembler?

a. Program file

b. Object file

c. Data File

d. Task File

59. Which tool is used for grouping characters in tokens in the Compiler?

a. Parser

b. Code optimizer

c. Code generator

d. Scanner

60. What is the Linker?

a. It is always used before the program execution.

b. The load module is required.

c. It is the same as the loader

d. None of the above

61. Parsing is categorized into how many types?

a. three types

b. four types

c. two types

d. five types

62. In parsing, the Parser constructs the parse tree from the start symbol and transforms it into the input symbol.

a. Bottom-up parsing

b. Top-down parsing

c. None of the above

d. Both a and b

62. Which derivation is generated by the top-down Parser?

a. Right-most derivation in reverse

b. Left-most derivation in reverse

c. Right-most derivation

d. Left-most derivation

63. Which derivation is generated by the bottom-up Parser?

a. Right-most derivation in reverse

b. Left-most derivation in reverse

c. Right-most derivation

d. Left-most derivation

64. Which Parser is most potent in the following parsers?

a. Operator Precedence

b. SLR

c. Canonical L.R.

d. LALR

65. The output of the lexical analyzer is _______

a. string character

b. syntax tree

c. a set of RE

d. a set of tokens