CC MCQs

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Compiler Construction MCQs with Answer & Explanation

1. The output of lexical analyzer is


a) A set of RE
b) Syntax Tree
c) Set of Tokens
d) String Character

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

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


a) Linear list
b) Search tree
c) Hash Table
d) Self Organization

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

3. For operator precedence parsing, which one is true?


a) For all pair of non-terminal
b) For all pair of non-terminals
c) To delimit the handle
d) None of the mentioned

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. Object program is a
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
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

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

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

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

Answer: a
Explanation: As per the definition of Lexical Analyzer 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

Answer: b
Explanation: Parsing or syntactic analysis is the process of analyzing 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

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 is designed so that they are
a) Re-enterable
b) Non-Usable
c) Serially usable
d) None of the mentioned

Answer: a
Explanation: For the convince of the user compilers are made re-enterable.
6. Which of the following is not 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

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

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

1. Which phase of compiler is Syntax Analysis


a) First
b) Second
c) Third
d) None of the mentioned

Answer: b
Explanation: It is Second Phase of Compiler after Lexical Analyzer.
2. What is Syntax Analyzer also known as
a) Hierarchical Analysis
b) Hierarchical Parsing
c) None of the mentioned
d) Hierarchical Analysis & Parsing

Answer: d
Explanation: It is also called as Hierarchical Analysis or Parsing.
3. Syntax Analyzer takes Groups Tokens of source Program into Grammatical Production
a) True
b) False

Answer: a
Explanation: It Groups Tokens of source Program into Grammatical Production.
4. From where it takes its input from?
a) Lexical analyzer
b) Syntactic Analyzer
c) Semantic Analyzer
d) None of the mentioned

Answer: a
Explanation: A syntax analyzer or parser takes the input from a lexical analyzer in the form of token streams.
5. Parsers are expected to parse the whole code
a) True
b) False

Answer: a
Explanation: Parsers are expected to parse the whole code even if some errors exist in the program.
6. A grammar for a programming language is a formal description of
a) Syntax
b) Semantics
c) Structure
d) Library

Answer: c
Explanation: The grammar clearly indicates that which type of a structure does a program has.
7. Which of these is not true about Symbol Table?
a) All the labels of the instructions are symbols
b) Table has entry for symbol name address value
c) Perform the processing of the assembler directives
d) Created during pass 1

Answer: c
Explanation: The Symbol table does not ever perform the processing of the assembler derivative.
1. Select a Machine Independent phase of the compiler
a) Syntax Analysis
b) Intermediate Code generation
c) Lexical Analysis
d) All of the mentioned

Answer: d
Explanation: All of them work independent of a machine.
2. A system program that combines the separately compiled modules of a program into a form suitable for
execution?
a) Assembler
b) Compiler
c) Linking Loader
d) Interpreter

Answer: c
Explanation: A loader which combines the functions of a relocating loader with the ability to combine several
program segments that have been independently compiled.
3. Which of the following system software resides in the main memory always
a) Text Editor
b) Assembler
c) Linker
d) Loader

Answer: d
Explanation: Loader is used to loading programs.
4. Output file of Lex is _____ the input file is My file?
a) Myfile.e
b) Myfile.yy.c
c) Myfile.lex
d) Myfile.obj

Answer: b
Explanation: This Produce the file “myfile.yy.c” which we can then compile with g++.
5. Type checking is normally done during?
a) Lexical Analysis
b) Syntax Analysis
c) Syntax Directed Translation
d) Code generation
Answer: c
Explanation: It is the function of Syntax directed translation.
6. Suppose One of the Operand is String and other is Integer then it does not throw error as it only checks
whether there are two operands associated with ‘+’ or not.
a) True
b) False

Answer: a
Explanation: Syntax analyzer does not check the type of the operand.
7. In Short Syntax Analysis Generates Parse Tree
a) True
b) False

Answer: a
Explanation: Short Syntax Analysis generates a parse tree.

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

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

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)

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

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

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 *

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

Answer : c
Explanation:
Compiler transforms source code into the machine language which is in binary .
Kinds of object codes:
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

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

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

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

Answer: d
Explanation: the next step in LR parsing shall have 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

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

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

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

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 } .
advertisement

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

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

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

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

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

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

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

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

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

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

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

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

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

1. Which of the following is the fastest logic ?


a) TTL
b) ECL
c) CMOS
d) LSI

Answer: b
Explanation: In electronics, emitter-coupled logic (ECL) is a high-speed integrated circuit.
2. A bottom up parser generates
a) Right most derivation
b) Rightmost derivation in reverse
c) Leftmost derivation
d) Leftmost derivation in reverse

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

Answer: a
Explanation: ambiguous grammar has more than one parse tree.
4. An optimizer Compiler
a) Is optimized to occupy less space
b) Both of the mentioned
c) Optimize the code
d) None of the mentioned

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) I s required to create a load module
d) None of the mentioned

6. A latch is constructed using two cross coupled


a) AND OR gates
b) AND gates
c) NAND and NOR gates
d) NAND gates
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

Answer: c
Explanation: More loops are added.
advertisement

8. The optimization which avoids test at every iteration is


a) Loop unrolling
b) Loop jamming
c) Constant folding
d) None of the mentioned

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

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

