Top 80+ Solved Theory of Computation and Compiler Design MCQ Questions Answer
Q. 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?
a. Finite state automata
b. Deterministic pushdown automata
c. Non-Deterministic pushdown automata
d. Turing Machine
Q. Consider the following statements:(I) The output of a lexical analyzer is groups of characters.(II) Total number of tokens in printf("i=%d, &i=%x", i, &i); are 11.(III) Symbol table can be implementation by using array and hash table but not tree.Which of the following statement(s) is/are correct?
a. Only (I)
b. Only (II) and (III)
c. All (I), (II), and (III)
d. None of these
Q. Which one of the following statements is FALSE?
a. Context-free grammar can be used to specify both lexical and syntax rules.
b. Type checking is done before parsing.
c. High-level language programs can be translated to different Intermediate Representations.
d. Arguments to a function can be passed using the program stack.
Q. Consider the following statements related to compiler construction : I. Lexical Analysis is specified by context-free grammars and implemented by pushdown automata. II. Syntax Analysis is specified by regular expressions and implemented by finite-state machine. Which of the above statement(s) is/are correct?
a. Only I
b. Only II
c. Both I and II
d. Neither I nor II
Q. Which of the following statement(s) regarding a linker software is/are true?I. A function of a linker is to combine several object modules into a single load module.II. A function of a linker is to replace absolute references in an object module by symbolic references to locations in other modules.
a. Only I
b. Only II
c. Both I and II
d. Neither I nor II
Q. The number of tokens in the following C statement is printf("i=%d, &i=%x",i&i);
a. 13
b. 6
c. 10
d. 9
Q. In compiler optimization, operator strength reduction uses mathematical identities to replace slow math operations with faster operations. Which of the following code replacements is an illustration of operator strength reduction?
a. Replace P + P by 2 * P or Replace 3 + 4 by 7.
b. Replace P * 32 by P < < 5
c. Replace P * 0 by 0
d. Replace (P < <4) – P by P * 15
Q. Debugger is a program that
a. allows to examine and modify the contents of registers
b. does not allow execution of a segment of program
c. allows to set breakpoints, execute a segment of program and display contents of register
d. All of the above
Q. 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 thecorresponding 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.
a. 1 only
b. 2 only
c. 1 and 4 only
d. 1, 2, 3, and 4
Q. Which of the following statements are TRUE?I. There exist parsing algorithms for some programming languages whose complexities are less than O(n3).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.
a. I and II
b. I and IV
c. III and IV
d. I, III and IV
Q. Which of the following describes a handle (as applicable to LR-parsing) appropriately?
a. It is the position in a sentential form where the next shift or reduce operation will occur
b. It is non-terminal whose production will be used for reduction in the next step
c. It is a production that may be used for reduction in a future step along with a position in the sentential form where the next shift or reduce operation will occur
d. It is the production p that will be used for reduction in the next step along with a position in the sentential form where the right hand side of the production may be found
Q. An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if andonly if
a. the SLR(1) parser for G has S-R conflicts
b. the LR(1) parser for G has S-R conflicts
c. the LR(0) parser for G has S-R conflicts
d. the LALR(1) parser for G has reduce-reduce conflicts
Q. Consider the following two statements:P: Every regular grammar is LL(1)Q: Every regular set has a LR(1) grammarWhich of the following is TRUE?
a. Both P and Q are true
b. P is true and Q is false
c. P is false and Q is true
d. Both P and Q are false
Q. Consider the following grammar.S -> S * ES -> EE -> F + EE -> FF -> idConsider the following LR(0) items corresponding to the grammar above.(i) S -> S * .E(ii) E -> F. + E(iii) E -> F + .EGiven the items above, which two of them will appear in the same set in the canonicalsets-of-items for the grammar?
a. (i) and (ii)
b. (ii) and (iii)
c. (i) and (iii)
d. None of the above