Compiler Construction MCQ With Answer & Explanation|Principles of Modern Compiler Design MCQ Set|SPPU Exam Covid-19 Time


 

A.  Lexical Analysis(Scanner)



1. What is the output of lexical analyzer?
a) A set of RE
b) Syntax Tree
c) Set of Tokens
d) String Character
View Answer

Answer: c
Explanation: A lexical analyzer coverts character sequences to set of tokens.

2. Which symbol table implementation is based on the property of locality of reference?

a) Linear list
b) Search tree
c) Hash Table
d) Self Organisation
View Answer

Answer: c
Explanation: Hash table is used as a reference for symbol table because it is efficient.

3. Which of the following is true for operator precedence parsing?
a) For all pair of non-

terminalb) For all pair of non-terminals
c) To delimit the handle
d) None of the mentioned
View Answer: a
Explanation: There are two important properties for these operator precedence parsers is that it does not appear on the right side of any production and no production has two adjacent non-terminals. Implying that no production right side is empty or has two adjacent non-terminals. So accordingly to property option (A) is correct.

4. What is an Object program?
a) Program written in machine language
b) Program to be translated into machine language
c) Translation of high-level language into machine language
d) None of the mentioned
View Answer

Answer: c
Explanation: Since the input is the source language and the output that we get after the analysis is the machine language.

5. Which concept of FSA is used in the compiler?
a) Lexical analysis
b) Parser
c) Code generation
d) Code optimization
View Answer

Answer: a
Explanation: Because the lexer performs its analysis by going from one stage to another.

6. Which concept of grammar is used in the compiler?
a) Lexical analysis
b) Parser
c) Code generation
d) Code optimization
View Answer

Answer: b
Explanation: As the lexical analysis of a grammar takes place in phases hence it is synonymous to parser.

7. Which of the following are Lexemes?
a) Identifiers
b) Constants

c) Keywords
d) All of the mentioned
View Answer

Answer: d
Explanation: Different Lexical Classes or Tokens or Lexemes Identifiers, Constants, Keywords, Operators.

 

 

1. What constitutes the stages of the compilation process?
a) Feasibility study, system, design, and testing
b) Implementation and documentation
c) Lexical analysis, syntax, Analysis and code generation
d) None of the mentioned
View Answer

Answer: c
Explanation: As defined in the compilation process.

2. The lexical analyzer takes _________ as input and produces a stream of _______ as output.
a) Source program, tokens
b) Token, source program
c) Either of the two
d) None of the mentioned
View Answer

Answer: a
Explanation: As per the definition of Lexical Analyser which states that lexical analysis is the process of converting a sequence of characters into tokens.

3. Parsing is also known as ________
a) Lexical Analysis
b) Syntax Analysis
c) Semantic Analysis
d) Code Generation
View Answer

Answer: b
Explanation: Parsing or syntactic analysis is the process of analysing a string of symbols and conforming to the rules of grammar.

4. A compiler program written in a high level language is called ________
a) Source Program
b) Object Program
c) Machine Language Program
d) None of the mentioned
View Answer

Answer: a
Explanation: The input that we give in high level language is also known as the source language.

5. System program such a compiler are designed so that they are ________
a) Re-enterable
b) Non-Usable
c) Serially usable
d) None of the mentioned
View Answer

Answer: a
Explanation: For the convince of the user compilers are made re-enterable.

6. Which of the following is not a feature of compiler?
a) Scan the entire program first and translate into machine code
b) To remove syntax errors
c) Slow for debugging
d) Execution time is more
View Answer

Answer: d
Explanation: The objective of the compiler is clearly not to increase the execution time of the program.

7. A system program that brings together separately compiled modules of a program into a form language that is suitable for execution.
a) Assembler
b) Linking loader
c) Cross compiler
d) None of the mentioned
View Answer

Answer: b
Explanation: A loader which brings together the functions of a relocating loader with the ability to combine a number of program segments that have been independently compiled into an executable program.

8. A programmer by mistakes writes a program to multiply two numbers instead of dividing them, how can this error be detected?
a) Compiler
b) Interpreter
c) Compiler or interpreter
d) None of the mentioned
View Answer

Answer: d
Explanation: This is a logical error that can’t be detected by any compiler or interpreter.
 
 

 

 

B. Syntax Analysis(Parsing)

 

1. Which of the following derivations does a top-down parser use while parsing an input string?
a) Leftmost derivation
b) Leftmost derivation in reverse
c) Rightmost derivation
d) Rightmost derivation in reverse
View Answer

Answer: a
Explanation: In top down parser takes input from Left to right constructing leftmost derivation of the sentence.

2. The process of assigning load addresses to the various parts of the program and adjusting the code and data in the program to reflect the assigned addresses is called?
a) Assembly
b) Parsing
c) Relocation
d) Symbol resolute
View Answer

Answer: c
Explanation: Relocation is the process of replacing symbolic references or names of libraries with actual usable addresses in memory before running a program. Linker performs it during compilation.

3. Which of the following statements is false?
a) Left as well as right most derivations can be in Unambiguous grammar
b) An LL (1) parser is a top-down parser
c) LALR is more powerful than SLR
d) Ambiguous grammar can’t be LR (k)
View Answer

Answer: a
Explanation: If a grammar has more than one leftmost (or rightmost) derivation the grammar is ambiguous. Sometimes in unambiguous grammar the rightmost derivation and leftmost derivations may differ.

4. Which of the following grammar rules violate the requirements of an operator grammar?

(i) P -> QR
(ii) P -> QsR
(iii) P -> ε
(iV) P -> QtRr

a) (i) only
b) (i) and (iii) only
c) (ii) and (iii) only
d) (iii) and (iv) only
View Answer

Answer: b
Explanation: An operator precedence parser is a bottom-up parser that interprets an operator-precedence grammar.
Consider the grammar with the following translation rules and E as the start symbol.
A -> A1 #B {A.value = A1.value * B.value}
| B {A.value = B.value}
B-> B1 & F {B.value = B1.value + C.value}
|C {B.value= C.value }
C -> num {C.value = num.value}.

5. Compute E.value for the root of the parse tree for the expression:2 # 3 & 5 # 6 &4.
a) 200
b) 180
c) 160
d) 40
View Answer

Answer: c
Explanation: Higher precedence operator will never produce an expression with operator with lower precedence.&># in terms of precedence order.

6. Given the following expression grammar:

E -> E * F | F+E | F
F -> F-F | id

which of the following is true?
a) * has higher precedence than +
b) – has higher precedence than *
c) + and — have same precedence
d) + has higher precedence than *
View Answer

Answer: b
Explanation: Precedence is that a higher precedence operator will never produce an expression with operator with lower precedence.
In the given grammar MINUS has higher precedence than ASTERIX.

7. Consider a program P that consists of two source modules M1(contains reference to a function defined in M2) and M2 contained in two different files.
a) Edit time
b) Compile time
c) Link time
d) Load time
View Answer

Answer: c
Explanation: Compiler transforms source code into the machine language which is in binary.
Kinds of object codes:
i. Defined symbols, which allow it to be called by other modules,
ii. Undefined symbols, which call the other modules where these symbols are defined, and
iii. Symbols which are used internally within object file for relocation.

8. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
a) Removing left recursion only
b) Factoring the grammar alone
c) Factoring & left recursion removal
d) None of the mentioned
View Answer

Answer: d
Explanation: Factoring as well as left recursion removal do not suffice to convert an arbitrary CFG to LL(1) grammar.

9. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states.
a) n1 is necessarily less than n2
b) n1 is necessarily equal to n2
c) n1 is necessarily greater than n2
d) none of the mentioned
View Answer

Answer: b
Explanation: SLR parser has less range of context free languages than LALR but still both n1 & n2 are same for SLR & LALR respectively.

10. Match the following.

P. Regular expression        1. Syntax analysis
Q. Pushdown automata         2. Code generation
R. Dataflow analysis         3. Lexical analysis
S. Register allocation       4. Code optimization

a) P-4. Q-1, R-2, S-3
b) P-3, Q-1, R-4, S-2
c) P-3, Q-4, R-1, S-2
d) P-2, Q-1, R-4, S-3
View Answer

Answer: b
Explanation: Syntax analysis has Regular expressions. The code optimization goes hand in hand with data flow analysis. Whereas CFG is related to PDA which is related to syntax analysis Register allocation is used in reference with code generation.
 
 

1. Find the TRUE statement?

I.  There exist parsing algorithms for some programming languages which has O(3) complexity.
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 intermediate code level and source Language.

a) I and II
b) I and IV
c) III and IV
d) I III and IV
View Answer

Answer: b
Explanation: In recursion, space used but recursive call can’t be calculated by the compiler.

2. Which of the following describes a handle (as applicable to LR-parsing) appropriately?
a) Position where next reduce or shift operation will occur
b) The next step has use of Non-terminal for reduction
c) Used for reduction in a coming-up step along with a position in the sentential form where the next shift or reduce operation will occur
d) Used in the next step for reduction along with a position in the sentential form where the right hand side of the production may be found
View Answer

Answer: d
Explanation: the next step in LR parsing shall have a Reduction.

3. Which one of the following is a top-down parser?
a) Recursive descent parser
b) Operator precedence parser
c) An LR(k) parser
d) An LALR(k) parser
View Answer

Answer: a
Explanation: Recursive Descent also known as top down parsing also known to be LL(1).
Consider the following two statements:
P: Every regular grammar is LL(1)
Q: Regular is LR(1) grammar.

4. Which 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
View Answer

Answer: c
Explanation: Ambiguity can be seen in regular grammar
S → aA/a
A → aA/ε
In above grammar, string ‘a’ has two leftmost
derivations.
S → aA
S → a
S->a (using A->ε).

5. Consider the grammar defined by the following production rules:

    S --> T * P 
    T --> U | T * U
    P --> Q + P | Q
    Q --> Id
    U --> Id

Which one of the following is TRUE?
a) + is left associative, while ∗ is right associative
b) + is right associative, while ∗ is left associative
c) Both + and ∗ are right associative
d) Both + and ∗ are left associative
View Answer

Answer: b
Explanation: It is associative we can see and tell.
Second productions latter part shows left recursion and is left associative.

6. The grammar A → AA | (A) | e is not suitable for predictive-parsing because the grammar is?
a) Ambiguous
b) Left recursive
c) Right recursive
d) An operator grammar
View Answer

Answer: b
Explanation:
A ::= A a
| b is the left recursive language.

7. Consider the grammar.

E → E + n | E × n | n 

For a sentence n + n × n, the handles in the right-sentential form of the reduction are __________
a) n, E + n and E + n × n
b) n, E + n and E + n × n
c) n, n + n and n + n × n
d) n, E + n and E × n
View Answer

Answer: d
Explanation: E → E + n {Applying E → E + n }
→ E + E * n {Applying E → E * n }
→ E + n * n {Applying E → n }
→ n + n * n {Applying E → n }.

8. Which grammar rules violate the requirements of an operator grammar?

1.  P → Q R                    
2.  P → Q s R
3.  P → ε       
4.  P → Q t R r

a) 1 only
b) 1 and 3 only
c) 2 and 3 only
d) 3 and 4 only
View Answer

Answer: b
Explanation: Top down parsin: We begin with the start symbol and compare the right side of the different productions against the first piece of input to see which of the productions should be used.

9. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
a) Removing left Recursive alone
b) Factoring the grammar alone
c) Along with removing left recursion we also perform the factoring of the grammar
d) None of the mentioned
View Answer

Answer: d
Explanation: Removing left recursion and factoring the grammar do not suffice to convert an arbitrary CFG to LL(1) grammar.

10. In a bottom-up evaluation of a syntax directed definition its inherited attributes can do which of the following?
a) Always evaluated
b) Can be evaluated if the definition is L attributed
c) Can be evaluated if the definition has synthesized attributes
d) Never be evaluated
View Answer

Answer: b
Explanation: A Syntax Directed Definition (SDD) is called S Attributed if it has only synthesized attributes. Also the L-Attributed Definitions contain both synthesized and inherited attributes but do not need to build a dependency graph to evaluate them. 
 
 

1. What is the grammar for the below equations?

S → C C
C → c C | d

a) LL(1)
b) SLR(1) but not LL(1)
c) LALR(1) but not SLR(1)
d) LR(1) but not LALR(1)
View Answer

Answer: a
Explanation: Since there is no conflict, the grammar is LL (1) hence a predictive parse table with no conflicts can be constructed.

2. Which of the following statements is false?
a) Unambiguous grammar has both kind of derivations
b) An LL(1) parser is a top-down parser
c) LALR is more powerful than SLR
d) Ambiguous grammar can’t be LR(k)
View Answer

Answer: a
Explanation: If a grammar has more than one leftmost (or rightmost) derivation the grammar is ambiguous.

3. Given the following expression grammar:

E -> E * F | F + E | F
F -> F - F | id 

Which of the following is true?
a) * has higher precedence than +
b) – has higher precedence than *
c) + and — have same precedence
d) + has higher precedence than *
View Answer

Answer: b
Explanation: e.g. input is 3*4-5 r
         E
     /  |  \
     E   *   F
  |     / | \
  F    F - F
  |    |     |
id (3) id (4) id (5)

First ‘- ‘ is be evaluated then ‘ *’

4. Which one of the following is true at any valid state in shift-reduce parsing?
a) At the bottom we find the prefixes
b) None of the mentioned
c) Stack contains only viable prefixes
d) Stack consists of viable prefixes
View Answer

Answer: c
Explanation: The prefixes on the stack of a shift-reduce parser are called viable prefixes.

5. In the context of abstract-syntax-tree and control-flow-graph. Which one of the following is true?
a) In both AST and CFG if node N2 be the successor of node N1
b) For any input program, neither AST nor CFG will contain a cycle
c) The max number of successors of a node in an AST and a CFG depends on the input program
d) None of the mentioned
View Answer

Answer: c
Explanation: Successors depends on input .

6. Match the following.

      List-I                  List-II
A. Lexical analysis       1. Graph coloring
B. Parsing                2. DFA minimization
C. Register allocation    3. Post-order traversal
D. Expression evaluation  4. Production tree

a) A – 2, B – 3, C – 1, D – 4
b) A – 2, B – 1, C – 4, D – 3
c) A – 2, B – 4, C – 1, D – 3
d) A – 2, B – 3, C – 4, D – 1
View Answer

Answer: c
Explanation: The entire column an items matches the Column B items in a certain way.

7. Which of the following pairs is the most powerful?
a) SLR, LALR
b) Canonical LR ,LALR
c) SLR canonical LR
d) LALR canonical LR
View Answer

Answer: c
Explanation parser algorithm is simple.

8. Consider the following grammar G.

  S → F ⎪ H
  F → p ⎪ c
  H → d ⎪ c

Which one is true?
S1: All strings generated by G can be parsed with help of LL (1).
S2: All strings generated by G can be parsed with help of LR (1).
a) Only S1
b) Only S2
c) Both S1 & S2
d) None of the mentioned
View Answer

Answer: d
Explanation: There is ambiguity as the string can be derived in 2 possible ways.
First Leftmost Derivation
S → F
F → c
Second Leftmost Derivation
S → H
H → c.

9. 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 to parse a string with n tokens?
a) n/2
b) n-1
c) 2n-1
d) 2^n
View Answer

Answer: b
Explanation: The moves are n-1.

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

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.

a) 1 only
b) 2 only
c) 1 and 4 only
d) 1, 2, 3 and 4 only
View Answer

Answer: d
Explanation: All these are valid reasons.
 
 

1. Inherited attribute is a natural choice in ___________
a) Variable declarations record is maintained
b) L values and R values
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: a
Explanation: It keeps track of variable.

2. YACC builds up __________
a) SLR parsing table
b) Canonical LR parsing table
c) LALR parsing table
d) None of the mentioned
View Answer

Answer: c
Explanation: It is a parser generator.

3. In an absolute loading scheme which loader function is accomplished by assembler?
a) Re-allocation
b) Allocation
c) Linking
d) Loading
View Answer

Answer: a
Explanation: Large number variables onto a small number of CPU register.

4. A parser with the valid prefix property is advantageous because it __________
a) Detects errors
b) None of the mentioned
c) Errors are passed to the text phase
d) All of the mentioned
View Answer

Answer: c
Explanation: Advantage for a valid prefix property.

5. The action of parsing the source program into proper syntactic classes is called __________
a) Syntax Analysis
b) Lexical Analysis
c) Interpretation analysis
d) General Syntax Analysis
View Answer

Answer: b
Explanation: Conversion of characters to tokens.

6. Relocating bits used by relocating loader are specified by __________
a) Relocating loader itself
b) Linker
c) Assembler
d) Macro Processor
View Answer

Answer: b
Explanation: Takes an object files and combines them into a single executable file, library file, or another object file.

7. What is the binary equivalent of the decimal number 368?
a) 10111000
b) 110110000
c) 111010000
d) 111100000
View Answer

Answer: b
Explanation: 368 binary equivalents is
8=1000
6=0110
3=0011
So 1101101000.

8. AB+(A+B)’ is equivalent to __________
a) A?B
b) A+B
c) (A+B)A
d) (A+B)B
View Answer

Answer: a
Explanation: It is equivalent to A? B.

9. A top down parser generates __________
a) Rightmost Derivation
b) Right most derivation in reverse
c) Left most derivation
d) Left most derivation in reverse
View Answer

Answer: c
Explanation: Top-down parsing is a parsing strategy where one first looks at the highest level of the parse tree and works down the parse tree by using the rewriting rules of a formal grammar.

10. Running time of a program depends on __________
a) Addressing mode
b) Order of computations
c) The usage of machine idioms
d) All of the mentioned
View Answer

Answer: d
Explanation: Run time, runtime or execution time is the time during which a program is running (executing).
 
 

2. A bottom up parser generates __________
a) Right most derivation
b) Rightmost derivation in reverse
c) Leftmost derivation
d) Leftmost derivation in reverse
View Answer

Answer: b
Explanation: This corresponds to starting at the leaves of the parse tree also known as shift-reduce parsing.

3. A grammar that produces more than one parse tree for some sentence is called __________
a) Ambiguous

b) Unambiguous
c) Regular
d) None of the mentioned
View Answer

Answer: a
Explanation: ambiguous grammar has more than one parse tree.

4. An optimizer Compiler __________
a) Is optimized to occupy less space
b) Is optimized to occupy less space & Optimize the code
c) Optimize the code
d) None of the mentioned
View Answer

Answer: d
Explanation: In computing, an optimizing compiler is a compiler that tries to minimize or maximize some attributes of an executable computer program.

5. The linker __________
a) Is similar to interpreter
b) Uses source code as its input
c) Is required to create a load module
d) None of the mentioned
View Answer

Answer: c
Explanation: It is a program that takes one or more object files generated by a compiler and combines them into a single executable file, library file, or another object file.

6. A latch is constructed using which two cross coupled?
a) AND OR gates
b) AND gates
c) NAND and NOR gates
d) NAND gates
View Answer

Answer: d
Explanation: It has two inputs and one output.

7. Pee Hole optimization __________
a) Loop Optimization
b) Local Optimization
c) Constant folding
d) Data Flow analysis
View Answer

Answer: c
Explanation: More loops are added.

8. The optimization which avoids test at every iteration is?
a) Loop unrolling
b) Loop jamming
c) Constant folding
d) None of the mentioned
View Answer

Answer: a
Explanation: Execution speed is enhanced by sacrificing bits.

9. Scissoring enables __________
a) A part of data to be displayed
b) Entire data to be displayed
c) None of the mentioned
d) No data to be displayed
View Answer

Answer: a
Explanation: Displays only some part of the data.

10. Shift reduce parsers are __________
a) Top down Parser
b) Bottom Up parser
c) May be top down or bottom up
d) None of the mentioned
View Answer

Answer: b
Explanation: Also known as shift reduce parser.

 

 

C. Syntax Directed Definition & Translation

 

1. In a single pass assembler, most of the forward references can be avoided by putting the restriction ___________
a) On the number of strings/life reacts
b) Code segment to be defined after data segment
c) On unconditional rump
d) None of the mentioned
View Answer

Answer: b
Explanation: A single pass assembler scans the program only once and creates the equivalent binary program.

2. The method which merges the bodies of two loops is?
a) Loop rolling
b) Loop jamming
c) Constant folding
d) None of the mentioned
View Answer

Answer: b
Explanation: In computer science, loop fusion (or loop jamming) is a compiler optimization and loop transformation which replaces multiple loops with a single one.

3. Assembly code data base is associated with ___________
a) Code is converted into assembly
b) Table of rules in the form of patterns for matching with the uniform symbol table to discover syntactic structure
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: a
Explanation: An assembly language is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generally one-to-one) correspondence between the language and the architecture’s machine code instructions.

4. The process manager has to keep track of ___________
a) Status of each program
b) Information to a programmer using the system
c) Status of each program & Information to a programmer using the system
d) None of the mentioned
View Answer

Answer: c
Explanation: Process manager keep track of the status and info about the program.

5. What is the function of the syntax phase?
a) recognize the language and to cal the appropriate action routines that will generate the intermediate form or matrix for these constructs
b) Build a literal table and an identifier table
c) Build a uniform symbol table
d) Parse the source program into the basic elements or tokens of the language
View Answer

Answer: a
Explanation: In this phase symbol table is created by the compiler which contains the list of lexemes or tokens.

6. If E be a shifting operation applied to a function f, such that E(f) = f (x +β ), then?
a) E (αf+β g) = α E(f) +β E (g)
b) E (αf +β g ) =. ( α+ β ) + E (f + g)
c) E (αf +β g ) = α E (f+gβ)
d) E (αf +β g ) = αβ E (f + g)
View Answer

Answer: a
Explanation: Shifting operation when performed gives this result.

7. Pass I ______________
a) Assign address to all statements
b) Save the values assigned to all labels for use in pass 2
c) Perform some processing
d) All of the mentioned
View Answer

Answer: d
Explanation: The pass 1 of a compiler the above mentioned functions are performed

8. Which table is a permanent database that has an entry for each terminal symbol?
a) Terminal Table
b) Literal Table
c) Identifier Table
d) None of the mentioned
View Answer

Answer: a
Explanation: A database that has entry for each terminal symbols such as arithmetic operators, keywords, punctuation characters such as ‘;’, ‘,’etc Fields: Name of the symbol.

9. Which of the following functions is performed by loader?
a) Allocate memory for the programs and resolve symbolic references between objects decks
b) Address dependent locations, such as address constants, to correspond to the allocated space
c) Physically place the machine instructions and data into memory
d) All of the mentioned
View Answer

Answer: d
Explanation: A loader is the part of an operating system that is responsible for loading programs and libraries.

10. The root directory of a disk should be placed ___________
a) At a fixed address in main memory
b) At a fixed location on the disk
c) Anywhere on the disk
d) None of the mentioned
View Answer

Answer: b
Explanation: Root directory is placed at a fixed disk location
 
 

5. Which of the following is true for machine language?
a) Continuous execution of program segments
b) Depicting flow of data in a system
c) A sequence of instructions which solves a problem
d) The language which interacts with the computer using only the binary digits 1 and 0
View Answer

Answer: d
Explanation: Machine code or machine language is a set of instructions executed directly by a computer’s central processing unit (CPU). Each instruction performs a very specific task.

6. Software that measures, monitors, and controls events are ___________
a) System S/w
b) Real Time software
c) Scientific software
d) Business Software
View Answer

Answer: b
Explanation: In computer science, real-time computing (RTC), or reactive computing describes hardware and software systems subject to a “real-time constraint”, for example operational deadlines from event to system response.

7. A linker is given object module for a set of programs that were compiled separately. What is not true about an object module?
a) Object code
b) Relocation bits
c) Names and locations of all external symbols denied in the object module
d) Absolute addresses of internal symbols
View Answer

Answer: d
Explanation: A linker or link editor is a computer program that takes one or more object files generated by a compiler and combines them into a single executable file, library file, or another object file.

8. The table created by lexical analysis to describe all literals used in the source program is?
a) Terminal table
b) Literal table
c) Identifier table
d) Reductions
View Answer

Answer: b
Explanation: In computer science, and specifically in compiler and assembler design, literal pool is a lookup table used to hold literals during assembly and execution.

9. Which loader function is accomplished by loader?
a) Reallocation
b) Allocation
c) Linking
d) Loading
View Answer

Answer: d
Explanation: Function of a loader.

10. What is Pass 2?
a) Assemble instruction and generate data
b) Perform processing of assembler
c) Write the object program
d) All of the mentioned
View Answer

Answer: d
Explanation: A multi-pass compiler is a type of compiler that processes the source code or abstract syntax tree of a program several times. Each pass takes the result of the previous pass as the input and creates an intermediate output.
 
 

1. Which is not true about syntax and semantic parts of a computer language?
a) Semantics is checked mechanically by a computer
b) Semantics is the responsibility of the programmer
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: d
Explanation: Both in terms of semantics is not true.

2. Which of the following statement is true?
a) SLR powerful than LALR
b) LALR powerful than Canonical LR parser
c) Canonical LR powerful than LALR parser
d) The parsers SLR= Canonical LR=LALR
View Answer

Answer: c
Explanation: LR > LALR > SLR In terms of the parser.

3. Which of the following features cannot be captured by CFG?
a) Syntax of if-then-else statements
b) Syntax of recursive procedures
c) A variable is declared before its use
d) Matching nested parenthesis
View Answer

Answer: d
Explanation: It is because, it is equivalent to recognizing us, where the first w is the declaration and the second is its use, we are not a CFG.

4. In which of the following no information hiding is done?
a) Compile prig 1, prig 2
b) Run test, prog
c) Load R1, A
d) 001001000010101
View Answer

Answer: d
Explanation: The entire binary symbol gives information.

5. The identification of common sub-expression and replacement of run-time computations by compile-time computations is _____________
a) Local optimization
b) Loop optimization
c) Constant folding
d) Data flow analysis
View Answer

Answer: c
Explanation: Constant folding is the process of recognizing and evaluating constant expressions at compile time rather than computing them at runtime. Terms in constant expressions are typically simple literals they may also be variables whose values are assigned at compile time.

6. The graph that shows basic blocks and their successor relationship is called ____________
a) Dag
b) Flow Graph
c) Control Graph
d) Hamilton Graph
View Answer

Answer: b
Explanation: Flow graph shows the basic blocks.

7. The specific task storage manager performs ____________
a) Allocation/ deal location of programs
b) Protection of storage area assigned to the program
c) Allocation/ deal location of programs & protection of storage area assigned to the program
d) None of the mentioned
View Answer

Answer: c
Explanation: Its basic function is that of the task storage manager.

8. When a computer is rebooted, a special type of loader is executed called?
a) Compile and GO ” loader
b) Boot loader
c) Bootstrap Loader
d) Relating Loader
View Answer

Answer: c
Explanation: A boot loader, is a small program that places the operating system (OS) of a computer into memory.

9. What is the disadvantage of ” Compile and GO ” loading scheme?
a) Memory is wasted because the case occupied by the assembler is unavailable to the object program
b) Necessary to translate the users program
c) It is very difficult to handle multiple segments, even when the source programs are in different languages and to produce orderly modular programs
d) All of the mentioned
View Answer

Answer: d
Explanation: In computer programming, a compile and go system, compile, load, and go system, assemble and go system, or load and go system[1][2][3] is a programming language processor in which the compilation, assembly, or link steps are not separated from program execution.

10. What is the function of the storage assignment?
a) Assign storage to all variables referenced in the source program
b) Assign storage to all temporary locations that are necessary for intermediate results
c) Assign storage to literals, and to ensure that the storage is allocated and appropriate locations are initialized
d) All of the mentioned
View Answer

Answer: d
Explanation: The storage assignment performs the above mentioned tasks.
 
 
D. Error Detection & Recovery
 
 

1. Choose the correct statement.
a) CFG is not LR
b) Ambiguous Grammar can never be LR
c) CFG is not LR & Ambiguous Grammar can never be LR
d) None of the mentioned
View Answer

Answer: c
Explanation: Mentioned reason is true.

2. How is the parsing precedence relations defined?
a) None of the mentioned
b) All of the mentioned
c) To delimit the handle
d) Only for a certain pair of terminals
View Answer

Answer: b
Explanation: The reason why the precedence operations is performed.

3. When will the relationship between ‘+’ and ‘-’ be <?
a) For unary minus
b) Minus is right associative
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: c
Explanation: Both statements are true.

4. When will the relationship between ‘<’ and ‘>’ be <?
a) >
b) <
c) =
d) Undefined
View Answer

Answer: d
Explanation: Undefined. There is no existing relationship between the two.
 
 

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Error Recovery in LR phase – 2”.

1. The grammar S → aSa | bS | c is?
a) LL(1) but not LR(1)
b) LR(1) but not LR(1)
c) Both LL(1) but not LR(1) & LR(1) but not LR(1)
d) None of the mentioned
View Answer

Answer: c
Explanation:
First(aSa) = a
First(bS) = b
First(c) = c
LR parsers are more powerful than LL (1) parsers and LR (1).

2. Recursive descent parsing is an example of ____________
a) Top down parsing
b) Bottom up parsing
c) Predictive parsing
d) None of the mentioned
View Answer

Answer: a
Explanation: Top down is the answer.

3. LR stands for ___________
a) Left to right
b) Left to right reduction
c) Right to left
d) Right most derivation and Left to right and a in reverse
View Answer

Answer: d
Explanation: Right most derivation and left to right and in reverse is used for LR.

4. Which is the most powerful parser?
a) SLR
b) LALR
c) Canonical LR
d) Operator-precedence
View Answer

Answer: c
Explanation: Canonical tops all other parsers.

 

E. Mixed

1.

Compiler translates the source code to

 

  • A. Executable code
  • B. Machine code
  • C. Binary code
  • D. Both B and C

 

2.

Which of the following groups is/are token together into semantic structures?

 

  • A. Syntax analyzer
  • B. Intermediate code generation
  • C. Lexical analyzer
  • D. Semantic analyzer

 

3.

Compiler should report the presence of __________ in the source program, in translation process.

 

  • A. Classes
  • B. Objects
  • C. Errors
  • D. Text

 

4.

What is the output of lexical analyzer?

 

  • A. A parse tree
  • B. A list of tokens
  • C. Intermediate code
  • D. Machine code

5.

How many parts of compiler are there?

 

  • A. 1
  • B. 2
  • C. 4
  • D. 8

 

6.

Grammar of the programming is checked at _______ phase of compiler.

 

  • A. Semantic analysis
  • B. Syntax analysis
  • C. Code optimization
  • D. Code generation

 

 

7.

_________ is a process of finding a parse tree for a string of tokens.

 

  • A. Parsing
  • B. Analysing
  • C. Recognizing
  • D. Tokenizing

 

8.

What is the action of parsing the source program into proper syntactic classes?

 

  • A. Lexical analysis
  • B. Syntax analysis
  • C. General syntax analysis
  • D. Interpretation analysis

9.

Compiler can check ________ error.

 

  • A. Logical
  • B. Syntax
  • C. Content
  • D. Both A and B

 

10.

A grammar that produces more than one parse tree for some sentence is called as

 

  • A. Ambiguous
  • B. Unambiguous
  • C. Regular
  • D. All of these

 

 

11.

Lexical analysis is about breaking a sequence of characters into

 

  • A. Groups
  • B. Packets
  • C. Lines
  • D. Tokens

 

12.

_______ is the most general phase structured grammar.

 

  • A. Context sensitive
  • B. Regular
  • C. Context free
  • D. All of these
  •  

13.

________ is considered as a sequence of characters in a token.

 

  • A. Texeme
  • B. Pattern
  • C. Lexeme
  • D. Mexeme

 

14.

What is the name of the process that determining whether a string of tokens can be generated by a grammar?

 

  • A. Analysing
  • B. Recognizing
  • C. Translating
  • D. Parsing

 

 

15.

A _________ is a software utility that translates code written in higher language into a low level language.

 

  • A. Converter
  • B. Compiler
  • C. Text editor
  • D. Code optimizer

 

An intermediate code form is

Postfix notation
Syntax trees
Three address code
All of these
      _____________________________________________________________________________________
In operator precedence parsing , precedence relations are defoned

For all pair of non terminals
For all pair of terminals
To delimit the handle
Only for a certain pair of terminals
      _____________________________________________________________________________________
Relocating bits used by relocating loader are specified by

Relocating loader itself
Linker
Assembler
Macro processor
      _____________________________________________________________________________________
A compiler for a high level language that runs on one machine and produce code for different machine is called

Optimizing compiler
One pass compiler
Cross compiler
Multipass compiler
      _____________________________________________________________________________________
Synthesized attribute can be easily simulated by a

LL grammar
Ambiguous grammar
LR grammar
None of the above
      _____________________________________________________________________________________
The output of a lexical analyzer is

Machine code
Intermediate code
A stream of tokens
A parse tree
      _____________________________________________________________________________________
Running time of a program depends on

The way the registers and addressing modes are used
The order in which computations are performed
The usage of machine idioms
All of these
      _____________________________________________________________________________________
Reduction in strength means

Replacing run time computation by compile time computation
Removing loop invariant computation
Removing common sub expression
Replacing a costly operation by a relatively cheaper one
      _____________________________________________________________________________________
_________or scanning is the process where the stream of characters making up the source program is read from left to right and grouped into tokens.

Lexical analysis
Diversion
Modeling
None of the above
      _____________________________________________________________________________________
Task of the lexical analysis

To parse the source program into the basic elements or tokens of the language
To build a literal table and an identifier table
To build a uniform symbol table
All of these
      _____________________________________________________________________________________
Shift reduce parsers are

Top down parser
Bottom up parser
May be top down or bottom up parser
None of the above
      _____________________________________________________________________________________
Any description error can be repaired by

Insertion alone
Deletion alone
Insertion and deletion alone
Replacement alone
      _____________________________________________________________________________________
The linker

is similar to interpreter
uses source code as its input
is required to create a load module
none of the above
      _____________________________________________________________________________________
A grammar that produces more than one parse tree for some sentence is called

Ambiguous
Unambiguous
Regular
None of these
      _____________________________________________________________________________________
In an absolute loading scheme which loader function is accomplished by assembler ?

re-allocation
allocation
linking
loading
      _____________________________________________________________________________________
Intermediate code generation phase gets input from

Lexical analyzer
Syntax analyzer
Semantic analyzer
Error handling
      _____________________________________________________________________________________
We can optimize code by

Dead code elimination
Common subprograms
Copy intermediate loop
Loop declaration
      _____________________________________________________________________________________
Code can be optimized at

Source from user
Target code
Intermediate code
All of the above
      _____________________________________________________________________________________
Whether a given pattern constitutes a token or not depends on the

Source language
Target language
Compiler
All of these
      _____________________________________________________________________________________
YACC builds up

SLR parsing table
Canonical LR parsing table
LALR parsing table
None of the above
      _____________________________________________________________________________________
Type checking is normally done during

Lexical analysis
Syntax analysis
Syntax directed translation
Code optimization
      _____________________________________________________________________________________
A top down parser generates

Right most derivation
Right most derivation in reverse
Left most derivation
Left most derivation in reverse
      _____________________________________________________________________________________
Which of the following does not interrupt a running process?

A device
Timer
Scheduler
Power failure
      _____________________________________________________________________________________
In an absolute loading scheme, which loader function is accomplished by a loader ?

Re-allocation
Allocation
Linking
Loading
      _____________________________________________________________________________________
The lexical analyzer takes_________as input and produces a stream of_______as output.

Source program,tokens
Token,source program
Either A and B
None of the above
      _____________________________________________________________________________________
Which of the following can be accessed by transfer vector approach of linking?

External data segments
External subroutines
Data located in other procedure
All of these
      _____________________________________________________________________________________
___________is a graph representation of a derivation.

The parse tree
The oct tree
The binary tree
None of the above
      _____________________________________________________________________________________
The optimization which avoids test at every iteration is

Loop unrolling
Loop jamming
Constant folding
None of these
      _____________________________________________________________________________________
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
      _____________________________________________________________________________________
A parser with the valid prefix property is advantageous because it

Detects error as soon as possible
Detects errors as and when they occur
Limits the amount of erroneous output passed to the text phase
All of these
      _____________________________________________________________________________________
Which of the following parser is most powerful?

Operator precedence
Canonical LR
LALR
SLR
      _____________________________________________________________________________________
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
      _____________________________________________________________________________________
 Macro-processors are ______

Hardware
Compiler
Registers
None of the above
      _____________________________________________________________________________________
In which way(s) a macroprocessor for assembly language can be implemented ?

Independent two-pass processor
Independent one-pass processor
Expand macrocalls and substitute arguments
All of the above
      _____________________________________________________________________________________
‘Macro’ in an assembly level program is _______.

sub program
a complete program
a hardware portion
relative coding
      _____________________________________________________________________________________
The optimization technique which is typically applied on loops is

Removal of invariant computation
Peephole optimization
Constant folding
All of these
      _____________________________________________________________________________________
Concept which can be used to identify loops is

Dominators
Reducible graphs
Depth first ordering
All of these
      _____________________________________________________________________________________
Local and loop optimization in turn provide motivation for

Data flow analysis
Constant folding
Pee hole optimization
DFA and constant folding
      _____________________________________________________________________________________
LR stands for

Left to right
Left to right reduction
Right to left
Left to right and right most derivation in reverse
      _____________________________________________________________________________________
Grammar of the programming is checked at ________ phase of compiler.

semantic analysis
code generation
syntax analysis
code optimization
      _____________________________________________________________________________________
Which of the following is not an intermediate code form?

Postfix notation
Syntax trees
Three address codes
Quadruples
      _____________________________________________________________________________________
A compiler that runs on one machine and produces code for a different machine is called

Cross compilation
One pass compilation
Two pass compilation
None of the above
      _____________________________________________________________________________________
The graph that shows basic blocks and their successor relationship is called

DAG
Flow chart
Control graph
Hamiltonian graph
      _____________________________________________________________________________________
A grammar is meaningless

If terminal set and non terminal set are not disjoint
If left hand side of a production is a single terminal
If left hand side of a production has no non terminal
All of these
      _____________________________________________________________________________________
Which of the following is used for grouping of characters into tokens?

Parser
Code optimization
Code generator
Lexical analyzer
      _____________________________________________________________________________________
An optimizer compiler

Is optimized to occupy less space
Is optimized to take less time for execution
Optimizes the code
None of these
      _____________________________________________________________________________________
Pee hole optimization

Loop optimization
Local optimization
Constant folding
Data flow analysis
      _____________________________________________________________________________________
The action of parsing the source program into proper syntactic classes is called

Syntax analysis
Lexical analysis
Interpretation analysis
General syntax analysis                                                                   


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
      _____________________________________________________________________________________
YACC builds up

SLR parsing table
Canonical LR parsing table
LALR parsing table
None of the above
      _____________________________________________________________________________________
In an absolute loading scheme which loader function is accomplished by assembler ?

re-allocation
allocation
linking
loading
      _____________________________________________________________________________________
A parser with the valid prefix property is advantageous because it

Detects error as soon as possible
Detects errors as and when they occur
Limits the amount of erroneous output passed to the text phase
All of these
      _____________________________________________________________________________________
The action of parsing the source program into proper syntactic classes is called

Syntax analysis
Lexical analysis
Interpretation analysis
General syntax analysis
      _____________________________________________________________________________________
Relocating bits used by relocating loader are specified by

Relocating loader itself
Linker
Assembler
Macro processor
      _____________________________________________________________________________________


A top down parser generates

Right most derivation
Right most derivation in reverse
Left most derivation
Left most derivation in reverse
      _____________________________________________________________________________________
Running time of a program depends on

The way the registers and addressing modes are used
The order in which computations are performed
The usage of machine idioms
All of these
      _____________________________________________________________________________________

A bottom up parser generates

Right most derivation
Right most derivation in reverse
Left most derivation
Left most derivation in reverse
      _____________________________________________________________________________________



A grammar that produces more than one parse tree for some sentence is called

Ambiguous
Unambiguous
Regular
None of these
      _____________________________________________________________________________________


An optimizer compiler

Is optimized to occupy less space
Is optimized to take less time for execution
Optimizes the code
None of these
      _____________________________________________________________________________________


The linker

is similar to interpreter
uses source code as its input
is required to create a load module
none of the above
      _____________________________________________________________________________________

Pee hole optimization

Loop optimization
Local optimization
Constant folding
Data flow analysis
      _____________________________________________________________________________________
The optimization which avoids test at every iteration is

Loop unrolling
Loop jamming
Constant folding
None of these
      _____________________________________________________________________________________


Advantage of panic mode of error recovery is that

It is simple ti implement
It never gets into an infinite loop
Both A and B
None of these
      _____________________________________________________________________________________
Which of the following is not an intermediate code form?

Postfix notation
Syntax trees
Three address codes
Quadruples
      _____________________________________________________________________________________

Shift reduce parsers are

Top down parser
Bottom up parser
May be top down or bottom up parser
None of the above
      _____________________________________________________________________________________
A compiler that runs on one machine and produces code for a different machine is called

Cross compilation
One pass compilation
Two pass compilation
None of the above
      _____________________________________________________________________________________

Input to code generator

Source code
Intermediate code
Target code
All of the above
      _____________________________________________________________________________________


The output of lexical analyzer is

A set of regular expressions
Syntax tree
Set of tokens
Strings of character
      _____________________________________________________________________________________
Local and loop optimization in turn provide motivation for

Data flow analysis
Constant folding
Pee hole optimization
DFA and constant folding
      _____________________________________________________________________________________


LR stands for

Left to right
Left to right reduction
Right to left
Left to right and right most derivation in reverse
      _____________________________________________________________________________________


Which of the following is the most powerful parser?

SLR
LALR
Canonical LR
Operator precedence
      _____________________________________________________________________________________
Which of the following is used for grouping of characters into tokens (in a computer)

A parser
Code optimizer
Code generator
Scanner
      _____________________________________________________________________________________
_________or scanning is the process where the stream of characters making up the source program is read from left to right and grouped into tokens.

Lexical analysis
Diversion
Modeling
None of the above
      _____________________________________________________________________________________

Which of the following can be accessed by transfer vector approach of linking?

External data segments
External subroutines
Data located in other procedure
All of these
      _____________________________________________________________________________________
 Macro-processors are ______

Hardware
Compiler
Registers
None of the above
      _____________________________________________________________________________________









Comments

Popular Posts

Vivo Z1 Pro will be the first smartphone that comes with 712 chipset, Learn the specialty of this processor.