Answer: b
Explanation: Also known as shift reduce parser.
1. Compiler can diagnose
a) Grammatical errors only
b) Logical errors only
c) Grammatical and logical errors
d) None of the mentioned

Answer: a
Explanation: Only syntactical errors can be detected by the compiler.
2. A simple two-pass assembler does which of the following in the first pass.
a) It allocates space for the literals
b) Calculates total length of the program
c) Symbol table is built for the symbols and their value
d) All of the mentioned

Answer: d
Explanation: A two-pass assembler. Each pass scans the program, the first pass generates the symbol table and
the second pass generates the machine code…
3. A system program that set-up an executable program in main memory ready for execution is
a) Assembler
b) Linker
c) Loader
d) Text editor

Answer: c
Explanation: A loader is the part of an operating system that is responsible for loading programs and libraries.
It is important that with the starting of a program, as it places programs into memory and executes it.
4. A compiler is a program that
a) Program is put into memory and executes it.
b) Translation of assembly language into machine language.
c) Acceptance of a program written in a high level language and produces an object program.
d) None of the mentioned

Answer: c
Explanation: A compiler is a computer program (or set of programs) that transforms source code written in a
programming language (the source language) into another computer language (the target language, often
having a binary form known as object code).
5. A programmer by mistake writes multiplication instead of division, such error can be detected by a/an
a) Compiler
b) Interpreter
c) Compiler or interpreter test
d) None of the mentioned

Answer: d
Explanation: No Logical errors can be detected
6. The computer language generally translated to pseudocode is
a) Assembly
b) Machine
c) Pascal
d) FORTRAN

Answer: a
Explanation: An assembly language (or assembler 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.
7. A system program that combines separately compiled modules of a program into a form suitable for
execution is
a) Assembler
b) Linking Loader
c) Cross Compiler
d) None of the mentioned

Answer: b
Explanation: A loader which combines 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.
advertisement

8. In which way a macro processor for assembly language can be implemented?


a) Independent two-pass processor
b) Independent one-pass processor
c) Processor put into pass 1 of a standard two pass assembler
d) All of the mentioned

Answer: d
Explanation: A general-purpose macro processor or general purpose preprocessor is a macro …designed for
string manipulation, macro definition
9. Resolution of externally defined symbols is performed by
a) Linker
b) Loader
c) Compiler
d) Interpreter

Answer: a
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.
10. A shift reduce parser carries out the actions specified within braces immediately after reducing with the
corresponding rule of grammar S—-> xxW ( PRINT “1”) S—-> y { print ” 2 ” } S—-> Sz { print ” 3 ” ) What
is the translation of xxxxyzz using the syntax directed translation scheme described by the above rules ?
a) 23131
b) 11233
c) 11231
d) 33211

Answer: a
Explanation: Initially 2 is printed then 3 then 1 3 1

This set of Compilers online quiz focuses on “Data Structure for Representing Parsing Table – 2”.

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


a) Linear List
b) Search Tree
c) Hash table
d) Self Organization

Answer: c
Explanation: A hash table (hash map) is a data structure used to implement an associative array. A hash table
uses a hash function to compute an index into an array, from which the correct value can be found.
2. In operator precedence parsing whose precedence relations are defined
a) For all pair of non-terminals
b) For all pair of terminals
c) To delimit the handle
d) None of the mentioned

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 no terminals.
3. LR parsers are attractive because
a) It can be constructed to recognize CFG corresponding to almost all programming constructs
b) It does not backtrack
c) Both of the mentioned
d) None of the mentioned

Answer: c
Explanation: These above mentioned are the reasons why LR parser is considered to be attractive
4. The most powerful parser is
a) SLR
b) LALR
c) Canonical LR
d) Operator Precedence

Answer: c
Explanation: The most powerful parser is Canonical LR
5. Yacc Builds up
a) SLR parsing Table
b) Canonical LR parsing Table
c) LALR parsing Table
d) None of the mentioned

Answer: c
Explanation: Yacc provides a general tool for describing the input to a computer program.
6. Object program is a
a) Program written in machine language
b) Translated into machine language
c) Translation of high-level language into machine language
d) None of the mentioned

Answer: c
Explanation: A computer program when from the equivalent source program into machine language by the
compiler or assembler.
7. ( Z,* ) be a structure, and * is defined by n * m =maximum ( n , m ) Which of the following statements is
true for ( Z, * ) ?
a) ( Z,* ) is a monoid
b) ( Z,* ) is an algebraic group
c) ( Z,* ) is a group
d) None of the mentioned

Answer: d
Explanation: It is neither a monoid nor a simple group nor algebraic group
advertisement

8. The address code involves


a) Exactly 3 address
b) At most Three address
c) No unary operators
d) None of the mentioned

Answer: d
Explanation: In computer science, three-address is an intermediate code used by optimizing compilers to aid in
the implementation of code-improving transformations.
9. An intermediate code form is
a) Postfix Notation
b) Syntax Trees
c) Three address code
d) All of the mentioned

Answer: d
Explanation: Intermediate code generator takes an input from its predecessor phase, semantic analyzer, in the
form of an annotated syntax tree.
10. Relocating bits used by relocating loader are specified by
a) Relocating loader itself
b) Linker
c) Assembler
d) Macro Processor

Answer: b
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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy