PCD Final
PCD Final
Answer: c Answer: d
Explanation: S1 can be written as (00) ^n where n >= 1. Explanation: Strings of odd number of zeroes can be
And S2 can be written as (00) ^ (m+n) where m >=2 and generated by the regular expression (00) *0.Pumping
n >= 1. S2 can be further reduced to (00) ^x where x >= lemma can be used to prove the non-regularity of the
3. SO we can write regular grammars for both other options.
G1 -> G100/00 (For S1) 9. If ∑ = {a, b, c, d, e, f} then number of strings in ∑ of
G2 -> G200/000000 (For S2). length 4 such that no symbol is used more than once in a
1
string is b) #
a) 35 c) *
b) 360 d) &
c) 49
d) 720 Answer: c
Explanation: Zero or Specific Expression matching can
Answer: b be done only by a single character that is*.
Explanation: Here string length is 4 so we create string of 4. All…….. are automatically treated as regular
length 4 by 6 values firstly we arrange any value by 6 expressions.
methods. Then Remaining numbers are 5 so we can a) Programmatic description
arrange them by 5 methods then remaining numbers are 4 b) Window
so we arrange them by 4 methods and then 3.Thus c) Win Object
6*5*4*3=360. d) Collection
10. Which one of the following statement is FALSE?
a) Context-free languages are closed under union Answer: a
b) Context-free languages are closed under concatenation Explanation: It is seen that programmatic description are
c) Context-free languages are closed under intersection treated as regular expression.
d) Context-free languages are closed under Kleene 5. Regular Expressions can be used with XML
closure checkpoints.
a) True
Answer: c b) False
Explanation: CFL is closed under Kleene closure,
concatenation, and Union Answer: a
Explanation: XML checkpoints employ RE.
. 6. The production Grammar is {S->aSbb,S->abb} is
Compilers – Finite Automata and Regular a) Type-3 grammar
Expressions-2 b) Type-2 grammar
This set of Compilers Interview focuses on “Finite c) Type-1 grammar
Automata and Regular Expressions – 2”. d) Type-0 grammar
1. Which of the following strings is not generated by the
following grammar? Answer: b
S → SaSbS|ε Explanation: As per the definition of type-2 grammar.
a) aabb 7. Regular expression (x/y)(x/y) denotes the set
b) abab a) {xy,xy}
c) aababb b) {xx,xy,yx,yy}
d) aaabbb c) {x,y}
d) {x,y,xy}
Answer: d
Explanation: Answer: b
S->aSbS putting S-> € and then S->SaSbS Explanation: From first part if we take x then from the
S->aSaSaSbSbSbS putting S->SaSbS latter part x then it forms xx
S->aaabbb putting S->€. From first part if we take x then from the latter part y
2. Regular expressions can be used only for values of then it forms xy
type string and number. From first part if we take y then from the latter part x
a) True then it forms yx
b) False From first part if we take y then from the latter part y
then it forms yy.
Answer: b 8. Regular expression x/y denotes the set
Explanation: RE is used for all types of string and a) {x,y}
numbers. b) {xy}
3. What is the Regular Expression Matching Zero or c) {x}
More Specific Characters d) {y}
a) x
2
Answer: a Answer: a
Explanation: Because either x or y can be selected. Explanation: Bootstrapping to a new platform. When a
9. The regular expressions denote zero or more instances software is developed for a new platform, a cross
of an x or y is compiler is used to compile necessary tools such as the
a) (x+y) OS and a native compiler.
b) (x+y)* 5. Is GCC a cross Complier
c) (x* + y) a) Yes
d) (xy)* b) No
Answer: b Answer: a
Explanation: For instances of x or y the exp is x+y and Explanation:
both can zero or more times than (x+y)*. GCC, a free software collection of compilers, also can be
used as cross compile. It supports many languages and
Cross Compiler-1 - platforms.
“Cross Compiler”. 6. The __________ is a technique for building cross
1. A system program that combines separately compiled compilers for other machines
modules of a program into a form suitable for execution a) Brazilian Cross
is b) Canadian Cross
a) Assembler c) Mexican Cross
b) Linking loader d) X-cross
c) Cross compiler
d) None of the mentioned Answer: b
Explanation: The Canadian Cross is a technique for
Answer: b building cross compilers for other machines. Given three
Explanation: The definition of cross compiler. machines X, Y, and Z, one uses machine X (e.g. running
2. A compiler for a high-level language that runs on one Windows XP on an IA-32 processor) to build a cross
machine and produces code for a different machine is compiler that runs on machine Y (e.g. running Mac OS X
called on an x86-64 processor) to create executables for
a) Optimizing compiler machine Z.
b) One pass compiler 7. __________ was developed from the beginning as a
c) Cross compiler cross compiler
d) Multipass compiler a) Free Pascal
b) GCC
Answer: c c) Pascal
Explanation: So done by the definition. d) None of the mentioned
3. Cross-compiler is a compiler
a) Which is written in a different language from the Answer: a
source language? Explanation: Free Pascal was developed from the
b) That generates object code for the machine it’s beginning as a cross compiler. The compiler executable
running on. (ppcXXX where XXX is target architecture) is capable of
c) Which is written in the same language as the source producing executables for all OS of the same
language? architecture.
d) That runs on one machine but produces object code for
another machine .
3
d) None of the mentioned =0
So, Corresponding signed value of unsigned 10u is +10.
Answer: b 4. What will be output of the following c code?
Explanation: This is how the GCC is designed to take #include
names of executable files. int main(){
2. What will be output of the following code? const int *p;
#include int a=10;
int main(){ p=&a;
printf(“%d\t”,sizeof(6.5)); printf(“%d”,*p);
printf(“%d\t”,sizeof(90000)); return 0;
printf(“%d”,sizeof(‘A’)); }
return 0; a) 0
} b) 10
a) 8 4 2 c) Garbage Value
b) 8 4 2 d) Any Memory address
c) 8 4 4
d) 8 4 3 Answer: b
Explanation: In the following declaration
Answer: c const int *p;
Explanation: GCC compilers (32 bit compilers) size of: p can keep address of constant integer.
double is 8 byte 5. What will be output of the following c code?
long int is 8 byte #include
Character constant is 2 byte. int main(){
3. What will be output of the following c code? int a= sizeof(signed) +sizeof(unsigned);
( according to GCC compiler) int b=sizeof(const)+sizeof(volatile);
#include printf(“%d”,a+++b);
int main(){ return 0;
signed x; }
unsigned y; a) 10
x = 10 +- 10u + 10u +- 10; b) 9
y = x; c) 8
if(x==y) d) Error
printf(“%d %d”,x,y);
else if(x!=y) Answer: c
printf(“%u %u”,x,y); Explanation: Default data type of signed, unsigned, const
return 0; and volatile is intSo, a = 4 and b =4
} Now, a+++b
a) 0 0 = a++ + b
b) 65536 -10 = 4 + 4 //due to post increment operator.
c) 0 65536 =8
d) Compilation error But in Linux gcc compiler size of int is 4 byte so your out
will be 16.
Answer: a 6. Which of the following is integral data type?
Explanation: Consider on the expression: a) void
x = 10 +- 10u + 10u +- 10; b) char
10: It is signed integer constant. c) float
10u: It is unsigned integer constant. d) double
X: It is signed integer variable.
As we know operators enjoy higher precedence than Answer: b
binary operators. So Expanation:
x = 10 + (-10u) + 10u + (-10); In c char is integral data type. It stores the ASCII value .
= 10 + -10 + 10 + (-10); 7. What will be output of the following c code?
#include
4
int main(){ 2. The symbol table implementation is based on the
volatile int a=11; property of locality of reference is
printf(“%d”,a); a) Linear list
return 0; b) Search tree
} c) Hash Table
a) 11 d) Self Organisation
b) Garbage
c) -2 Answer: c
d) Cannot Predict Explanation: Hash table is used as a reference for symbol
table because it is efficient.
Answer: d 3. For operator precedence parsing, which one is true?
Explanation: Value of volatile variable can’t be predicted a) For all pair of non-terminal
because its value can be changed by any microprocessor b) For all pair of non-terminals
interrupt. c) To delimit the handle
8. What will be output of the following c code? d) None of the mentioned
#include
const enum Alpha{ Answer: a
X, Explanation: There are two important properties for these
Y=5, operator precedence parsers is that it does not appear on
Z the right side of any production and no production has
}p=10; two adjacent non-terminals. Implying that no production
int main(){ right side is empty or has two adjacent non-terminals. So
enum Alpha a,b; accordingly to property option (A) is correct.
a= X; 4. Object program is a
b= Z; a) Program written in machine language
printf(“%d”,a+b-p); b) Program to be translated into machine language
return 0; c) Translation of high-level language into machine
} language
a) -4 d) None of the mentioned
b) -5
c) 10 Answer: c
d) 11 Explanation: Since the input is the source language and
the output that we get after the analysis is the machine
Answer: a language.
Explanation: Default value X is zero and 5. Which concept of FSA is used in the compiler?
Z=Y+1=5+1=6 a) Lexical analysis
So, a + b – p b) Parser
=0 + 6 -10 = -4. c) Code generation
d) Code optimization
.
Answer: a
Lexical Analysis-1 - Explanation: Because the lexer performs its analysis by
“Lexical Analysis”. going from one stage to another.
1. The output of lexical analyzer is 6. Which concept of grammar is used in the compiler
a) A set of RE a) Lexical analysis
b) Syntax Tree b) Parser
c) Set of Tokens c) Code generation
d) String Character d) Code optimization
Answer: c Answer: b
Explanation: A lexical analyzer coverts character Explanation: As the lexical analysis of a grammar takes
sequences to set of tokens. place in phases hence it is synonymous to parser.
5
7. Which of the following are Lexemes? 5. System program such a compiler are designed so that
a) Identifiers they are
b) Constants a) Re-enterable
c) Keywords b) Non-Usable
d) All of the mentioned c) Serially usable
d) None of the mentioned
Answer: d
Explanation: Different Lexical Classes or Tokens or Answer: a
Lexemes Identifiers, Constants, Keywords, Operators. 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
Lexical Analysis-2 - machine code
“Lexical Analysis”. b) To remove syntax errors
1. What constitutes the stages of the compilation process? c) Slow for debugging
a) Feasibility study, system, design, and testing d) Execution time is more
b) Implementation and. documentation
c) Lexical analysis, syntax. Analysis and code generation Answer: d
d) None of the mentioned Explanation: The objective of the compiler is clearly not
to increase the execution time of the program.
Answer: c 7. A system program that brings together separately
Explanation: As defined in the compilation process. compiled modules of a program into a form language that
2. The lexical analyzer takes_________as input and is suitable for execution
produces a stream of_______as output. a) Assembler
a) Source program, tokens b) Linking loader
b) Token, source program c) Cross compiler
c) Either of the two d) None of the mentioned
d) None of the mentioned
Answer: b
Answer: a Explanation: A loader which brings together the
Explanation: As per the definition of Lexical Analyser functions of a relocating loader with the ability to
which states that lexical analysis is the process of combine a number of program segments that have been
converting a sequence of characters into tokens. independently compiled into an executable program.
3. Parsing is also known as 8. A programmer, by mistakes writes a program to
a) Lexical Analysis multiply two numbers instead of dividing them, how can
b) Syntax Analysis this error be detected
c) Semantic Analysis a) Compiler
d) Code Generation b) Interpreter
c) Compiler or interpreter
Answer: b d) None of the mentioned
Explanation: Parsing or syntactic analysis is the process
of analysing a string of symbols and conforming to the Answer: d
rules of grammar. Explanation: This is a logical error can’t be detected by
4. A compiler program written in a high level language is any compiler or interpreter.
called
a) Source Program .
b) Object Program Compilers – Regular Expression-1
c) Machine Language Program “Regular Expression”.
d) None of the mentioned 1. A regular expression enables a quick test to determine
objects and text strings with undependable values.
Answer: a a) True
Explanation: The input that we give in high level b) False
language is also known as the source language.
6
Answer: a Option C it gives either 1 or 0.
Explanation: Because it checks for all the values and Hence Option D is the answer.
determines whether the output string matches with the 7. The RE gives none or many instances of an x or y is
given string. a) (x+y)
2. RE can be used only for values of type string and b) (x+y)*
number. c) (x* + y)
a) True d) (xy)*
b) False
Answer: b
Answer: b Explanation: Whether x or y is denoted by x+y and for
Explanation: No not for all values the string and numbers zero or more instances it is denoted but (x+y)*.
can we use the RE.
3. You can use RE, if you expect the value of a property Regular Expression-2 -
to change in an unpredictable way each time its run. “Regular Expression”.
a) True 1. The RE in which any number of 0′s is followed by any
b) False number of 1′s followed by any number of 2′s is
a) (0+1+2)*
Answer: b b) 0*1*2*
Explanation: For every cycle the values does not change c) 0* + 1 + 2
unpredictably because the type of grammar that it accepts d) (0+1)*2*
is defined.
4. All…….. Are automatically treated as regular Answer: b
expressions. Explanation: The order for the desired string is 012 and
a) Programmatic description foe any number of 0s we write 0* for any number of 1s
b) Window we denote it by 1* and similarly for 2*.Thus 0*1*2*.
c) Win Object 2. The regular expression have all strings of 0′s and 1′s
d) Collection with no two consecutive 0′s is :
a) (0+1)
Answer: a b) (0+1)*
Explanation: The programmatic description is genuinely c) (0+∈) (1+10)*
treated as regular expression. d) (0+1)* 011
5. If a ‘/’ is used before a character that has no special
meaning, ‘/’ is ignored. Answer: c
a) True Explanation: From the former bracket we choose 0 or
b) False epsilon. Then from the latter part 1 or 10 which can be
followed by 1 or 10.
Answer: a 3. The regular expression with all strings of 0′s and 1′s
Explanation: The backslash carries no significance and it with at least two consecutive 0′s is:
is ignored. a) 1 + (10)*
6. The regular expression denote a language comprising b) (0+1)*00(0+1)*
all possible strings of even length over the alphabet (0, 1) c) (0+1)*011
a) 1 + 0(1+0)* d) 0*1*2*
b) (0+1) (1+0)*
c) (1+0) Answer: b
d) (00+0111+10)* Explanation: The expression (0+1)*00(0+1)* is where
either it initially takes 0 or 1 or 00 followed by string of
Answer: d combination of 0 and 1.
Explanation: Option A does not consider even length 4. Which of the following is NOT the set of regular
criteria for the question. expression R = (ab + abb)* bbab
Option B it can so happen here that from the former a) ababbbbab
bracket it takes 0 or 1 and takes null from the latter then b) abbbab
it forms a string of odd length c) ababbabbbab
7
d) abababab Answer: b
Explanation: Here the non terminal that gives null will
Answer: a said to have a null production.
Explanation: ab followed by abb which is followed by
bbab. .
5. String generated by Compilers – Relations-1
S->aS/bA, “Relations”.
A->d/ccA 1. (a,b) what is a?
a) aabccd a) Domain
b) adabcca b) Range
c) abcca c) Both of the mentioned
d) abababd d) None of the mentioned
Answer: a Answer: a
Explanation: S->aS (substitute S->aS) Explanation: A is called the domain.
S->aaS (substitute S->bA) 2. (a,b) what is b?
S->aabA (substitute A->ccA) a) Domain
S->aabccA (substitute A->d) b) Range
S->aabccd. c) Both of the mentioned
6. Consider the production of the grammar S->AA A->aa d) None of the mentioned
A->bb Describe the language specified by the production
grammar. Answer: b
a) L = {aaaa,aabb,bbaa,bbbb} Explanation: B is called the Range.
b) L = {abab,abaa,aaab,baaa} 3. R is said to be reflexive if aRa is true for every a in A;
c) L = {aaab,baba,bbaa,bbbb} a) True
d) L = {aaaa,abab,bbaa,aaab} b) False
Answer: a Answer: a
Explanation: S->AA (substitute A->aa) Explanation: All the elements of A are related with
S->aaaa itself by relation R, hence it is a reflexive relation.
S->AA (substitute A->aa ) 4. If every aRb implies bRa then a relation R will be a
S->aaA (substitute A->bb) symmetric relation.
S->aabb a) True
S->AA (substitute A->bb the A->aa) b) False
S->bbaa
S->AA (substitute A->bb) Answer: a
S->bbbb. Explanation: a is related to b by R, and if b is also related
7. If R is regular language and Q is any language to a by the
(regular/ non regular), then Pref (Q in R) is ———. same relation R).
a) Non-regular 5. If every aRb and bRc implies aRc, then the relation is
b) Equal transitive
c) Infinite a) True
d) Regular b) False
Answer: d Answer: a
Explanation: So says the definition of Regular Grammar. Explanation: a is related to b by R, and b is related to c
8
d) None of the mentioned a) A=B
b) A=C
= {3,5,9}.
7. If a set A has n elements, then the total number of Answer: c
subsets of A is. Explanation: Transition Law.
a) N 6. The number of proper subsets of the set {1, 2, and 3}
b) 2^n is.
c) N^2 a) 8
d) 2n b) 6
c) 7
Answer: c d) 5
Explanation: Number of subsets of A = nC0 + nC1+ . . . .
. + nCn = 2n. Answer: b
Compilers – Relations-2 Explanation: Number of proper subsets of the set {1, 2,
a) A ⊂ B
1. If A ∩ B = B, then to
a) A
b) B
c) B ⊂ A
b) A = ø
c) A^C
d) B = ø d) B^C
Explanation: A ∩ B ⊆ A Hence A ∪ (A ∩ B) = A.
Answer: a
Explanation: Since A ∩ B = B , hence B ⊂ A .
Answer: c
a) (A × B) ∪ (A × C)
a) Invalid set equal to.
b) Infinite set
c) (A ∪ B) × (A ∪ C)
c) Finite set b) (A × B) ∩ (A × C)
d) None of the mentioned
d) None of the mentioned
Answer: c
a) (A – B) ∪ (A – C)
equal to
b) (A – B) ∪ C
Finite Automata-1 -
“Finite Automata”.
c) (A – B) ∩ (A – C) 1. A language L from a grammar G = { VN, Σ, P, S} is
d) (A – B) ∩ C a) Set of symbols over VN
b) Set of symbols over Σ
Answer: c c) Set of symbols over P
Explanation: it is De’ Morgan law. d) Set of symbols over S
4. A = {x: x ≠ x }represents
a) {0] b) {1} Answer: b
c) {} Explanation: The definition of the grammar is set of
d) {x} symbols over Σ.
2. The transitional function of a DFA is
Answer: c a) Q X Σ→Q
b) Q X Σ→2Q
5. If A, B, C be three sets such that A ∪ B = A ∪ C and
Explanation: That is a fact.
c) Q X Σ→2n
A ∩ B = A ∩ C, then
9
d) Q X Σ→Qn 7. A finite automata recognizes
a) Any Language
Answer: a b) Context Sensitive Language
Explanation: Q is the finite set and let be a finite set of c) Context Free Language
symbols so Q X Σ fives no of states. d) Regular Language
3. The transitional function of a NFA is
a) Q X Σ→Q Answer: d
b) Q X Σ→2Q Explanation: All regular languages are implemented by
c) Q X Σ→2n the finite automata.
d) Q X Σ→Qn
.
Answer: b
Explanation: Let Q be a finite set and let be a finite set of Finite Automata-2 -
symbols. Also let be a function from Q to 2Q.All the “Finite Automata”.
elements of Q a state, the transition function, q0 the 1. Which is true for Dead State?
initial state and A the set of accepting states. a) It cannot be reached anytime
Then a nondeterministic finite automaton is a 5-tuple < Q b) T no necessity of the state
, , q0 , , A > . c) If control enters no way to come out from the state
4) Maximum number of states of a DFA converted from d) If control enters FA deads
a NFA with nstates is
a) n Answer: c
b) n2 Explanation: It is a rejecting state for if the control enters
c) 2n it reaches the dead end and cannot reach an accepting
d) None of these state.
2. Which is true for Moore Machine?
Answer: c a) Output depends on present state
Explanation: Take the NFA with states {qo,q1}, alphabet b) Output depends on present input
Σ={a}, initial state q0, transitions δ(q0,a)=q0, δ(q0,a)=q1 c) Output depends on present state and present input
and final state q1. It generates the same language as the d) Output depends on present state and past input
DFA with the same set of states and alphabet, but
transitions δ(q0,a)=q1 and δ(q1,a)=q1. Answer: a
5. Basic limitations of finite state machine is Explanation: The definition states that moore machines
a) It cannot remember arbitrarily large amount of output is determined by the current state only.
information 3. Which is true for Mealy Machine?
b) In cannot remember state transitions a) Output depends on present state
c) In cannot remember grammar for a language b) Output depends on present input
d) It cannot remember language generated from a c) Output depends on present state and present input
grammar d) Output depends on present state and past input
Answer: b Answer: c
Explanation: Because it does to store its previous state of Explanation: The definition states that its output is
the transition. determined by current state and current input.
6. The string WWR is not recognized by any FSM 4. Which is true for in accessible state?
because a) It cannot be reached anytime
a) A FSM cannot remember arbitrarily large amount of b) T no necessity of the state
information c) If control enters no way to come out from the state
b) A FSM cannot fix the midpoint d) If control enters FA deads
c) A FSM cannot match W with WR
d) A FSM cannot remember first and last inputs Answer: a
Explanation: The very meaning of in accessible state is
Answer: b that it cannot be reached at any point of time.
Explanation: Palindromes cannot be recognised by FSM. 5. In Mealy Machine O/P is associated with
a) Present state
10
b) Next state
c) Input
d) None of the mentioned
Answer: b
Explanation: The definition states that its output is
a)
determined by current state and current input.
6. In Moore Machine O/P is associated with
a) Present state
b) Next state
c) Input
d) None of the mentioned
Answer: a
Explanation: The definition states that moore machines b)
output is determined by the current state only.
7. Which type string is accepted by the following finite
automata?
a) All string
b) Null string
c) No string
d) None of the mentioned
c)
Answer: b
Explanation: Null strings are not accepted by finite
automata.
8. Myhill-Nerode Theorem is used for __________
a) Minimization of DFA d)
b) Maximization of NFA
c) Conversion of NFA Answer: a
d) Conversion of DFA Explanation: We can verify that the string ababa is
a)
b)
11
• an initial state q0 ∈ Q
• a transition function Δ : Q × Σ → P(Q).
• a final state F ⊆ Q.
6. NFAs are ___ DFAs
a) Larger than
b) More expressive than
c) Less expressive than
c) d) Equally expressive as
Answer: a
Explanation: Because t more number of states for a
NDFA than for a DFA for a given expression.
d) 7. An NFA’s transition function returns
a) A Boolean value
Answer: b b) A state
Explanation: A ε transition takes no input and represents c) A set of states
a pure nondeterministic choice of being in the state or the d) An edge
target state without having done any processing.
3. NDFAs where introduced by ____________ Answer: c
a) Michael O Rabin & Dana Scott Explanation: A transition function Δ: Q × Σ → P
b) Dan Brown (Q).Where P (Q) denotes the power set of Q…
c) Sun micro system Labs Compilers – Non-Deterministic Finite Automata-2
d) SAP Labs This set of Compilers Interview for freshers focuses on
“Non – Deterministic Finite Automata – 2”.
Answer: a 1. Conversion of a DFA to an NFA
Explanation: NFAs were introduced Dana Scott and a) Is impossible
Michael O. Rabin who also showed their equivalence to b) Requires the subset construction
DFAs. c) Is Chancy
4. The regular languages are not closed under d) Is nondeterministic
a) Concatenation
b) Union Answer: b
c) Kleene star Explanation: In order to convert NDFA to DFA we work
d) Complement with sets of state where each state in the DFA
corresponds to a set of NFA states.
Answer: d 2. A regular language corresponds to
Explanation: RE are closed under a) An alphabet
• Union (cf. picture) b) Set of strings over an alphabet
• Intersection c) A DFA only
• Concatenation d) A DFA or an NFA
• Negation
• Kleene closure. Answer: b
5. The Tuples for NDFA Explanation: A regular grammar takes in all strings over
a) ∑,Q,q0,F,δ an alphabet.
b) Q,q0,F,δ 3. An NFA may be converted to a DFA using
c) Θ,Q,q0,F,δ a) Induction
d) F,Q,Δ,q0, δ b) A construction
c) Contradiction
Answer: a d) Compilation
Explanation: An NFA is represented formally by a 5-
tuple, (Q, Σ, Δ, q0, F), of Answer: b
• a set of states Q Explanation: subset construction is used to convert a
• a set of input symbols Σ NFA into DFA.
12
4. The subset construction shows that every NFA accepts Answer: d
a Explanation: As per its definition.
a) String 7. For every NFA a deterministic finite automaton (DFA)
b) Function can be found that accepts the same language.
c) Regular language a) True
d) Context-free language b) False
Answer: c Answer: a
Explanation: Like DFAs, NFAs only recognize regular Explanation: Therefore it is possible to convert an
languages. existing NFA into a DFA for the purpose of
5. Construct a NDFA for the following regular implementing a simpler machine. Which is executed by
expression using the powerset construction.
(a∪b)*aba(a∪b)* 8. Like DFAs, NFAs only recognize regular languages
a) True
b) False
Answer: a
a) Explanation: It is a known fact.
Answer: b
Explanation: Yes it can be done through power set
construction.
2. Find the wrong statement?
a) The language accepted by finite automata are the
languages denoted by regular expression
b) Every DFA has a regular expression denoting its
c)
language
c) For a regular expression r, there does not exists NDFA
with L® ant transit that accept
d) None of the mentioned
Answer: c
d) Explanation: The vice versa is true.
3. Regular expression a/b denotes the set
Answer: a a) {a}
Explanation: The NDFA initially takes either a or b b) {€,a,b}
followed by a then b then reaches the final state or takes c) {a,b}
iterations of a or b to reach the final state. d) {ab}
6. Which is the application of NFA
a) A regular language is produced by union of two Answer: c
regular languages Explanation: Either a is the output or b hence it’s {a, b}.
b) The concatenation of two regular languages is regular 4. The behaviour of a NFA can be stimulated by DFA
c) The Kleene closure of a regular language is regular a) Always
d) All of the mentioned b) Sometimes
c) Never
13
d) Depends on NFA
Answer: a
Explanation: It can be done through power set
construction.
5. For any DFA state {qi,qj…qm} If some qj is a final
state in the NFA Then {qi,qj…qm}, is a final state in the
DFA.True or False
a)
a) True
b) False
Answer: a
Explanation: It the the standard procedure to convert
NFA to DFA.
6. The relation between NFA-accepted languages and
DFA accepted languages is
a) > b)
b) <
c) =
d) <=
Answer: c
Explanation: The no of languages accepted by NFA and
DFA is equal.
7. In regular expressions, the operator ‘*’ stands for
a) Concatenation c)
b) Selection
c) Iteration
d) Addition
Answer: c
Explanation: It indicates iterations which can vary from
zero to any number.
. d)
Answer: a
Explanation: Initially in lexical analysis the program is
divided into tokens. Tokens can be expressed as regular
expressions: [a-zA-Z] [a-zA-Z0-9]*
14
the keyword if is given by if. the partially completed DFA that accepts this language is
Integers are given by [+-]? [0-9]+. shown below.
3. Is empty string a valid input in Ndfa
a) True
b) False
Answer: a
Explanation: Empty strings can be inputted n a NDFA.
4. What is the complement of the language accepted by
the NFA shown below? Assume ∑ = {a} and ε is the
empty string
The missing arcs in the DFA are
a) Φ
b) ε
c) a a)
d) {a, ε}
Answer: b
Explanation: The given alphabet ∑ contains only one
symbol {a} and the given NFA accepts all strings with
any number of occurrences of ‘a’. Hence the complement b)
is an empty string.
5. Given the language L = {ab, aa, baa}, whih of the
following strings are in L*?
1) abaabaaabaa
2) aaaabaaaa c)
3) baaaaabaaaab
4) baaaaabaa
a) 1, 2 and 3
b) 2, 3 and 4
c) 1, 2 and 4
d)
d) 1, 3 and 4
Answer: d
Answer: c
Explanation: State ‘q’ is trap state. All other states are
Explanation: Any combination of strings in set {ab, aa,
accepting states. In state 00, DFA must move to ‘q’ for
baa} will be in L*.
input symbol 0. All (non-trap) states indicate names
“abaabaaabaa” can be partitioned as a combination of
indicate the characters seen before reaching that
strings in set {ab, aa, baa}. The partitions are “ab aa baa
particular state. Option (D) is the only options that follow
ab aa”
these rules.
2) “aaaabaaaa” can be partitioned as a combination of
7. Which of the following problems occur?
strings in set {ab, aa, baa}. The partitions are “aa ab aa
….1) Does a given program ever produce an output?
aa”
….2) If L is a CFL, then is L’ is also context-free?
3) “baaaaabaaaab” cannot be partitioned as a
….3)L’ is regular only if L is regular?
combination of strings in set {ab, aa, baa}
….4) If L is a recursive language, then, L’ is also
4) “baaaaabaa” can be partitioned as a combination of
recursive?
strings in set {ab, aa, baa}. The partitions are “baa aa ab
a) 1, 2, 3, 4
aa”.
b) 1, 2,
6. Consider the set of strings on {0,1} in which, every
c) 2, 3, 4
substring of 3 symbols has at most two zeros. Complete
15
d) 3, 4 Answer: c
Explanation: The RE having 2 0’s padded by (0+1)*
Answer: d which means accepted strings must have at least 2 0’s.
Explanation: 1) Is a variation of Turing Machine Halting 3. Which one is a FALSE statement?
problem and it is undecidable. a) There exists a unique DFA for every regular language
….2) Context Free Languages are not closed under b) NFA can always are converted to a PDA
intersection and complement. c) Complement of CFL is always recursive
….3) Complement of Regular languages is also regular. d) Every NDFA can be converted to a DFA
….4) Recursive Languages is closed under complement.
8. Definition of a language L with alphabet {a} is given Answer: d
as following. L= { ank | k > 0, and n is a positive integer Explanation: Deterministic PDA cannot handle languages
constant} What is the minimum number of states needed or grammars with ambiguity, but NDFA can handle with
in a DFA to recognize L? ambiguous languages as well as context-free grammar.
a) k+1 Hence not every Ndfa can be converted to DFA.
b) n+1 4. Match the following
c) 2n+1 Group 1 Group 2
d) 2k+1 P. Regular expression 1. Syntax analysis
Q. Pushdown automata 2. Code generation
Answer: b R. Dataflow analysis 3. Lexical analysis
Explanation: Note that n is a constant and k is any S. Register allocation 4. Code optimization
positive integer. For example, let n=3, then the DFA a) P-4. Q-1, R-2, S-3
must be able to accept aaa, aaaaaa, aaaaaaaaa, , .. build b) P-3, Q-1, R-4, S-2
such a DFA, 4 states are required. c) P-3, Q-4, R-1, S-2
d) P-2, Q-1, R-4, S-3
Answer: b
Explanation: Regular grammar relates to lexical analysis
Pushdown automata relates to Syntax analysis
Data flow analysis is Code optimization
. Register allocation is code generation.
5. Let L = L1 ∩ L2, where L1 and L2 are languages as
The NFA with epsilon- Moves-1 - defined below:
“The NFA with epsilon- Moves – 1”. L1 = {ambmcanbn | m, n >= 0 }
1. S –> aSa| bSb| a| b ;the language generated by the L2 = {aibjck | i, j, k >= 0 }
above grammar is the set of Then L is
a) All palindromes. a) Not recursive
b) All odd length palindromes b) Regular
c) Strings beginning and ending with the same symbol c) Context free but not regular
d) All even length palindromes d) None of the mentioned
Answer: b Answer: c
Explanation: The strings accepted by language are {a, b, Explanation: The language L1 accept strings {c, abc,
aaa, bbb, aba, bab,}. All the strings are odd length abcab, aabbcab, aabbcaabb,} and L2 accept strings {a, b,
palindromes. c, ab, abc, aabc, aabbc, … }. Intersection of these two
2. Which one of the following languages over the languages is L1 ∩L2 = {akbkc | k >= 0} which is not
alphabet {0, 1} is described by the regular expression: regular but context free.
(0+1)*0(0+1)*0(0+1)*?
a) strings with the substring 00
b) strings with at most two 0’s
c) strings with at least two 0’s
d) strings beginning and ending with either 0 or 1
16
6. Convert the NFA to DFA Compilers for Experienced -
This set of Compilers for Experienced people focuses on
“The NFA with Epsilon – Moves – 2”.
1. NFA-εs are defined because certain properties can be
more easily proved on them as compared to NFA.
a) True
b) False
Answer: a
Explanation: NFA-ε can be transformed into a NFA
always, the properties are also true for NFAs.
2. E(q) is known ε-closure of q.
a) True
b) False
Answer: a
Explanation: The ε-closure of a set of states Z of an NFA
is defined as the set of states reachable from any state in
a) Z following ε-transitions.
3. ε-transitions does not add any extra capacity of
recognizing formal
a) True
b) False
Answer: a
Explanation: ε-transitions provides a convenient
transition in the systems whose current states are not
precisely known.
b)
4. Which of the following CFG’s can’t be simulated by
c) Both of the mentioned
an FSM ?
d) None of the mentioned
a) S->Sa/b
Answer: a
b) S->aSb/ab
Explanation: Initially Q is empty. Then since the initial
c) S->abX, X->cY, Y->d/aX
state of the DFA is {0} , {0} is added to Q.
d) None of these
Since 2( 0 , a ) = { 1 , 2 } , { 1 , 2 } is added to Q and
({0},a)={1,2}.
Answer: b
Since 2( 0 , b ) = , is added to Q and ( { 0 } , b ) = .
Explanation: generates the set {an bn ,n=1,2,3 ….}which
At this point Q = { {0} , { 1 , 2 }, }. Similarly ( { 1 , 2 } ,
is not regular ?.
b ) = { 1 , 3 } . Hence { 1 , 3 } is added to Q . Similarly
5. The transitions which does not take an input symbol
( { 1 , 3 } , a ) = { 1 , 2 } and ( { 1 , 3 } , b ) = . Thus
are called
there are no new states to be added to Q . Since the
a) ε-transitions
transitions from all states of Q have been computed and
b) λ-transitions
no more states are added to Q, the conversion process
c) None of these
stops here.
d) Both of the mentioned
7. Does epsilon ring any change in the automata
a) Yes
Answer: d
b) No
Explanation: The transitions taking an input symbol are
called ε-transitions or λ-transitions.
Answer: b
6. A nondeterministic finite automaton with ε-moves is
Explanation: It adds nothing new to the automata.
an extension of nondeterministic finite automaton
a) True
.
17
b) False Answer: c
Explanation: The states traversed are ABDBDABDAC,
Answer: a and the only edge not traversed C D.
Explanation: Both are equivalent. 2. If string s is accepted by this DFA, which of these
7. Is an ordinary NFA and a NFA-ε are equivalent strings cannot be suffix of s?
a) True
b) False
Answer: a
a) 111001
Explanation: Yes ordinary NFA and NFA-ε are the same,
b) 111111
in that, given either one, one can construct the other,
c) 111000
which recognizes the same language.
d) 101010
8. Which is a correct statement?
a) { If an bn | n = 0,1, 2, 3 ..} is regular language
Answer: a
b) Strings with equal number of a’s and b’s denies a
Explanation: 111001 cannot be the suffix of any string
regular language
accepted by this DFA. Suppose s=w111001. No matter
c) L (A* B*)∩ B gives the set A
what state the DFA reaches after reading w, it will go to
d) None of the mentioned
state D after reading “111”, then go to state B after
reading “00” and finally reaches state C after reading
Answer: c
“1”.
Explanation: If we include A and B in a set and if we
3. Find the pair of regular expressions that are equivalent
write A* it means except then A i.e. B same as B* means
a) (0+1)* and (0*+1*)*
except then B i.e. so if we intersect (A*B*) and B then
b) (0+1)* and (0+1*)*
get A because in any regular language. If we write A-B
c) (0+10)* and (0*+10)*
then A-B=A intersection B’ so if we intersect A and B
d) All of the mentioned
means A-B So intersection of (A*B*) and B = (BA)
intersection B means (BA)-B’ and B’=A so (BA)
Answer: d
intersection(A)=A
Explanation: All generate all strings of 0’s and 1’s thus
So ans is (C).
are these pairs are equivalent.
4. Which of the following strings is NOT in the Kleene
To practice all areas of Compilers for Experienced
star of the language {011, 10, 110}?
people, .
a) 01
b) 10
The NFA with n-moves to the DFA-1 -
c) 110
“The NFA with n-moves to the DFA”.
d) 10011101
1. Examine the following DFA: If input is 011100101,
which edge is NOT traversed?
Answer: d
Explanation: Every string in the language {011, 10,
110}* has to be formed from zero or more uses of the
strings 011, 10, and 110. A string may be used more than
once.
5. Which grammar is not regular
a) 0^n
b) 0^n 1^n n
c) 0^m 0^n n
a) A B d) 0^n 0^n n
b) C
c) C D Answer: a
d) D A Explanation: According to pumping lemma, is not a
regular language. It is the language of the DFA with two
states to achieve an even number of 0’s…
18
6. If is a language, and is a symbol, then, the quotient of Answer: b
and, is the set of strings such that is in: is in. Suppose is Explanation: S => AB => AbA => Aba => aSba =>
regular, which of the following statements is true? aABba => aAbAba => aAbaba => aababa.
a) L/a is always a regular language 9. The grammar G: S → SS | a | b is ambiguous. Check
b) L/a is not a regular language all and only the strings that have exactly two leftmost
c) Both of the mentioned derivations in G
d) None of the mentioned a) bbb
b) ab
Answer: a c) Both of the mentioned
Explanation: We can build a DFA for as such: firstly we d) None of the mentioned
get the DFA for: Then, we copy all the states and
transitions to the DFA for. However, we mark any state Answer: c
as a final state in if and only if is a final state in. Explanation: S => a. A string of length 2 has only one
7. a context-free grammar G: S → AB A → 0A1 | 2 B → derivation, e.g., S => SS => aS => ab.
1B | 3A which of the following strings are in L (G)? 10. For the following grammar: S → A | B | 2 A → C0 |
a) 021300211 D B → C1 | E C → D | E | 3 D → E0 | S E → D1 | S
b) 022111300211 Identify all the unit pairs
c) None of the mentioned a) D,C
d) Both of the mentioned b) A,B
c) B,C
Answer: d d) A,C
Explanation: First, notice that A generates strings of the
form 021, where n is 0 or more. Also, B gives zero or Answer: a
more 1’s, which is followed by one 3, and then A gives Explanation: The cycle of unit-productions S → A → D
something. Since S generates something an A can → S says that any pair involving only S, A, and D is a
generate followed by something a B can generate, the unit pair. Similarly, the cycle S → B → E → S tells us
strings in L (G) are of the form 0 21 30 21. that any pair involving S, B, and E is a unit pair.
8. The parse tree below represents a rightmost derivation
according to the grammar S → AB, A → aS|a, B → bA. .
Which of the following are right-sentential forms
corresponding to this derivation? Compilers Interview for Experienced -
This set of Compilers Interview for Experienced people
focuses on “The NFA with epsilon-moves to the DFA-2”.
1. The classes of languages P and NP are closed under
certain operations, and not closed under others. Decide
whether P and NP are closed under each of the following
operations.
1. Union
2. Intersection
3. Intersection with a regular language
4. Kleene closure (star)
5. Homomorphism
6. Inverse homomorphism
a) P is not closed under union
b) NP is not closed under intersection.
c) None of the mentioned
a) aAbAba
d) Both of the mentioned
b) aababa
c) aABba
Answer: d
d) aSba
Explanation: Both P and NP are closed under each of
these operations.
2. Ndfa and dfa accept same languages
a) True
19
b) False Answer: a
Explanation: nfa has n then dfa has at max 2^n.
Answer: a 8. An NFA is nothing more than a ε-NFA with no ε
Explanation: They both are equivalent. transitions
3. __________ a part of a compiler that is responsible for a) True
recognizing syntax. b) False
a) Parser
b) Bzr Answer: a
Answer: c Answer: a
Explanation: A compiler’s scanner reads an input stream Explanation: for every NFA t a ε-NFA that accepts the
that consists of characters and produces an output stream similar language, and vice versa.
that contains words, each labelled with its Syntactic
category. To practice all areas of Compilers for Interviews, .
5. _________an IR-to-IR transformer that tries to
improve the IR program in some way. Minimization of DFA-1 -
a) Optimizer “Minimization of DFA”.
b) Parser 1. Consider the languages L1 = and L2 = {a}. Which one
c) Both of the mentioned of the following represents L1 L2* U L1*
d) None of the mentioned a) €
b) a*
Answer: a c) Both of the mentioned
Explanation: The optimizer is an IR-to-IR transformer d) None of the mentioned
that tries to improve the IR program in some way.
6. _________a phase of a compiler that maps the IR Answer: a
program into the instruction set and the finite resources Explanation: L1* = * which is { }.
of the target machine.
a) Optimizer
b) Parser
c) None of the mentioned
d) Both of the mentioned
Answer: c
Explanation: In a two-phase compiler, ensures that t a
source program and an object program.
7. If the NFA N has n states, then the corresponding DFA
D has 2n states
a) True
b) False
20
2. Choose the correct statement for the following Answer: b
Explanation: The given alphabet contains only one
symbol {a} and the given NFA accepts all strings with
any number of occurrences of ‘a’.
5. A deterministic finite automation (DFA)D with
alphabet {a,b} is given below Which of the following
finite state machines is a valid minimal DFA which
accepts the same language as D?
Answer: d a)
Explanation: The DFA can be minimized to two states
and the second state is final state .We reach second state
after a 0.
3. Given the language L = {ab, aa, baa}, which of the
following strings are in L*?
1) abaabaaabaa
2) aaaabaaaa b)
3) baaaaabaaaab
4) baaaaabaa
a) 1, 2, 3
b) 2, 3, 4
c) 1, 2, 4 c)
d) 1, 3, 4
Answer: c
Explanation: The given alphabet ∑ contains only one
symbol {a} and the given NFA accepts all strings with
any number of occurrences of ‘a’.
4. W hat is the complement of the language accepted by
the NFA shown below?
d)
Answer: a
Explanation: Options (B) and (C) are invalid because
a) A,B they both accept ‘b’ as a string which is not accepted by
b) B give DFA. D is invalid because it accepts bb+a which are
c) C not accepted by given DFA.
d) D,C 6.Let w be any string of length n is {0,1}*. Let L be the
set of all substring of w.
State the minimum number of states in a NDFA that
21
accepts L? a) P-2,Q-1,R-3,S-4
b) P-1, Q-3, R-2,S-4
c) P-1,,Q-2,R-3,S-4
d) P-3.Q-2,R-1,S-4
Answer: c
a) n-1
Explanation: The above figures correctly represent the
b) n
figures
c) n +1
Eg: p gives ϵ + 0(01*1 + 00) * 01* and the q gives the
d) 2n-1
expression ϵ + 0(10 *1 + 00) * 0 and so on.
10. Which of the following are regular sets?
Answer: c
I. { a^n b^2m | n>=0, m>=0}
Explanation: We need minimum n+ 1 state to build NFA
II. {a^n b^m |n=2m}
that accepts all substrings of a binary string. Following
III. {a^n b^m | n!= m}
NFA accepts all strings containing substring of “010″ and
IV {xcy |x,y€{a,b)*}
it has 4 states.
a) I and IV
7. Which one of the following languages over the
b) I and III
alphabet {0,1} is described by the regular expression:
c) I and only
(0+1)*0(0+1)*0(0+1)*?
d) IV
a) String with substring 00
b) string with at most two 0’s
Answer: a
c) string containg at least two 0’s
Explanation: We can write DFA for both I and IV.
d) None of the mentioned
.
Answer: c
Explanation: The regular expression has two 0′s
Minimization of DFA-2 -
surrounded by (0+1)* which means accepted strings must
“Minimization of DFA”.
have at least 2 0′s.
1. The language accepted by this DFA is
8. Which one of the following is FALSE?
a) Every NFA can be converted to DFA
b) Every subset of a recursively enumerable set is
recursive
c) Both of the mentioned
d) None of the mentioned
Answer: b a) b*ab*ab*ab*
Explanation: Every subset of a recursively enumerable b) (a+b)*
set is recursive. c) b*a(a+b)*
9. Match the following NFAs with the regular d) b*ab*ab*
expressions they correspond to
1. ϵ + 0(01*1 + 00) * 01* Answer: c
2. ϵ + 0(10 *1 + 00) * 0 Explanation: Initially circle s around b so b* then a then
3. ϵ + 0(10 *1 + 10) *1 followed by (a+b)*.
4. ϵ + 0(10 *1 + 10) *10 * 2. The minimum state automaton equivalent to the above
FSA has the following number of states
a) 1
22
b) 2 b) I and III only
c) 3 c) II and III only
d) 4 d) I II III
Answer: b Answer: b
Explanation: State q0 can be omitted because it takes the Explanation: 0*1(1+00*1)*
same input as state q1 hence by removing q0 nothing II) 0*1*1+11*0*1
changes.v III) (0+1)*1
(I) and (III) represent DFA.
(II) doesn’t represent the DFA since it accepts strings like
11011,
occurrences
of (000)’s as (111)’s}.
Following is equivalent FSA with 2 states.
Which one of the following is TRUE?
3. Which one of the following is TRUE?
a) L1 is regular but not L2
a) The language L={a^n b^n |n>0 } is regular
b) L2 is regular
b) The language L={a^n |n is prime } is regular
c) L1 and L2 are regular
c) The language L={w|w has 3k+1 b’s for some k } is
d) Neither of them are regular
regular
d) None of these
Answer: A
Explanation: L1 is regular let us considering the string
Answer: c
011011011011 . Number of times 011 has occurred is 4
Explanation: Only for this option we can build a FA.
but also its occurrence is 3. Also if the string is ending
with 011 we can make a 110 . Now the next string:
110110110110 in this 110 has occurred 4 times and 011
3 times which already satisfy the .
7. The length of the shortest string NOT in the language
(over Σ = {a, b}) of the following regular expression is
4. ______________.
a) q0, q1,q2 a*b*(ba)*a*
b) q0,q1 a) 2
c) q0,q1,q2,q3 b) 3
d) q3 c) 4
d) 5
Answer: a
Explanation: From q0 state ->0 then again remain on the Answer: B
same state 0, then to next state 1and to q2 we get 1. Explanation: baa is not regular so 3.
5. Which of the regular expressions given below 8. Consider the machine M: The language recognized by
represent the following DFA? M is :
Answer: b
Explanation: if the NFA has n states, the resulting DFA
may have up to 2n states, an exponentially larger number,
which sometimes makes the construction impractical for
S denotes the set of seven bit in which the 1st ,4th and large NFAs.
last bits are 1. The number of strings that are accepted by 3. What can be said about a regular language L over {a}
M is whose minimal finite state automaton has two states?
a) 1 a) L must be {an| n is odd}
b) 5 b) L must be {an| n is even}
c) 7 c) L must be {an| n is even}
d) 8 d) Either L must be {an | n is odd}, or L must be {an | n
is even}
Answer: c
Explanation: Language that can be accepted by DFA is Answer: d
1001001 1001011, 1001101, 1001111, 1101001, Explanation: There are two states. When first state is
1111001, 1011001. final, it accepts even no. of a’s. When second state is
final, it accepts odd no. of a’s.
. 4. How many minimum states are required to find
whether a string has odd number of 0’s or not
Obtaining the regular Expression from the Finite a) 1
automata-1 - b) 2
“Obtaining the regular Expression from the finite c) 3
automata”. d) 4
1. L1 is accepted by the NFA, obtained by changing the
accepting state of M to a non-accepting state and vice Answer: b
versa. Which of the following statements is true? Explanation:
a) L1 = {0, 1}* – L
5. The number of states in DFA that accepts the language
c) L1 ⊆ L
b) L1 = {0, 1}* – L
L(M) ∩ L(N) is ________.
d) L1=L
Answer: b
Explanation: either it takes 0 or 1 or iterations of it or
a) 0
24
b) 1 L1 is interesting. The important thing to note
c) 2 about L1 is length of x is greater than 0.
d) 3 8. The reorganizing capability of NDFA and DFA
a) May be diffent
Answer: b b) Must be different
Explanation: In DFA M: all strings must end with ‘a’. In c) Must be same
DFA N: all strings must end with ‘b’. So the intersection d) None of the mentioned
is empty. For an empty language, only one state is
needed. Answer: c
Explanation: Given any NDFA one can construct an
equivalent DFA.
9. Which of the following is not regular?
a) String whose length is perfect square and consists of
0s
6. Consider alphabet ∑ = {0, 1}, the null/empty string λ
b) Palindromes consisting of 0’s and 1’s
and the sets of strings X0, X1 and X0.How are X1 and
c) Both of the mentioned
X2 are related ?
d) None of the mentioned
X0 = 1 X1
X1 = 0 X1 + 1 X2
Answer: c
X2 = 0 X1 + {λ}
Explanation: Strings of odd numbers of zeros can be
Which one of the following represents the strings in X0?
generated by regular expression (00)*0.
a) 10 (0* + (10)*)1
10. Which of the following pairs of regular expression
b) 10 (0* + (10)*)*1
are equivalent?
c) 10 (0* + (10)*)*1
a) 1(01)* and (10)*1
d) 10 (0 + 10)*1 + 110 (0 + 10)*1
b) X(xx)* and (xx)*x
View Answe
c) None of the mentioned
Answer: c
d) Both of the mentioned
Explanation: The smallest possible string by given
grammar is “11”.
Answer: d
X0 = 1X1
Explanation: R1 and R2 are reverse of each other. If ant
= 11X2 [Replacing X1 with 1X2] = 11 [Replacing X2
one of them can be generated them the other can be
with λ]
generated as well.
The string “11” is only possible with option (C).
L3: {apbqcr ⎪ p, q, r ≥ 0}
This set of Compilers test focuses on “Obtaining the
Regular Expression from the Finite Automata – 2”.
a) L1 and L3 only
1. Which of the following identity is true?
b) L2
a) Ɛ +RR* = R* = ɛ + R*R
c) L2 and L3 only
b) (R1R2)*R1 = R1 (R2R1)*
d) L3 only
c) R*R* = R*
d) All of the mentioned
Answer: a
Explanation: L3 is simple to guess, it is regular. Answer: d
Below is DFA for L1. Explanation: The former Re can be produced from the
latter one.
2. The set of all strings over ∑ = {a,b} in which all
strings having bbbb as substring is
a) (a+b)* bbbb (a+b)*
b) (a+b)* bb (a+b)*bb
c) bbb(a+b)*
25
d) bb (a+b)* c) L1
d) All of the mentioned
Answer: a
Explanation: Out of all RE mentioned only the first string Answer: d
certainly has bbbb as substring. Rest all just have a Explanation: all these expression give us a regular
possibility of having it. grammar when L1 and L2 are regular.
3. The set of all strings over ∑ ={a,b} in which a single a 8. Regular expression a/b denotes the set
is followed by any number of b’s a single b followed by a) {a}
any number of a’s is b) {ab}
a) ab* + ba* c) {a,b}
b) ab*ba* d) None of the mentioned
c) a*b + b*a
d) None of the mentioned Answer: c
Explanation: Because it would give either a or b.
Answer: a 9. Which of the following regular expression denotes
Explanation: ab*+ba* is the expression in which which a zero or more instances of an a or b?
single a is followed by any number of b’s a single b a) a/b
followed by any number of a’s. b) (a/b)*
4. Regular expressions are used to represent which c) (ab)*
language d) a*Ib
a) Recursive language
b) Context free language Answer: b
c) Regular language Explanation: this expression gives o or more instances of
d) All of the mentioned a or b .
10. The string (a)|((b)*(c)) is equivalent to
Answer: c a) Empty
Explanation: Regular expression is represented by b) abcabc
regular language. c) b*c|a
5. The set of all strings over ∑ = {a,b} in which strings d) None of the mentioned
consisting a’s and b’s and ending with in bb is
a) ab Answer: c
b) a*bbb Explanation: Either b or a can lead followed by c this
c) (a+b)* bb expression can be achieved by C as well.
d) All of the mentioned
To practice all areas of Compilers for tests, .
Answer: c
Explanation: only this expression ends with bb only. Lexical Analyser-1 -
6. If P, Q, R are three regular expressions and if P does “Lexical Analyser”.
not contain a then the equation R = R + RP has a unique 1. In a compiler the module that checks every character
solution given by of the source text is called
a) R = QP* a) The code generator
b) R = P*Q b) The code optimizer
c) R = RP c) The lexical analyzer
d) None of the mentioned d) The syntax analyzer
Answer: a Answer: a
Explanation: It is an important law primarily used in Explanation: lexical analysis is the process of converting
conversion. a sequence of characters into a sequence of tokens.
7. If L1 and L2 are regular languages is/are also regular 2. The context free grammar is ambiguous if
language(s). a) The grammar contains non-terminals
a) L1 + L2 b) Produces more than one parse tree
b) L1L2 c) Production has two non-terminals side by side
26
d) None of the mentioned d) None of the mentioned
Answer: b Answer: a
Explanation: Since more than one parse tree is generated Explanation: Lexical Analysis Identifies Different
hence one than option is available .Therefore it’s Lexical Units in a source Code.
ambiguous. 9. Which one is a type of Lexeme
3. Another Name for Lexical Analyser a) Identifiers
a) Linear Phase b) Constants
b) Linear Analysis c) Keywords
c) Scanning d) All of the mentioned
d) All of the mentioned
Answer: d
Answer: d Explanation: All of them along with Operators are
Explanation: Lexical Analyzer is also called “Linear different types of lexemes.
Phase” or “Linear Analysis” or “Scanning“. 10. A________ is a string of characters which form a
4. An individual token is called ________ syntactic unit.
a) Lexeme a) Lexeme
b) Lex b) Lex
c) Both of the mentioned c) None of the mentioned
d) None of the mentioned d) Both of the mentioned
Answer: a Answer: a
Explanation: Individual Token is also Called Lexeme. Explanation: A lexeme is a string of characters which
5. Lexical Analyser’s Output is given to Syntax Analysis. forms a syntactic unit.
a) True
b) False .
Answer: a Answer: c
Explanation: Lexical Analyzer is First Phase of Explanation: The process of forming tokens from an
Compiler. input stream of characters is called tokenization.
7. Input to Lexical Analyser is 2. When expression sum=3+2 is tokenized then what is
a) Source Code the token category of 3
b) Object Code a) Identifier
c) Lexeme b) Assignment operator
d) None of the mentioned c) Integer Literal
d) Addition Operator
Answer: a
Explanation: Lexical analyser’s Input is Source Code. Answer: c
8. Lexical Analysis Identifies Different Lexical Units in a Explanation:
_______. Lexeme
a) Source Code Token category
b) Object Code Sum “Identifier”
c) Lexeme = “Assignment operator”
3 “Integer literal”
27
+ “Addition operator” Answer: a
2 “Integer literal” Explanation: Lexers are often generated by a lexer
; “End of statement”. generator same as parser.
3. Which grammar defines Lexical Syntax 8. Which one is a lexer Generator
a) Regular Grammar a) ANTLR
b) Syntactic Grammar b) DRASTAR
c) Context free Grammar c) FLEX
d) Lexical Grammar d) All of the mentioned
Answer: d Answer: d
Explanation: The specification of a programming Explanation: ANTLR – Can generate lexical analyzers
language often includes a set of rules, the lexical and parsers.
grammar, which defines the lexical syntax. DFASTAR – Generates DFA matrix table-driven lexers
4. Two Important lexical categories are in C++.
a) White Space Flex – variant of the “lex” (C/C++).
b) Comments Ragel – A state machine and lexer generator with output
c) None of the mentioned in C, C++, C#, Objective-C, D, Java, Go and Ruby.
d) Both of the mentioned 9. Which of the lexical analyser can handle Unicode
a) Java CC
Answer: d b) JFLex
Explanation: Two important common lexical categories c) Quex
are white space and comments. d) All of the mentioned
5. It has encoded within it information on the possible
sequences of characters that can be contained within any Answer: d
of the tokens it handles .Above motioned function is Explanation: JavaCC – JavaCC generates lexical
performed by? analyzers written in Java.
a) Scanner JFLex – A lexical analyzer generator for Java.
b) Parser Quex – A fast universal lexical analyzer generator for C
c) Syntactic Analyser and C++.
d) All of the mentioned FsLex – A lexer generator for byte and Unicode character
input for F#.
Answer: a 10. The output of a lexical analyzer is
Explanation: The first stage, the scanner, is FSM. It has a) Machine Code
encoded information on the possible sequences of b) Intermediate Code
characters that can be contained within any of the tokens c) Stream of Token
it handles . d) Parse Tree
6. What goes over the characters of the lexeme to
produce a value? Answer: c
a) Scanner Explanation: The output given is in form of tokens.
b) Parser
c) Evaluator .
d) Lexical generator
Syntax Analyser-1 -
Answer: a “Syntax Analyser”.
Explanation: In order to construct a token, the lexical 1. Which phase of compiler is Syntax Analysis
analyzer needs a second stage, the evaluator, which goes a) First
over the characters of the lexeme to produce a value. b) Second
7. Lexers are often generated by a lexer generator, same c) Third
as parser generators, d) None of the mentioned
a) True
b) False Answer: b
Explanation: It is Second Phase Of Compiler after
Lexical Analyzer.
28
2. What is Syntax Analyser also known as 8. Which of these features of assembler are Machine-
a) Hierarchical Analysis Dependent
b) Hierarchical Parsing a) Instruction formats
c) None of the mentioned b) Addressing modes
d) Both of the mentioned c) Program relocation
d) All of the mentioned
Answer: d
Explanation: It is also called as Hierarchical Analysis or Answer: d
Parsing. Explanation: All of these options are features of
3. Syntax Analyser takes Groups Tokens of source assembler which are machine dependent.
Program into Grammatical Production 9. A compiler can check?
a) True a) Logical Error
b) False b) Syntax Error
c) Both Logical and Syntax Error
Answer: a d) Not Logical and Syntax Error
Explanation: It Groups Tokens of source Program into
Grammatical Production. Answer: b
4. From where it take its input from? Explanation: No compiler can ever check logical errors.
a) Lexical analyser 10. The fourth Generation computer was made up of?
b) Syntactic Analyser a) Transistor
c) Semantic Analyser b) Vacuum tubes
d) None of the mentioned c) Chips
d) Microprocessor chips
Answer: a
Explanation: A syntax analyzer or parser takes the input Answer: d
from a lexical analyzer in the form of token streams. Explanation: It is the only way to increase its throughput.
5. Parsers are expected to parse the whole code
a) True .
b) False
Syntax Analyser-2 -
Answer: a “Syntax Analyser”.
Explanation: Parsers are expected to parse the whole 1. Select a Machine Independent phase of the compiler
code even if some errors exist in the program. a) Syntax Analysis
6. A grammar for a programming language is a formal b) Intermediate Code generation
description of c) Lexical Analysis
a) Syntax d) All of the mentioned
b) Semantics
c) Structure Answer: d
d) Library Explanation: All of them work independent of a machine.
2. A system program that combines the separately
Answer: c compiled modules of a program into a form suitable for
Explanation: The grammar clearly indicates that which execution?
type of a structure does a program has. a) Assembler
7. Which of these is not true about Symbol Table? b) Compiler
a) All the labels of the instructions are symbols c) Linking Loader
b) Table has entry for symbol name address value d) Interpreter
c) Perform the processing of the assembler directives
d) Created during pass 1 Answer: c
Explanation: A loader which combines the functions of a
Answer: c relocating loader with the ability to combine a number of
Explanation: The Symbol table does not ever perform the program segments that have been independently
processing of the assembler derivative. compiled.
29
3. Which of the following system software resides in the 9. What does a Syntactic Analyser do?
main memory always a) Maintain Symbol Table
a) Text Editor b) Collect type of information
b) Assembler c) Create parse tree
c) Linker d) None of the mentioned
d) Loader
Answer: c
Answer: d Explanation: Syntax analyzer will just create parse tree.
Explanation: Loader is used to loading programs. Semantic Analyzer checks the meaning of the string
4. Output file of Lex is _____ the input file is Myfile? parsed.
a) Myfile.e 10. Semantic Analyser is used for?
b) Myfile.yy.c a) Generating Object code
c) Myfile.lex b) Main ting symbol table
d) Myfile.obj c) None of the mentioned
d) Both of the mentioned
Answer: b
Explanation: This Produce the filr “myfile.yy.c” which Answer: d
we can then compile with g++. Explanation: Maintaining the Symbol Table for each
5. Type checking is normally done during? block.
a) Lexical Analysis Source Program for Semantic Errors.
b) Syntax Analysis Collects Type Information for Code Generation.
c) Syntax Directed Translation Reporting compile-time errors in the code Generating the
d) Code generation object code (e.g., assembler or intermediate code).
Answer: c .
Explanation: It is the function of Syntax directed
translation. Context Free Grammar-1 -
6. Suppose One of the Operand is String and other is “Context free Grammar”.
Integer then it does not throw error as it only checks 1. Assume the statements S1 and S2 given as:
whether there are two operands associated with ‘+’ or not S1: Given a context free grammar, there exists an
. algorithm for determining whether L (G) is infinite.
a) True S2: There exists an algorithm to determine whether two
b) False context free grammars generate the same language.
Which of the following is true?
Answer: a a) S1 is correct and S2 is not correct
Explanation: Syntax analyser does not check the type of b) Both S1 and S2 are correct
the operand. c) Both S1 and S2 are not correct
7. In Short Syntax Analysis Generates Parse Tree d) S1 is not correct and S2 is correct
a) True
b) False Answer: a
Explanation: The proof of S1 can be seen in various book
Answer: a of theory of computation but s2 is a problem of category
Explanation: Short Syntax Analysis generates a parse undecidable so a contradiction to this assumption can be
tree. easily obtained.
8. By whom is the symbol table created? 2. If P & R are regular and also given that if PQ=R, then
a) Compiler a) Q has to be regular
b) Interpreter b) Q cannot be regular
c) Assembler c) Q need not be regular
d) None of the mentioned d) Q has to be a CFL
Answer: a Answer: c
Explanation: symbol table is created by the compiler Explanation: If two regular languages when combined do
which contains the list of lexemes or tokens. not always produce a regular language.
30
3. Which of the following conversion is not possible a) a*
(algorithmically)? b) ab*
a) Regular grammar to CFG c) (a/b)*
b) NDFA to DFA d) a*b*c
c) NDPDA to DPDA
d) NDTM to DTM Answer: a
Explanation: it gives any number of a’s.
Answer: c 8. Grammars that can be translated to DFAs:
Explanation: Not every NDPDA has an equivalent a) Left linear grammar
deterministic PDA. b) Right linear grammar
4. Consider the grammar given below E? E+E | E*E | E-E c) Generic grammar
| E/E | E^E | (E) | id Assume that + and ^ have the same d) All of the mentioned
but least precedence, * and / have the next higher
precedence but the same precedence and finally ^ has the Answer: b
highest precedence. Assume + and ^ associate to the left Explanation: Right linear grammar can be translated to
like * and / and that ^ associates to the right. Choose the the DFAs.
correct for the ordered pairs (^,^) , (-,-) , (+,+) , (*,*) in 9. The language accepted by a Push down Automata:
the operator precedence table constructed for the a) Type0
grammar b) Type1
a) All < c) Type2
b) All > d) Type3
c) < > , =
d) < > > > Answer: c
Explanation: A known fact that type 2 grammar is
Answer: d accepted by PDA.
Explanation: This relation is established of basis of the 10. Given the following statements: (i) Recursive
precedence of operators. enumerable sets are closed under complementation. (ii)
5. Recursively enumerable languages are not closed Recursive sets are closed under complements. Which
under: is/are the correct statements?
a) Union a) I only
b) Intersection b) II only
c) Complementation c) Both I and II
d) Concatenation d) Neither I nor II
Answer: c Answer: b
Explanation: Recursive languages are closed under the Explanation: Recursive languages are closed under the
following operations. following operations.
The Kleene star L * of L The Kleene star L * of L
the concatenation L * o P of L and P the concatenation L * o P of L and P
the union L U P the union L U P
the intersection L ∩ P. the intersection L ∩ P.
6. Grammar that produce more than one Parse tree for
same sentence is: .
a) Ambiguous
b) Unambiguous Compilers Quiz -
c) Complementation This set of Compilers Quiz focuses on “Context Free
d) Concatenation Intersection Grammar – 2”.
1. Assume statements S1 and S2 defined as: S1: L2-L1 is
Answer: a recursive enumerable where L1 and L2 are recursive and
Explanation: an ambiguous grammar is one for which t recursive enumerable respectively. S2: The set of all
more than one parse tree for a single sentence. Turing machines is countable. Which of the following is
7. Automaton accepting the regular expression of any true?
number of a ‘ s is: a) S1 is correct and S2 is not correct
31
b) Both S1 and S2 are correct b) In derivation tree, the label of all nodes except leaf
c) Both S1 and S2 are not correct nodes is a variable
d) S1 is not correct and S2 is correct c) In derivation tree, if the root of a sub tree is X then it is
called –tree
Answer: b d) None of the mentioned
Explanation: The assumptions of statement S1 and S2 are
correct. Answer: d
2. A context free language is called ambiguous if Explanation: All of them are true regarding a derivation
a) It has 2 or more left derivations for some terminal tree.
string ѡ є L (G) 7. Push down automata accepts which language
b) It has 2 or more right derivations for some terminal a) Context sensitive language
string ѡ є L (G) b) Context free language
c) Both of the mentioned c) Recursive language
d) None of the mentioned d) None of the mentioned
Answer: b Answer: b
Explanation: A context-free grammar (CFG) is a set of Explanation: PDA accepts CFG.
recursive rewriting rules (or productions) used to 8. A regular Grammar is a?
generate patterns of strings. a) CFG
3. Which of the following statement is false? b) Non CFG
a) The CFG can be converted to Chomsky normal form c) English Grammar
b) The CFG can be converted to Greibach normal form d) None of the mentioned
c) CFG is accepted by pushdown automata
d) None of the mentioned Answer: a
Explanation: Regular grammar is CFG.It restricts its
Answer: d rules to a single non terminal on left hand side.
Explanation: All the statements follow the rules. 9. A CFG is closed under
4. The context free grammar S → A111|S1, A → A0 | 00 a) Union
is equivalent to b) Kleene star
a) {0ⁿ1ᵐ | n=2, m=3} c) Concatenation
b) {0ⁿ1ᵐ | n=1, m=5} d) None of the mentioned
c) {0ⁿ1ᵐ | n should be greater than two and m should be
greater than four} Answer: d
d) None of the mentioned Explanation: CFG is closed under the above mentioned 3
operations.
Answer: a 10. Which of these does not belong to CFG
Explanation: S-> A111 a) Terminal Symbol
S->00111 (A->00). b) Non terminal Symbol
5. The context free grammar S → SS | 0S1 | 1S0 | ɛ c) Start symbol
generates d) End Symbol
a) Equal number of 0’s and 1’s
b) Unequal number of 0’s and 1’s Answer: d
c) Number of 0’s followed by any number of 1’s Explanation: CFG consist of terminal non terminal start
d) None of the mentioned symbol set of production rules but does not have an end
symbol.
Answer: a
Explanation: S->SS To practice all areas of Compilers for Quizzes, .
S->0S1S
S->0S11S0 Regular Grammar-1 -
S->0110. “Regular Grammar”.
6. Which of the following statement is false? 1. How many strings of length less than 4 contains the
a) In derivation tree, the label of each leaf node is language described by the regular expression
terminal (x+y)*y(a+ab)*?
32
a) 7 Answer : b
b) 10 Explanation : Except b all are regular expression*.
c) 12 7. Regular expression are
d) 11 a) Type 0 language
b) Type 1 language
Answer : d c) Type 2 language
Explanation : string of length 0 = 1 d) Type 3 language
string of length 1 = 4
string of length 2 = 3 Answer : a
string of length 3 = 3. Explanation : According to Chomsky hierarchy .
2. Which of the following is true? 8. Which of the following is true?
a) (01)*0 = 0(10)* a) All subsets of a regular set are always regular
b) (0+1)*0(0+1)*1(0+1) = (0+1)*01(0+1)* b) All finite subsets of non-regular set are always regular
c) (0+1)*01(0+1)*+1*0* = (0+1)* c) Union of two non regular set of language is not regular
d) All of the mentioned d) Infinite times union of finite set is always regular
Answer : d Answer : b
Explanation : None. Explanation : None.
3. A language is regular if and only if 9. L and ~L are recursive enumerable then L is
a) Accepted by DFA a) Regular
b) Accepted by PDA b) Context free
c) Accepted by LBA c) Context sensitive
d) Accepted by Turing machine d) Recursive
Answer : a Answer : d
Explanation : All of above machine can accept regular Explanation :If L is recursive enumerable and its
language but all string accepted by machine is regular complement too if and only if L is recursive.
only for DFA. 10. Regular expressions are closed under
4. Regular grammar is a) Union
a) Context free grammar b) Intersection
b) Non context free grammar c) Kleene star
c) English grammar d) All of the mentioned
d) None of the mentioned
Answer : d
Answer : a Explanation : According to definition of regular
Explanation : Regular grammar is subset of context free expression.
grammar.
5. Let the class of language accepted by finite state .
machine be L1 and the class of languages represented by
regular expressions be L2 then Regular Grammar-2 -
a) L1=L2 “Regular Grammar”.
c) L1 U L2 = .* 1. Consider the production of the grammar S->AA A->aa
d) L1=L2 A->bb Describe the language specified by the production
grammar.
Answer : d a) L = {aaaa,aabb,bbaa,bbbb}
Explanation : Finite state machine and regular expression b) L = {abab,abaa,aaab,baaa}
have same power to express a language. c) L = {aaab,baba,bbaa,bbbb}
6. Which of the following is not a regular expression? d) L = {aaaa,abab,bbaa,aaab}
a) [(a+b)*-(aa+bb)]*
b) [(0+1)-(0b+a1)*(a+b)]* Answer: a
c) (01+11+10)* Explanation: the production rules give aaaa or aabb or
d) (1+2+0)*(1+2)* bbaa or bbbb.
33
2. Give a production grammar that specified language L b) {xx,xy,yx,yy}
= {ai b2i >= 1} c) {x,y}
a) {S->aSbb,S->abb} d) {x,y,xy}
b) {S->aSb, S->b}
c) {S->aA,S->b,A->b} Answer: b
d) None of the mentioned Explanation: the expression gives aa or xy or yx or yy.
8. Regular expression x/y denotes the set
Answer: a a) {x,y}
Explanation: S->aSbb, S->abb give a^I a’s and b^2i b’s. b) {xy}
3. Let R1 and R2 be regular sets defined over alphabet ∑ c) {x}
then d) {y}
a) R1 UNION R2 is regular
b) R1 INTERSECTION R2 is regular Answer: a
c) ∑ INTERSECTION R2 IS NOT REGULAR Explanation: x or y is given by the expression.
d) R2* IS NOT REGULAR 9. The regular expression denote a language comprising
all possible strings of even length over the alphabet (0,1)
Answer: a a) 1 + 0(1+0)*
Explanation: union of 2 regular languages is regular. b) (0+1)(1+0)*
4. Which of the following String can be obtained by the c) (1+0)
language L = {ai b2i / i >=1} d) (00+0111+10)*
a) aaabbbbbb
b) aabbb Answer: d
c) abbabbba Explanation: the condition is satisfied by 00 or 0111 or
d) aaaabbbabb 10 or iterations of these.
10. The regular expressions denote zero or more
Answer: a instances of an x or y is
Explanation: above production rule gives suppose if 3 a’s a) (x+y)
the corresponding b’s are 6 b’s. b) (x+y)*
34
Answer: a 8. Which Type of Grammar is it?
Explanation: grammar is non-linear because one of the S → Aa A → Aab | λ
rules (the first one) has two non-terminals on the right- a) Right Linear
hand side. b) Left Linear
3. Linear grammar has more than one non-terminal on c) None of the mentioned
the right-hand side. d) Both of the mentioned
a) True
b) False Answer: b
Explanation: In this case they both correspond to the
Answer: a regular expression (ab)*a.
Explanation: Grammar is linear because no rule has more 9. A Regular Grammar is any right-linear or left-linear
than one non terminal on the right-hand side. grammar.
4. In Right-Linear grammars, all productions have the a) True
form: A → xB b) False
a) True
b) False Answer: a
Explanation: As it turns out the languages that can be
Answer: a generated by Regular Grammars is equivalent to those
Explanation: Right-Linear grammars, following are the that can be specified by Regular Expressions.
form of productions: A → xB or A → x where x is some 10. Regular Grammars generate Regular Languages.
string of terminals. a) True
5. S → abS S → a is which grammar b) False
a) Right Linear Grammar
b) Left Linear Grammar Answer: a
c) Both of the mentioned Explanation: That’s why they are called regular
d) None of the mentioned languages.
35
d) None of the mentioned Answer: b
Explanation: Right Linear grammar can be translate to
Answer: b DFA.
Explanation: Push Down Automata manipulate the Stack 9. A language is regular if and only if it is accepted by
as a part of performing a transition. finite automata
4. Transition of finite automata is a) The given statement statement is true
a) Finite Diagram b) Given statement is false
b) State Diagram c) Statement is partially true
c) Node Diagram d) None of the mentioned
d) E-R Diagram
Answer: a
Answer: b Explanation: Regular Language is accepted by Finite
Explanation: Transition of finite automata is Finite Automata. Every regular language is Context free.
Diagram. 10. A Push Down Automata is if t at most one transition
5. A context free language is called ambiguous if applicable to each configuration?
a) It has 2 or more than 2 left derivations for some a) Deterministic
terminal string ѡ є L (G) b) Non deterministic
b) It has 2 or more than 2 left derivations for some c) Finite
terminal string ѡ є L (G) d) Non finite
c) Both of the mentioned
d) None of the mentioned Answer: a
Explanation: In every situation only one transition is
Answer: c available as continuation then the result is deterministic
Explanation: When two or more Left and right most push down automata.
derivative occur the grammar turn ambiguous .
6. Which of the following statement is true? To practice MCQs on all areas of Compilers, .
a) Every language that is defined by regular expression
can also be defined by finite automata Top-Down Parsing-1 -
b) Every language defined by finite automata can also be “Top-Down Parsing”.
defined by regular expression 1. Which of the following derivations does a top-down
c) We can convert regular expressions into finite parser use while parsing an input string?
automata a) Leftmost derivation
d) All of the mentioned b) Leftmost derivation in reverse
c) Rightmost derivation
Answer: d d) Rightmost derivation in reverse
Explanation: All these statements are true w.r.t regular
expression. Answer: a
7. Which of the following identity is wrong? Explanation: In top down parser takes input from Left to
a) R + R = R right constructing leftmost derivation of the sentence.
b) (R*)* = R* 2. The process of assigning load addresses to the various
c) ƐR = Rɛ = R parts of the program and adjusting the code and data in
d) ØR = RØ = RR* the program to reflect the assigned addresses is called
a) Assembly
Answer: d b) Parsing
Explanation: Regular grammar combined with empty c) Relocation
does not give R* instead gives empty. d) Symbol resolute
8. Grammars that can be translated to DFAs :
a) Left linear grammar Answer: c
b) Right linear grammar Explanation: Relocation is the process of replacing
c) Generic grammar symbolic references or names of libraries with actual
d) All of the mentioned usable addresses in memory before running a program.
Linker performs it during compilation.
36
3. Which of the following statements is false? d) + has higher precedence than *
a) Left as well as right most derivations can be in
Unambiguous grammar Answer: b
b) An LL (1) parser is a top-down parser Explanation:Precedence is that a higher precedence
c) LALR is more powerful than SLR operator will never produce an expression with operator
d) Ambiguous grammar can’t be LR (k) with lower precedence.
In the given grammar MINUS has higher precedence
Answer: a than ASTERIX.
Explanation: If a grammar has more than one leftmost (or 7. Consider a program P that consists of two source
rightmost) derivation the grammar is ambiguous. modules M1(contains reference to a function defined in
Sometimes in unambiguous grammar the rightmost M2) and M2 contained in two different files.
derivation and leftmost derivations may differ. a) Edit time
4. Which of the following grammar rules violate the b) Compile time
requirements of an operator grammar? c) Link time
(i) P -> QR d) Load time
(ii) P -> QsR
(iii) P -> ε Answer : c
(iV) P -> QtRr Explanation:
a) (i) only Compiler transforms source code into the machine
b) (i) and (iii) only language which is in binary .
c) (ii) and (iii) only Kinds of object codes:
d) (iii) and (iv) only defined symbols, which allow it to be called by other
modules,
Answer: b ii undefined symbols, which call the other modules where
Explanation: these symbols are defined, and
An operator precedence parser is a bottom-up parser that iii symbols which are used internally within object file
interprets an operator-precedence grammar. for relocation.
Consider the grammar with the following translation 8. Which of the following suffices to convert an arbitrary
rules and E as the start symbol. CFG to an LL(1) grammar?
A -> A1 #B {A.value = A1.value * B.value} a) Removing left recursion only
| B {A.value = B.value} b) Factoring the grammar alone
B-> B1 & F {B.value = B1.value + C.value} c) Factoring & left recursion removal
|C {B.value= C.value } d) None of the mentioned
C -> num {C.value = num.value}.
5. Compute E.value for the root of the parse tree for the Answer: d
expression:2 # 3 & 5 # 6 &4. Explanation:
a) 200 Factoring as well as left recursion removal do not suffice
b) 180 to convert an arbitrary CFG to LL(1) grammar.
c) 160 9. Assume that the SLR parser for a grammar G has n1
d) 40 states and the LALR parser for G has n2 states.
a) n1 is necessarily less than n2
Answer: c b) n1 is necessarily equal to n2
Explanation:higher precedence operator will never c) n1 is necessarily greater than n2
produce an expression with operator with lower d) None of the mentioned
precedence.&># in terms of precedence order.
6. Given the following expression grammar: Answer: b
E -> E * F | F+E | F Explanation: SLR parser has less range of context free
F -> F-F | id languages than LALR but still both n1 & n2 are same for
which of the following is true? SLR & LALR respectively.
a) * has higher precedence than + 10. Match the following.
b) – has higher precedence than * P. Regular expression 1. Syntax analysis
c) + and — have same precedence Q. Pushdown automata 2. Code generation
R. Dataflow analysis 3. Lexical analysis
37
S. Register allocation 4. Code optimization 3. Which one of the following is a top-down parser?
a) P-4. Q-1, R-2, S-3 a) Recursive descent parser
b) P-3, Q-1, R-4, S-2 b) Operator precedence parser
c) P-3, Q-4, R-1, S-2 c) An LR(k) parser
d) P-2, Q-1, R-4, S-3 d) An LALR(k) parser
Answer: b Answer: a
Explanation: Explanation: Recursive Descent also known as top down
Syntax analysis has Regular expressions . The code parsing also known to be LL(1).
optimization goes hand in hand with data flow analysis. Consider the following two statements:
Whereas CFG is related to PDA which is related to P: Every regular grammar is LL(1)
syntax analysis Register allocation is used in reference Q:Regular is LR(1) grammar.
with code generation. 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
Top-Down Parsing-2 - d) Both P and Q are false
“Predictive Top-Down Parsing”.
1. Find the TRUE statement? Answer: c
I. There exist parsing algorithms for some programming Explanation: Ambiguity can be seen in regular grammar
languages which has O(3) complexity. S → aA/a
II. A programming language which allows recursion can A → aA/ε
be implemented In above grammar, string ‘a’ has two leftmost
with static storage allocation. derivations.
III. No L-attributed definition can be evaluated in The S → aA
framework S→a
of bottom-up parsing. S->a (using A->ε).
IV. Code improving transformations can be performed at 5. Consider the grammar defined by the following
both intermediate code level and source production rules
Language. S –> T * P
a) I and II T –> U | T * U
b) I and IV P –> Q + P | Q
c) III and IV Q –> Id
d) I III and IV U –> Id
S→F⎪H
/|\ 8. Consider the following grammar G.
F→p⎪c
E*F
|/|\
FF–F H→d⎪c
||| Which one is true?
id (3) id (4) id (5) S1: All strings generated by G can be parsed with help of
First ‘- ‘ is be evaluated then ‘ *’ LL (1).
5. Which one of the following is true at any valid state in S2: All strings generated by G can be parsed with help of
shift-reduce parsing? LR (1).
a) At the bottom we find the prefixes. a) Only S1
b) None of the mentioned b) Only S2
c) Stack contains only viable prefixes c) Both S1 S2
d) Stack consists of viable prefixes d) None of the mentioned
Answer: c Answer: d
Explanation: The prefixes on the stack of a shift-reduce Explanation: T ambiguity as the string can be derived in
parser are called viable prefixes. 2 possible ways.
6. In the context of abstract-syntax-tree and control-flow- First Leftmost Derivation
graph. S→F
Which one of the following is true? F→c
a) In both AST and CFG if node N2 be the successor of Second Leftmost Derivation
node N1. S→H
b) For any input program, neither AST nor CFG will H→c.
contain a cycle 9. What is the maximum number of reduce moves that
c) The max no. of successors of a node in an AST and a can be taken by a bottom-up parser for a grammar with
CFG depends on the input program no epsilon- and unit-production to parse a string with n
d) None of the mentioned tokens?
a) n/2
Answer: c b) n-1
Explanation: Successors depends on input . c) 2n-1
7. Match the following: d) 2^n
List-I List-II
A. Lexical analysis 1. Graph coloring Answer: b
B. Parsing 2. DFA minimization Explanation: the moves are n-1.
C. Register allocation 3. Post-order traversal 10. Consider the following two sets of LR (1) items of an
D. Expression evaluation 4. Production tree LR (1) grammar.
ABCD X -> c.X, c/d
(a) 2 3 1 4 X -> .cX, c/d
(b) 2 1 4 3 X -> .d, c/d
(c) 2 4 1 3 X -> c.X, $
(d) 2 3 4 1 X -> .cX, $
X -> .d, $
Answer: c Which one is false?
Explanation: The entire column an items matches the 1. Cannot be merged since look ahead’s are different.
Column B items in a certain way. 2. Can be merged but will result in S-R conflict.
7. Which of the following pairs is the most powerful? 3. Can be merged but will result in R-R conflict.
a) SLR, LALR 4. Cannot be merged since goto on c will lead to two
b) Canonical LR ,LALR
40
different sets. d) General Syntax Analysis
a) 1 only
b) 2 only Answer: b
c) 1 and 4 only Explanation: Conversion of characters to tokens.
d) 1, 2, 3 and 4 only 6. Relocating bits used by relocating loader are specified
by
Answer: d a) Relocating loader itself
Explanation: All these are valid reasons. b) Linker
c) Assembler
. d) Macro Processor
Answer: d Answer: b
Explanation: In computing, an optimizing compiler is a Explanation: Also known as shift reduce parser
compiler that tries to minimize or maximize some
attributes of an executable computer program .
5. The linker
a) Is similar to interpreter Handle of Right sentinel Grammar-1 -
b) Uses source code as its input “Handle of Right sentinel Grammar”.
c) I s required to create a load module 1. DAG representation of a basic block allows
d) None of the mentioned a) Automatic detection of local common sub expressions
b) Detection of induction variables
42
c) Automatic detection of loop variant 7. Shift reduce parsers are
d) None of the mentioned a) Top down parser
b) Bottom up parser
Answer: a c) Maybe both
Explanation: it detects local sub expression . d) None of the mentioned
2. Inherited attribute is a natural choice in
a) Tracking declaration of a variable Answer: b
b) Correct use of L and R values Explanation: This corresponds to starting at the leaves of
c) Both of the mentioned the parse tree. It can be thought of. A process of reducing
d) None of the mentioned the string in question to the start symbol of the grammar.
Bottom-up parsing is also known as shift-reduce parsing.
Answer: a 8. A bottom up parser generates
Explanation: These attribute keep a check on variable a) Right most derivation
declaration b) Right most derivation in reverse
3. An intermediate code form is c) Left most derivation
a) Postfix notation d) Left most derivation in reverse
b) Syntax Trees
c) Three Address code Answer: b
d) All of the mentioned Explanation: This corresponds to starting at the leaves of
the parse tree. It can be thought of. a process of reducing
Answer: d the string in question to the start symbol of the grammar.
Explanation: Intermediate code generator receives input Bottom-up parsing is also known as shift-reduce parsing.
from its predecessor phase, semantic analyzer, in the 9. A garbage is
form of an annotated syntax tree. a) Unallocated storage
4. Which of the following actions an operator precedence b) Allocated storage whose access paths are destroyed?
parser may take to recover from an error? c) Allocated storage
a) Insert symbols onto the stack d) Uninitialized storage
b) Delete symbols from the stack
c) Inserting or deleting symbols from the input Answer: b
d) All of the mentioned Explanation: these are more like memory loacations with
values whose pointers have been revoked
Answer: d 10. A optimizing compiler
Explanation: All these symbols are used to recover a) Is optimized to occupy less space
operator precedence parser from an error b) Is optimized to take less time for execution
5. The output of lexical analyzer is c) Optimized the code
a) A set of regular expression d) None of the mentioned
b) Syntax tress
c) Set of Token Answer: c
d) String of Characters Explanation: As the name suggests that it optimizes the
code
Answer: c
Explanation: lexical analysis is the process of converting .
a sequence of characters into a sequence of tokens
6. Which of the following is used for grouping of Compilers Online Test -
characters into tokens? This set of Compilers online test focuses on “Handle of
a) Parser Right Sentinel Grammar – 2”.
b) Code optimization 1. Input to code generator
c) Code generator a) Source code
d) Lexical analyser b) Intermediate code
c) Target code
Answer: d d) All of the mentioned
Explanation: lexical analysis is the process of converting
a sequence of characters into a sequence of tokens.
43
Answer: b Answer: c
Explanation: Intermediate code is the input to the code Explanation: the output of lexical analyzer is output
generator token
2. A synthesized attribute is an attribute whose value at a 7. _____________ is a graph representation of a
parse tree node depends on derivation
a) Attributes at the siblings only a) The parse tree
b) Attributes at parent node only b) Oct tree
c) Attributes at children nodes only c) Binary tree
d) None of the mentioned d) None of the mentioned
Answer: c Answer: a
Explanation: Synthesized attribute’s value depend on Explanation: parse tree is a representation of the
children node only derivation
3. In a bottom up evaluation of a syntax direction 8. Which of the following symbols table implementation
definition ,inherited attributes can is based on the property of locality of reference?
a) Always be evaluated a) Hash Table
b) Be evaluated only if the definition is L –attributed b) Search tree
c) Evaluation only done if the definition has synthesized c) Self organizing list
attributes d) Linear list
d) None of the mentioned
Answer: c
Answer: c Explanation: Self Organizing list is based on locality of
Explanation: Bottom-up parsing identifies and processes reference
the text’s lowest-level, before its mid-level structures, 9. Which one of the following is a top-down parser?
and the highest-level overall structure to last are left a) Recursive Descent parser
4. The graph that shows basic blocks and their successor b) Operator precedence parser
relationship is called c) An LR(k) parser
a) DAG d) An LALR(k) parser
b) Flow Chart
c) Control Graph Answer: a
d) Hamilton graph Explanation: Recursive Descent parsing is LL (1) parsing
which is top down parsing
Answer: b 10. Assume that the SLR parser for a grammar G has n1
Explanation: Flow chart shows basic blocks states and the LALR parser for G has n2 states. Hence
5. _________ or scanning is the process where the stream which one is true?
of characters making up the source program is read from a) N1 is necessarily less than n2
left to right and grouped into tokens. b) N1 is necessarily equal to n2
a) Lexical Analysis c) N1 is necessarily greater than n2
b) Diversion d) None of the mentioned
c) Modelling
d) None of the mentioned Answer: b
Explanation: the output of lexical analyzer is output
Answer: a token
Explanation: Lexical analysis is the process of converting
a sequence of characters into a sequence of tokens To practice all areas of Compilers for online tests, .
6. The output of a lexical analyzer is
a) Machine code LR Parser-1 -
b) Intermediate code “LR Parser”.
c) A stream of tokens 1. Which of these is also known as look-head LR parser?
d) A parse tree a) SLR
b) LR
c) LLR
44
d) None of the mentioned between shift and reduce hence it is called shift reduce
conflict
Answer: c 7. When t a reduce/reduce conflict?
Explanation: LLR is the look ahead parser. a) If a state does not know whether it will make a shift
2. What is the similarity between LR, LALR and SLR? operation using the production rule i or j for a terminal.
a) Use same algorithm, but different parsing table. b) If a state does not know whether it will make a shift or
b) Same parsing table, but different algorithm. reduction operation using the production rule i or j for a
c) Their Parsing tables and algorithm are similar but uses terminal.
top down approach. c) If a state does not know whether it will make a
d) Both Parsing tables and algorithm are different. reduction operation using the production rule i or j for a
terminal.
Answer: a d) None of the mentioned
Explanation: The common grounds of these 3 parser is
the algorithm but parsing table is different Answer: c
3. An LR-parser can detect a syntactic error as soon as Explanation: It occurs when If a state does not know
a) The parsing starts whether it will make a reduction operation using the
b) It is possible to do so a left-to-right scan of the input. production rule i or j for a terminal.
c) It is possible to do so a right-to-left scan of the input. 8. When ß ( in the LR(1) item A -> ß.a,a ) is not empty,
d) Parsing ends the look-head
a) Will be affecting.
Answer: b b) Does not have any affect.
Explanation: Error is found when it the input string is c) Shift will take place.
scanned d) Reduction will take place.
4. Which of these is true about LR parsing?
a) Is most general non-backtracking shift-reduce parsing Answer: b
b) It is still efficient Explanation: T no terminal before the non terminal beta
c) Both a and b 9. When ß is empty (A -> ß.,a ), the reduction by A-> a is
d) None of the mentioned done
a) If next symbol is a terminal
Answer: c b) Only If the next input symbol is a
Explanation: LR parsers are a type of bottom-up parsers c) Only If the next input symbol is A
that efficiently handle deterministic context-free d) Only if the next input symbol is a
languages in guaranteed linear time.
5. Which of the following is incorrect for the actions of A Answer: d
LR-Parser I) shift s ii) reduce A->ß iii) Accept iv) reject? Explanation: the next token is considered in this case it’s
a) Only I) a
b) I) and ii) 10. The construction of the canonical collection of the
c) I), ii) and iii) sets of LR (1) items are similar to the construction of the
d) I), ii) , iii) and iv) canonical collection of the sets of LR (0) items. Which is
an exception?
Answer: c a) Closure and goto operations work a little bit different
Explanation: Only reject out of the following is a correct b) Closure and goto operations work similarly
LR parser action c) Closure and additive operations work a little bit
6. If a state does not know whether it will make a shift different
operation or reduction for a terminal is called d) Closure and associatively operations work a little bit
a) Shift/reduce conflict different
b) Reduce /shift conflict
c) Shift conflict Answer: a
d) Reduce conflict Explanation: closure and goto do work differently in case
of LR (0) and LR (1)
Answer: a
Explanation: as the name suggests that the conflict is .
45
LR Parser-2 - 5. A series of statements explaining how the data is to be
“LR Parser – 2”. processed is called
1. Terminal table a) Assembly
a) Contains all constants in the program b) Machine
b) Is a permanent table of decision rules in the form of c) COBOL
patterns for matching with the uniform symbol table to d) Program
discover syntactic structure?
c) Consist of a full or partial list of the token is as they Answer: d
appear in the program created by lexical analysis and Explanation: A program is a sequence of instructions,
used for syntax analysis and interpretation written to perform a task by computer. It requires
d) Is a permanent table which lists all keywords and programs to function, typically executing the program’s
special symbols of the language in symbolic form? instructions in a central processor.
6. A loader is a program that
Answer: d a) Program that places functions into memory and
Explanation: A permanent database that has entry for prepares them for execution
each terminal symbols such as arithmetic operators, b) Program that automates the translation of assembly
keywords, punctuation characters such as ‘;’, ‘,’etc language into machine language
Fields: Name of the symbol. c) Program accepting another program written in a high
2. Advantage of incorporating the macro-processor into level language and produces as object program
pass 1 is that d) None of the mentioned
a) Many functions have to be implemented twice
b) Functions are combined not necessarily creating Answer: a
intermediate files as output from the macro-processor and Explanation: A loader is the part of an operating system
input to the assembler that is responsible for loading programs and libraries. It
c) More flexibility is provided to the programmer in that is important in the process of placing the programs into
he may use all the features of the assembler in memory and executing them.
conjunction with macros 7. A system program that setup an executable program in
d) All of the mentioned main memory ready for execution is
a) Assembler
Answer: d b) Linker
Explanation: A general-purpose macro processor or c) Loader
general purpose pre-processor is a macro …designed d) Load and go
primarily for string manipulation, macro definition
3. Which of the following is a phase of a compilation Answer: c
process? Explanation: a loader is the part of an operating system
a) Lexical Analysis that is responsible for loading programs and libraries. It
b) Code Generation is one of the essential stages in the process of starting a
c) Both of the mentioned program, as it places programs into memory and prepares
d) None of the mentioned them for execution
8. Which of the following system program forgoes the
Answer: c production of object code to generate absolute machine
Explanation: Lexical analysis and code generation is a code and load it into the physical main storage location
phase of compilation process from which it will be executed immediately upon
4. System program such a s compiler are designed so that completion of the assembly?
they are a) Two pass assembler
a) Re-enterable b) Load and go assembler
b) Non reusable c) Macro processor
c) Serially usable d) Linker
d) None of the mentioned
Answer: b
Answer: a Explanation: A load and go assembler generates absolute
Explanation: Re-enterable is the keyword for compiler machine code and loads it to physical memory
being designed
46
9. Uniform symbol table 3. A system program that set-up an executable program
a) Has all constants in the program in main memory ready for execution is
b) Permanent table of rules in the form of patterns for a) Assembler
matching with the uniform symbol table to discover b) Linker
syntactic structure c) Loader
c) Consists of full or partial list of the tokens as they d) Text editor
appear in the program created by Lexical analysis and
used for syntax analysis and interpretation Answer: c
d) A permanent table which has all key words and special Explanation: A loader is the part of an operating system
symbols of the language in symbolic form that is responsible for loading programs and libraries. It
is important that with the starting of a program, as it
Answer: c places programs into memory and executes it.
Explanation: Each pass scans the program, the first pass 4. A compiler is a program that
generates the symbol table and the second pass generates a) Program is put into memory and executes it.
the machine code. b) Translation of assembly language into machine
10. Assembler is a program that language.
a) Puts programs into memory and executes them c) Acceptance of a program written in a high level
b) Translates the assembly language into machine language and produces an object program.
language d) None of the mentioned
c) Writes in high level language and produces an object
program Answer: c
d) None of the mentioned Explanation: A compiler is a computer program (or set of
programs) that transforms source code written in a
Answer: b programming language (the source language) into
Explanation: An assembler is a program that takes basic another computer language (the target language, often
computer instructions and converts them into a pattern of having a binary form known as object code).
bits that the computer’s processor can use to perform its 5. A programmer by mistake writes multiplication
basic operations. instead of division, such error can be detected by a/an
a) Compiler
. b) Interpreter
c) Compiler or interpreter test
Data Structure for Representing Parsing Table-1 - d) None of the mentioned
“Data Structure for Representing Parsing Table”.
1. Compiler can diagnose Answer: d
a) Grammatical errors only Explanation: No Logical errors can be detected
b) Logical errors only 6. The computer language generally translated to
c) Grammatical and logical errors pseudocode is
d) None of the mentioned a) Assembly
b) Machine
Answer: a c) Pascal
Explanation: Only syntactical errors can be detected by d) FORTRAN
the compiler.
2. A simple two-pass assembler does which of the Answer: a
following in the first pass. Explanation: An assembly language (or assembler
a) It allocates space for the literals language) is a low-level programming language for a
b) Calculates total length of the program computer, or other programmable device, in which t a
c) Symbol table is built for the symbols and their value very strong (generally one-to-one) correspondence
d) All of the mentioned between the language and the architecture’s machine
code instructions.
Answer: d 7. A system program that combines separately compiled
Explanation: a two-pass assembler. Each pass scans the modules of a program into a form suitable for execution
program, the first pass generates the symbol table and the is
second pass generates the machine code… a) Assembler
47
b) Linking Loader 1. The symbol table implementation is based on the
c) Cross Compiler property of locality of reference is
d) None of the mentioned a) Linear List
b) Search Tree
Answer: b c) Hash table
Explanation: A loader which combines the functions of a d) Self Organization
relocating loader with the ability to combine a number of
program segments that have been independently Answer: c
compiled into an executable program. Explanation: a hash table (hash map) is a data structure
8. In which way a macro processor for assembly used to implement an associative array. A hash table uses
language can be implemented? a hash function to compute an index into an array, from
a) Independent two-pass processor which the correct value can be found.
b) Independent one-pass processor 2. In operator precedence parsing whose precedence
c) Processor put into pass 1 of a standard two pass relations are defined
assembler a) For all pair of non-terminals
d) All of the mentioned b) For all pair of terminals
c) To delimit the handle
Answer: d d) None of the mentioned
Explanation: A general-purpose macro processor or
general purpose preprocessor is a macro …designed for Answer: a
string manipulation, macro definition Explanation: There are two important properties for these
9. Resolution of externally defined symbols is performed operator precedence parsers is that it does not appear on
by the right side of any production and no production has
a) Linker two adjacent no terminals.
b) Loader 3. LR parsers are attractive because
c) Compiler a) It can be constructed to recognize CFG corresponding
d) Interpreter to almost all programming constructs
b) It does not backtrack
Answer: a c) Both of the mentioned
Explanation: a linker or link editor is a computer program d) None of the mentioned
that takes one or more object files generated by a
compiler and combines them into a single executable file, Answer: c
library file, or another object file. Explanation: These above mentioned are the reasons why
10. A shift reduce parser carries out the actions specified LR parser is considered to be attractive
within braces immediately after reducing with the 4. The most powerful parser is
corresponding rule of grammar S—-> xxW ( PRINT “1”) a) SLR
S—-> y { print ” 2 ” } S—-> Sz { print ” 3 ” ) What is b) LALR
the translation of xxxxyzz using the syntax directed c) Canonical LR
translation scheme described by the above rules ? d) Operator Precedence
a) 23131
b) 11233 Answer: c
c) 11231 Explanation: The most powerful parser is Canonical LR
d) 33211 5. Yacc Builds up
a) SLR parsing Table
Answer: a b) Canonical LR parsing Table
Explanation: initially 2 is printed then 3 then 1 3 1 c) LALR parsing Table
d) None of the mentioned
.
Answer: c
Compilers Quiz Online - Explanation: Yacc provides a general tool for describing
This set of Compilers online quiz focuses on “Data the input to a computer program.
Structure for Representing Parsing Table – 2”. 6. Object program is a
a) Program written in machine language
48
b) Translated into machine language
c) Translation of high-level language into machine To practice all areas of Compilers for online Quizzes, .
language
d) None of the mentioned
Syntax-Directed Definitions and Translations-1 -
Answer: c “Regular Grammar”.
Explanation: A computer program when from the 1. In a single pass assembler, most of the forward
equivalent source program into machine language by the references can be avoided by putting the restriction
compiler or assembler. a) On the number of strings/life reacts
7. ( Z,* ) be a structure, and * is defined by n * m b) Code segment to be defined after data segment
=maximum ( n , m ) Which of the following statements is c) On unconditional rump
true for ( Z, * ) ? d) None of the mentioned
a) ( Z,* ) is a monoid
b) ( Z,* ) is an algebraic group Answer: b
c) ( Z,* ) is a group Explanation: A single pass assembler scans the program
d) None of the mentioned only once and creates the equivalent binary program.
2. The method which merges the bodies of two loops is
Answer: d a) Loop rolling
Explanation: It is neither a monoid nor a simple group b) Loop jamming
nor algebraic group c) Constant folding
8. The address code involves d) None of the mentioned
a) Exactly 3 address
b) At most Three address Answer: b
c) No unary operators Explanation: In computer science, loop fusion (or loop
d) None of the mentioned jamming) is a compiler optimization and loop
transformation which replaces multiple loops with a
Answer: d single one.
Explanation: In computer science, three-address is an 3. Assembly code data base is associated with
intermediate code used by optimizing compilers to aid in a) Code is converted into assembly.
the implementation of code-improving transformations. b) Table of rules in the form of patterns for matching
9. An intermediate code form is with the uniform symbol table to discover syntactic
a) Postfix Notation structure.
b) Syntax Trees c) Both of the mentioned
c) Three address code d) None of the mentioned
d) All of the mentioned
Answer: a
Answer: d Explanation: An assembly language is a low-level
Explanation: Intermediate code generator takes an input programming language for a computer, or other
from its predecessor phase, semantic analyzer, in the programmable device, in which t a very strong (generally
form of an annotated syntax tree. one-to-one) correspondence between the language and
10. Relocating bits used by relocating loader are the architecture’s machine code instructions
specified by 4. The process manager has to keep track of
a) Relocating loader itself a) Status of each program
b) Linker b) Information to a programmer using the system
c) Assembler c) Both of the mentioned
d) Macro Processor d) None of the mentioned
Answer: b Answer: c
Explanation: A linker or link editor is a computer Explanation: Process manager keep track of the status
program that takes one or more object files generated by and info about the program
a compiler and combines them into a single executable 5. Function of the syntax phase is to
file, library file, or another object file. a) recognize the language and to cal the appropriate
action routines that will generate the intermediate form or
49
matrix for these constructs 10. The root directory of a disk should be placed
b) Build a literal table and an identifier table a) At a fixed address in main memory
c) Build a uniform symbol table b) At a fixed location on the disk
d) Parse the source program into the basic elements or c) Anywhere on the disk
tokens of the language d) None of the mentioned
Answer: a Answer: b
Explanation: In this phase symbol table is created by the Explanation: Root directory is placed at a fixed disk
compiler which contains the list of lexemes or tokens. location
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) Syntax-Directed Definitions and Translations-2 -
c) E (αf +β g )=α E (f+gβ) “Regular Grammar”.
d) E (αf +β g )=αβ E (f + g) 1. The segment base is specified using the register named
is
Answer: a a) ORG instructions
Explanation: Shifting operation when performed gives b) TITLE instruction
this result c) ASSUME instruction
7. Pass I d) SEGMENT instruction
a) Assign address to all statements
b) Save the values assigned to all labels for use in pass 2 Answer: a
c) Perform some processing Explanation: ORG segment base register is used to
d) All of the mentioned specify the register
2. In what module multiple instances of execution will
Answer: d yield the same result even if one instance has not
Explanation: The pass 1 of a compiler the above terminated before the next one has begun?
mentioned functions are performed a) Non usable module
8. Which table is a permanent database that has an entry b) Serially usable
for each terminal symbol? c) Re-enter-able
a) Terminal Table d) None of the mentioned
b) Literal Table
c) Identifier Table Answer: C
d) None of the mentioned Explanation: Re enter-able module is the reason why the
compiler is used in the first place.
Answer: a 3. Dividing a project into segments and smaller units in
Explanation: A database that has entry for each terminal order to simplify design and programming efforts is
symbols such as arithmetic operators, keywords, called
punctuation characters such as ‘;’, ‘,’etc Fields: Name of a) Modular approach
the symbol. b) Top down approach
9. Which of the following functions is performed by c) Bottom up approach
loader? d) Left right approach
a) Allocate memory for the programs and resolve
symbolic references between objects decks Answer: a
b) Address dependent locations, such as address Explanation: Modular design, or “modularity in design”,
constants, to correspond to the allocated space is a design approach that subdivides a system into smaller
c) Physically place the machine instructions and data into parts called modules or skids that can be independently
memory created and then used in different systems.
d) All of the mentioned 4. Which one of the following is the tightest upper bound
that represents the time complexity of inserting an object
Answer: d into a binary search tree of n nodes?
Explanation: a loader is the part of an operating system a) O(1)
that is responsible for loading programs and libraries. b) O(long)
50
c) O(n) Answer: b
d) O(long) Explanation: In computer science, and specifically in
compiler and assembler design, literal pool is a lookup
Answer: c table used to hold literals during assembly and execution.
Explanation: For skewed binary search tree on n nodes, 9. Which loader function is accomplished by loader?
the upper bound to insert a node is O (n) a) Reallocation
5. Which of the following is true for machine language? b) Allocation
a) Continuous execution of program segments c) Linking
b) Depicting flow of data in a system d) Loading
c) A sequence of instructions which solves a problem
d) The language which interacts with the computer using Answer: d
only the binary digits 1 and 0 Explanation: Function of a loader
Answer: d .
Explanation: Machine code or machine language is a set
of instructions executed directly by a computer’s central Implementation of the Translation Specified by
processing unit (CPU). Each instruction performs a very Syntax-Directed Definitions -1 -
specific task. “Implementation of the Translation Specified by Syntax-
6. Software that measures, monitors, and controls events Directed Definitions “.
is 1. Which is not true about syntax and semantic parts of a
a) System S/w computer language?
b) Real Time software a) Semantics is checked mechanically by a computer
c) Scientific software b) Semantics is the responsibility of the programmer
d) Business Software c) Both of the mentioned
d) None of the mentioned
Answer: b
Explanation: In computer science, real-time computing Answer: d
(RTC), or reactive computing describes hardware and Explanation: Both in terms of semantics is not true.
software systems subject to a “real-time constraint”, for 2. Which of the following statement is true?
example operational deadlines from event to system a) SLR powerful than LALR
response. b) LALR powerful than Canonical LR parser
7. A linker is given object module for a set of programs c) Canonical LR powerful than LALR parser
that were compiled separately. What is not true about an d) The parsers SLR= Canonical LR=LALR
object module
a) Object code Answer: c
b) Relocation bits Explanation: LR >LALR>SLR In terms of parser
c) Names and locations of all external symbols denied in 3. Which of the following features cannot be captured by
the object module CFG ?
d) Absolute addresses of internal symbols a) Syntax of if-then-else statements
b) Syntax of recursive procedures
Answer: d c) A variable is declared before its use
Explanation: a linker or link editor is a computer program d) Matching nested parenthesis
that takes one or more object files generated by a
compiler and combines them into a single executable file, Answer: d
library file, or another object file. Explanation: It is because, it is equivalent to recognizing
8. The table created by lexical analysis to describe all us, where the first w is the declaration and the second is
literals used in the source program is its use, we are not a CFG.
a) Terminal table 4. In which of the following no information hiding is
b) Literal table done?
c) Identifier table a) Compile prig 1, prig 2
d) Reductions b) Run test, prog
c) Load R1 , A
51
d) 001001000010101 b) Necessary to translate the users program
c) It is very difficult to handle multiple segments, even
Answer: d when the source programs are in different languages and
Explanation: The entire binary symbol gives the to produce orderly modular programs
information d) All of the mentioned
5. The identification of common sub-expression and
replacement of run-time computations by compile-time Answer: d
computations is Explanation: In computer programming, a compile and
a) Local optimization go system, compile, load, and go system, assemble and
b) Loop optimization go system, or load and go system[1][2][3] is a
c) Constant folding programming language processor in which the
d) Data flow analysis compilation, assembly, or link steps are not separated
from program execution.
Answer: c 10. Function of the storage assignment is
Explanation: Constant folding is the process of a) Assign storage to all variables referenced in the source
recognizing and evaluating constant expressions at program
compile time rather than computing them at runtime. b) Assign storage to all temporary locations that are
Terms in constant expressions are typically simple necessary for intermediate results
literals they may also be variables whose values are c) Assign storage to literals, and to ensure that the storage
assigned at compile time. is allocated and appropriate locations are initialized
6. The graph that shows basic blocks and their successor d) All of the mentioned
relationship is called
a) Dag Answer: d
b) Flow Graph Explanation: the storage assignment performs the above
c) Control Graph mentioned tasks
d) Hamilton Graph
.
Answer: b
Explanation: Flow graph shows the basic blocks Compilers Question Bank -
7. The specific task storage manager performs This set of Compilers Question Bank focuses on
a) Allocation/ deal location of programs “Implementation of the Translation Specified by Syntax
b) Protection of storage area assigned to the program – Directed Definitions and Translations – 2”.
c) Both of the mentioned 1. A non relocatable program is the one which
d) None of the mentioned a) Cannot execute in any area of storage other than the
one designated
Answer: c b) Consists of a program and information for its
Explanation: its basic function is that of the task storage relocation
manager c) None of the mentioned
8. When a computer is rebooted, a special type of loader d) All of the mentioned
is executed called
a) Compile and GO ” loader Answer: a
b) Boot loader Explanation: A non reloadable program is one which
c) Bootstrap Loader cannot be made to execute in any area of storage other
d) Relating Loader than the one designated for it at the time of its coding or
translation.
Answer: c 2. A relocatable program form is one which
Explanation: A boot loader, is a small program that a) Cannot execute in any area of storage other than the
places the operating system (OS) of a computer into one designated
memory b) Consists of a program and information for its
9. Disadvantage of ” Compile and GO ” loading scheme relocation
is that c) None of the mentioned
a) Memory is wasted because the case occupied by the d) All of the mentioned
assembler is unavailable to the object program
52
Answer: c 7. Generation of intermediate code based on a abstract
Explanation: A relocatable program form is one which machine model is useful in compilers because
consists of a program and relevant information for its a) Implementation of lexical analysis and syntax analysis
relocation. Using this information it is possible to is made easier
relocate the program to execute from a storage area then b) Writing for intermediate code generation
the one designated for it at the time of its coding or c) Portability of the front end of the compiler
translation. d) None of the mentioned
3. A self-relocating program is one which
a) Cannot execute in any area of storage other than the Answer: a
one designated Explanation: Intermediate code generator receives input
b) Consists of a program and information for its from its predecessor phase, semantic analyzer, in the
relocation form of an annotated syntax tree.
c) None of the mentioned 8. Which of the following module does not incorporate
d) All of the mentioned initialization of values changed by the module?
a) Non reusable module
Answer: c b) Serially reusable module
Explanation: A self-relocating program is a program c) Re-enterable module
which can perform the relocation itself d) All of the mentioned
•A table of information about address sensitive
instruction in the program. Answer: a
•Relocating logic that can perform the relocation of the Explanation: Non reusable models can be used once for a
address sensitive instructions purpose they can’t be modified and used again
4. Scissoring enables 9. An intermediate code form is
a) A part of data to be displayed a) Postfix Notation
b) Entire data to be displayed b) Syntax Trees
c) Full data display on full screen c) Three address
d) No data to be displayed d) All of the mentioned
Answer: a Answer: d
Explanation: It displays a part of the data Explanation: all the specified options are type of
5. Which of the following can be accessed by transfer intermediate code form
vector approach of linking? 10. The best way to compare the different
a) External data segments implementations of symbol table is to compare the time
b) External sub-routines required to
c) Data located in other procedure a) Add a new name
d) All of the mentioned b) Make an enquiry
c) Add a new name and make an enquiry
Answer: b d) All of the mentioned
Explanation: External subroutines are routines that are
created and maintained separately from the program that Answer: d
will be calling them Explanation: These are the different implementations of
6. Relocation bits used by relocating loader are specified the symbol table as mentioned above.
by
a) Relocating loader itself To practice Compilers Question Bank, .
b) Linker
c) Assembler L-Attributed Definition-1 -
d) Macro processor “L-Attributed Definition”.
1. Dynamic linking can cause security concerns because
Answer: b a) Security is dynamic
Explanation: A linker or link editor is a computer b) None of the mentioned
program that takes one or more object files generated by c) Both of the mentioned
a compiler and combines them into a single executable d) Cryptographic procedures are not available for
file, library file, or another object file.
53
dynamic linking 6. If dynamic scoping is used and call by name
mechanism is used, the values printed will be
Answer: d a) 115, 220
Explanation: required by the program are linked during b) 25, 220
run time. c) 25, 15
2. Which of the following statements is FALSE? d) 115, 105
a) Both of the mentioned
b) In up-typed languages, values do not have any types Answer: b
c) Dynamic languages have no variables types Explanation Since x = i + j & in P (x) i = 200 & j = 20 x
d) None of the mentioned = 200 + 20 = 220 & printing (x + 10) 9. = i + j + 10 = 10
+ 5 + 10 = 25
Answer: c 7. P x =new Q();
Explanation: they have dynamically changing types. Q y =new Q();
3. S -> C C P z =new Q();
C -> eC | d x. f (1);((P) y). f (1);
The grammar is z.f(1);
a) LL (1) The output is
b) SLR (1) but not LL (1) a) 1 2 1
c) LALR (1) but not SLR (1) b) 2 1 1
d) LR (1) but not LALR (1) c) 2 1 2
d) 2 2 2
Answer: c
Explanation: Answer:d
The grammar is CLR and can be reduced to LALR Explanation:
4. S -> id: = E ” 1. Px = newQ();
newtemp (); 2. Qy = newQ();
gen(t . place . place;); .place t} ” 3. Pz = newQ();
.place .place;} 4. x : f(1);
For the statement ‘X: = Y + Z ’, print 2 # i = 2 5. ((P) y) :f(1);
the 3-address code sequence generated by this definition 6. z : f(1) print 2 # i = 2
is but line 5. will print 2 because typecast to parent class
a) X = Y + Z can’t prevent over ridding.
b) t1 = Y + Z; X t1 8. Which of the following is NOT an advantage of using
c) t1 = Y; t2 = t1 + Z; X = t2 shared, dynamically linked libraries as compared to
d) t1 = Y; t2 = Z; t3 + t2; X = t3 statically linked libraries?
a) Smaller sizes of executable
Answer: d b) Lesser overall page fault rate in the system
Explanation: c) Faster program start-up
In 3-address code we use temporary variables d) Existing programs need not be re-linked to take
5. If the programming language uses static scoping and advantage of newer versions of libraries
call by need parameter passing mechanism, the values
printed by the above program are Answer: c
a) 115, 220 Explanation: No need for re-linking if newer versions of
b) 25, 220 libraries are there.
c) 25, 15 9. Which grammar violate rules of an operator grammar?
d) 115, 105 (i) P-> QR
(ii) P -> Q s R
Answer: d (iii) P -> ε
Explanation: (iv) P ->Q t
So i = 100 & j = 5 P (i + j) = P (100 + 5) = P(105) So x = a) (i) only
105 x + 10 = 105 + 10 = 115 So 115 & 105 will be b) (i) and (iii) only
printed. c) (ii) and (iii) only
54
d) (iii) and (iv) only Answer: b
Explanation:The no. of states for SLR(1) & LALR(1) are
Answer: b equal so n 1 = n3, but CLR(1) or LR(1) will have no. of
Explanation: (I) P ” QR is not possible since two NT states greater than LALR & LR(0) both.
should include one operator as Terminal. 4. Consider line 3
10. Consider the grammar rule Int main()
E -> E1 − E2 for arithmetic expressions. { int 1,N;
If E1 and E2 do not have any common sub expression, in Fro (I,1 N,1);
order to get the shortest possible code }
a) E1 should be evaluated first Identify the compiler’s response about this line while
b) E2 should be evaluated first creating the object-module
c) Evaluation of E1 and E2 should necessarily be a) No compilation error
interleaved b) Only a lexical error
d) Order of evaluation of E1 and E2 is of no consequence c) Only syntactic errors
d) Both lexical and syntactic errors
Answer: b
Explanation: E1 is to be kept in accumulator & Answer: c
accumulator is required for operations to evaluate E2. Explanation: There are no lexical errors for C because all
the wrong spelled keywords
. 5. Which one of the following is true about the action of
yacc for the given grammar?
L-Attributed Definition-2 - a) It detects recursion and eliminates recursion
“L-Attributed Definition”. b) It detects reduce-reduce conflict, and resolves
1. The grammar A ->AA |( A)| ε c) It detects shift-reduce conflict, and resolves the
is not suitable for predictive-parsing because the conflict in favor of a shift over a reduce action
grammar is d) It detects shift-reduce conflict, and resolves the
a) Ambiguous conflict in favor of a reduce over a shift action
b) Left-recursive
c) Right-recursive Answer: c
d) An operator-grammar Explanation: Yacc tool is used to create a LALR(1)
parser.
Answer: a 6. What precedence and associativity properties does the
Explanation: The grammar is ambiguous. generated parser realize?
2. Consider the grammar a) Equal precedence and left associativity; expression is
E ->E + n | E # n | n evaluated to 7
For a sentence n + n, form of the reduction are b) Equal precedence and right associativity, expression is
a) n, E + n and E + n # n evaluated to 9
b) n , E + n and E + E # n c) Precedence of ‘x’ is higher than that of ‘+’, and both
c) n , n + n and n + n # n operators are left associative; expression is evaluated to 7
d) n , E + n and E # n d) Precedence of ‘ # ‘ is higher than that of ‘#’, and both
operators are left associative; expression is evaluated to 9
Answer: d
Explanation: during reduction the order is reverse. So {E Answer: b
” n , E ” E + n, E ” E # n} Explanation:The grammar has equal precedence and it is
3. S -> (S)| a also ambiguous.
Let the number of states in SLR(1), LR(1) and LALR(1) 7. Consider the following grammar.
parsers for the grammar n1 n2 and n3 respectively. S-> S * E
a) n1 < n2 < n3 S -> E
b) n1 = n3 < n2 E -> F + E
c) n1 = n2 = n3 E -> F
d) n1 $ n3 $ n2 F -> id
Consider the following LR(0) items corresponding to the
grammar above
55
(i) S -> S * .E b) T scope of common sub-expression elimination in this
(ii) E -> F . + E code
(iii) E -> F + .E c) T scope strength reduction in this code
Given the items above, which two of them will appear in d) T scope of dead code elimination in this code
the same set in the canonical sets-of-items for the
grammar? Answer: d
a) (i) and (ii) Explanation: All the statements are true except option
b) (ii) and (iii) last since t no dead code to get eliminated.
c) (i) and (iii)
d) None of these .
Answer: d Answer: d
Explanation: No specified execution time. Explanation: Others are HLL
2. Parsing is also known as 8. In a two pass assembler the object code generation is
a) Lexical analysis done during the
b) Syntax analysis a) Second pass
c) Semantic analysis b) First pass
d) Code generation c) Zeroth pass
d) Not done by assembler
Answer: b
Explanation: Another name for parsing is Syntax Answer: a
Analysis Explanation: I second pass object code is generated.
3. The linker 9. A programming language is to be designed to run on a
a) Is same as the loader machine that does not have a big memory.
b) Create a load module a) Prefer a 2 pass compiler
c) Both of the mentioned b) Prefer an interpreter
d) None of the mentioned c) Not support recursion
d) All of the mentioned
Answer: b
Explanation: It creates a module to be loaded Answer : d
4. Predictive parsers can be Explanation: If a language designed to run on a machine
a) Recursive then recursion should not be followed it should prefer 2
b) Constructive pass assembler and prefer an interpreter to a compiler.
c) Non recursive 10. Which of the following system software resides in
d) Both a and b main memory always?
a) Text editor
Answer: a b) Assembler
Explanation: The nature of predictive parsers can be c) Linker
Recursive d) Loader
5. Producer consumer problem can be solved using
a) Semaphores Answer: d
b) Event counters Explanation: It loads function and libraries.
c) Monitors
d) All of the mentioned .
63
Answer: a y=4;
Explanation: b will be one because when value of ais 1 it z = ++x * y++;
is stored .. a) 4
2. What value does the variable a have after ALL of the b) 5
code above executes? c) 6
int a; d) unknown/undefined
int b;
a=1; Answer: b
b=a++; Explanation: the value of y is increased by 1 and
a) 1 becomes 5..
b) 2 6. What will be the output of the following program?
c) 3 #include
d) unknown/undefined int main()
{
Answer: b int i = 10;
Explanation: a=2 cause it has been incremented. printf(“%d”, ++(-i));
3. What value does the variable z have after ALL of the return 0;
code above executes? }
int x; a) 11
int y; b) 10
int z; c) -9
x=3; d) None of the mentioned
y=4;
z = ++x * y++; Answer: d
a) 9 Explanation: The expression ++(-i) is not valid but –(++i)
b) 12 is valid.
c) 16 7. #include
d) 20 int main()
{
Answer: c int x=4, y, z;
Explanation: z=4* 4 y = –x;
Hence the answer will be 16. z = x–;
4. What value does the variable x have after ALL of the printf(“%d, %d, %d\n”, x, y, z);
code above executes? return 0;
int x; }
int y; a) 4,3,3
int z; b) 3,3,3
x=3; c) 2,3,3
y=4; d) 4,4,3
z = ++x * y++;
a) 2 Answer: c
b) 3 Explanation: y = 3 and z= 3 but
c) 4 x has decremented and become 2.
d) unknown/undefined 8. #include
main()
Answer: c {
Explanation: Finally the value of x is 4. int a=1, b=3;
5. What value does the variable y have after ALL of the b= a++ + a++ + a++ + a++ + a++;
code above executes? printf(“a=%d \n b=%d”,a,b);
int x; }
int y; a) a = 6, b = 15
int z; b) a =1 , b = 3
x=3; c) a = 1 , b =15
64
d) a = 2 , b = 4 c) Logical Operators
d) Arithmetic Operators
Answer: a
Explanation: Answer: d
B=1+2+3+4+5 Explanation: No other operator has higher precedence
B=15 than arithmetic operator
But finally a=6 2. Which of the following operators has the highest
9. #include precedence?
main() a) Unary +
{ b) *
int a=9, b=9; c) >=
a=b++; d) ==
b=a++;
b=++b; Answer: a
printf(“%d %d”,a,b); Explanation: unary operators have max precedence in
} over all other arithmetic operators
a) 9,9 3. If i=1 j=2,k=3, then what is the value of the expression
b) 10,10 !((j + k) > (i + 5))
c) 9,10 a) 6
d) 10,9 b) 5
c) 1
Answer: b d) 0
Explanation:
A=9 Answer: c
B=9 Explanation: !((2+3)>(1+5))
B=10 !(5>6)
10. #include Since the condition is false hence !(0)
main() And complement of 0 is 1.
{ int a,b; 4. The expression 5 – 2 – 3 * 5 – 2 will evaluate to 18, if
b = 10; – is left associative and
a = ++b + ++b; a) * has precedence over *
printf(“%d%d”,a,b); b) * has precedence over –
} c) – has precedence over *
a) 24,12 d) – has precedence over –
b) 23,12
c) 23,10 Answer: c
d) 24,10 Explanation: if – has precedence over* and if it
associates from the right
Answer: b 5. Coercion
Explanation: a) Takes place over an assignment operator
A = 11+12 b) Operator has operands of various types
So a=23 c) None of the mentioned
B=12 d) Both of the mentioned
. Answer: d
Explanation: conversion between compatible types
Compilers Aptitude Test - 6. Choose the correct statement
This set of Compilers for Aptitude test focuses on a) Expressions evaluated at compile time
“Implementation of Increment and Decrement – 2”. b) String constants concatenated at compile time
1. In C programming language, which of the following c) None of the mentioned
type of operators have the highest precedence d) Both of the mentioned
a) Relational Operators
b) Equality Operators
65
Answer: d d) Programmer-Defined
Explanation: The statements are true
7. Which of the following operators takes only integer Answer: b
operands ? Explanation: The indexing in an array starts with zero
a) + hence we can say that the element
b) * 3. Which of the following is a two-dimensional array?
c) / a) array array[20][20]
d) % b) int array[20][20]
c) int array[20, 20]
Answer: d d) char array[20]
Explanation: Two integers are taken to be input
8. Pick the operators that associate from the left Answer: b
a) + Explanation: Double dimensional arrays are declared in
b) , this format
c) < 4. Which of the following correctly accesses the seventh
d) All of the mentioned element stored in tan?
a) tan[6]
Answer: d b) tan[7]
Explanation: They are left associative c) tan(7)
9. Pick the operators that associate from the right d) tan
a) ?:
b) += Answer: a
c) = Explanation: The index no 6.
d) All of the mentioned 5. Which of the following gives the memory address of
the first element in array tan?
Answer: d a) tan[0]
Explanation: They are right associative b) tan
10. Pick the operators that associate from left to right c) &tan
a) && d) tan [1]
b) ?:
c) , Answer: b
d) All of the mentioned Explanation: the base address of the array is given by its
name.
Answer: d 6. What will happen if in a C program you assign a value
Explanation: They left to right associative to an array element whose subscript exceeds the size of
array?
To practice all areas of Compilers for Aptitude test, . a) The compiler would report an error
b) May stop working abruptly if data gets overwritten
Array Reference-1 - c) None of the mentioned
“Array Reference”. d) The element will be set to 0
1. Which of the following correctly declares an array?
a) Int array[ 10] Answer: b
b) int array Explanation: it often happens that the program crashes.
c) array{10} 7. What does the following declaration mean? int (*a)
d) array array[ 10] [10] a is
a) Pointer to an array
Answer: a b) None of the mentioned
Explanation: Correct declaration. c) Array of 10 integers
2. What is the index number of the last element of an d) Both of the mentioned
array with 29 elements?
a) 29 Answer: a
b) 28 Explanation: points to array.
c) 0
66
8. What is the meaning of following declaration? void main(){
Int arr[20] char arr[7]=”Network”;
a) Integer Array of size 20 printf(“%s”,arr);
b) None of the mentioned }
c) Array of size 20 a) Network
d) Array of size 20 that can have higher integer address b) N
c) network
Answer: a d) Garbage Value
Explanation: Declaration of an array
9. int a[20] Answer: d
What will be the size of above array elements? Explanation: garbage value is printed
a) 21 4. What will be output ?
b) 22 #include
c) 20 void main(){
d) 19 char arr[11]=”The African Queen”;
printf(“%s”,arr);
Answer: c a) The African Queen
Explanation: The number in square brackets denotes size b) The
of an array c) Queen
10. What is meaning of the following? d) Null
Int *ptr[20]
a) Interger array of size 20 pointing to an integer Pointer Answer: d
b) None of the mentioned Explanation:it gives a Null Value.
c) Array of integer pointer of size 20 5. What will be output if you will execute following c
d) Both of the mentioned code?
#include
Answer: c void main(){
Explanation: Array of pointers to integers char arr[20]=”MysticRiver”;
printf(“%d”,sizeof(arr));
. a) 20
b) 11
Array Reference-2 - c) 30
“Array Reference”. d) None of the mentioned
1. In which way can SAM be stored in an array
a) char name[]=”SAM” Answer: a
b) char name[6]={‘S’,’A’,’M’} Explanation: The size of array is 20
c) char name[6]={“S”,”A”,”M”} 6. What will be output if you will execute following c
d) char name [6]={‘S’,’A’,’M’,’\0’} code?
#include
Answer: d void main(){
Explanation: The array consists of the word SAM and int const SIZE=5;
also a NULL character. int expr;
2. Int RollNUm[30[4] is a double value[SIZE]={2.0,4.0,6.0,8.0,10.0};
a) 1-d Array expr=1|2|3|4;
b) 3-D Array printf(“%f”,value[expr]);
c) 4- D Array }
d) 2-D Array a) 2.00000
b) 4.00000
Answer: d c) 6.00000
Explanation: 2 [] brackets means a double dimensional d) Compilation error
array.
3. What will be output ? Answer: d
#include Explanation: No fixed value in [] brackets.
67
7. Comment on the following statement: Switch Case-1 -
int (*a)[7]; “Switch Case”.
a) An array “a” of pointers. 1. Select the output for following set of code.
b) A pointer “a” to an array. static void Main(string[] args)
c) A ragged array. {int movie = 1;
d) None of the mentioned switch (movie << 2 + movie)
{
Answer: b default:
Explanation: it is a pointer to array a Console.WriteLine(“A”);
8. Comment on the 2 arrays regarding P and Q: break;
int *a1[8]; case 4:
int *(a3[8]); Console.WriteLine(“B”);
P. Array of pointers break;
Q. Pointer to an array case 5:
a) a1 is P, a2 is Q Console.WriteLine(“C”);
b) a1 is P, a2 is P break;
c) a1 is Q, a2 is P case 8:
d) a1 is Q, a2 is Q Console.WriteLine(“D”);
break;
Answer: b }
Explanation: p =a1 Console.ReadLine();
And a3 is alo p }
8. Which of the following is not possible statically in C? a) A
a) Jagged Array b) B
b) Rectangular Array c) C
c) Cuboidal Array d) D
d) Multidimensional Array
Answer: c
Answer: a Explanation: ‘default’ case can be put in anywhere.
Explanation: Jagged array is not possible. Output: D.
9. What is the max no. of dimensions an array may have 2. Select the output for following set of code :
a) 2 static void Main(string[] args)
b) 8 {int i = 2, j = 4;
c) 20 switch (i + j * 2)
d) No limit {
case 1 :
Answer: d case 2 :
Explanation : Dimension of an array can be any number. Console.WriteLine(“1 and 2”);
10. Array passed as an argument to a function is break;
interpreted as case 3 to 10:
a) Address of the array Console.WriteLine(“3 to 10”);
b) None of the mentioned break;
c) Base address }
d) No. of elements of the array. Console.ReadLine();
}
Answer: c a) 3 to 10 will be printed
Explanation: The base address is passed when the array is b) 1 and 2 will be printed
passed as an argument in a function. c) error
d) The code gives output as 3 to 10
Answer: c
. Explanation:
Output :
68
static void Main(string[] args) {
{ case p:
int i = 2,j = 4; Console.WriteLine(“A”);
switch (i + j * 2) break;
{ case p * 1:
case 1 : Console.WriteLine(“B”);
case 2 : break;
Console.WriteLine(“1 and 2″); case p – 2:
break; Console.WriteLine(“C”);
case 3 : break;
Console.WriteLine(“3 to 10″); default:
break; Console.WriteLine(“D”);
} }
Console.ReadLine(); }
} a) A
Here i = 2,j = 4. b) B
3. Select the output for following set of code : c) C
static void Main(string[] args) d) Compile time error
{
int i = 2, k = 3; Answer: d
switch (i – k) Explanation: No constant variable.
{ 5. Select output for following set of code :
case -1: static void Main(string[] args)
++i; {
++k; int i = 2, j = 3, k = 4;
break; switch (i + j – k)
case 2: {
–i; case 0: case 2: case 4:
++k; ++i;
break; k += j;
default: break;
i += 3; case 1: case 3: case 5 :
k += i; –i;
break; k -= j;
} break;
Console.WriteLine(i + “\n” + k); default:
Console.ReadLine(); i += j;
} break;
a) 2 3 3 }
b) 3 2 3 Console.WriteLine(i + “\n” + j + “\n” + k);
c) 3 4 4 Console.ReadLine();
d) 5 10 10 }
a) 1 3 1
Answer: c b) 2 3 4
Output: 3 c) 5 3 4
4 d) Compile time error
4
Explanation: i – k = -1.So, case -1 will be executed only . Answer: a
4. Select output for following set of code : Explanation: Solving expression gives 1
static void Main(string[] args) Output : 1
{ 3
int const p = 0; 1
switch (3 * 5 / 6)
69
6. Select the output for following set of code : {
static void Main(string[] args) int i;
{ int j = 1;
int i = 9 , j = 7; int []ar = {21, 22, 13, 4};
switch (i – j + 3) switch (ar[j])
{ {
case 9: 7: case 1:
j += 6; i++;
break; break;
case 5: case 2:
i -= 4; i += 2;
break; j = 3;
} continue;
Console.WriteLine(i + “\n” + j); case 3:
Console.ReadLine(); i %= 2;
} j = 4;
a) 5 7 continue;
b) 9 13 default:
c) Compile time error –i;
d) 9 7 }
Console.WriteLine(i);
Answer: c Console.ReadLine();
Explanation: Invalid expression. }
7. Select the output for code : a) 23
static void Main(string[] args) b) 15
{ c) Compile time error
switch (5) d) 12
{
case 5.0f: Answer: c
Console.WriteLine(“harsh”); Explanation: Continue cannot be used.
break; Output :
case 5: static void Main(string[] args)
Console.WriteLine(“amish”); {
break; int i;
case 5.0L: int j = 1;
Console.WriteLine(“ANKIT”); int []ar = {21 , 22, 13, };
break; switch(ar[j])
default: {
Console.WriteLine(“ashish”); case 1:
} i++;
Console.ReadLine(); break;
} case 2:
a) amish i += 2;
b) ANKIT j = 3;
c) harsh continue;
d) Compile time error case 3:
i %= 2;
Answer: d j = 4;
Explanation: Only integers are allowed . default:
5.0f = (int)5.0f. –i;
5.0L =(int)5.0L. }
8. Select output for code: Console.WriteLine(i);
static void Main(string[] args)
70
Console.ReadLine(); Answer: c
} Explanation: ASCII value of p is 112.
9. Select the output for following set of Code: Output: coco 112 main.
static void Main(string[] args)
{ .
char ch = Convert.ToChar(‘a’ | ‘b’ | ‘c’);
switch (ch) Switch Case-2 -
{ “Switch Case”.
case ‘A’: 1. How many times will the following loop be executed?
case ‘a’: ch = ‘b’;
Console.WriteLine(“case A|case a”); while(ch >= ‘a’ && ch <= ‘z’)
break; a) 0
case ‘B’: b) 25
case ‘b’: c) 26
Console.WriteLine(“case B|case b”); d) 1
break;
case ‘C’: Answer: b
case ‘c’: Explanation: Because there are 26 alphabets and so it
case ‘D’: runs for 26-1 times
case ‘d’: 2. Consider the following program
Console.WriteLine(“case D|case d”); switch(input)
break; {
} case ‘1’:
Console.ReadLine(); printf(“One”);
} case ‘2’:
a) Compile time error printf(“Two”);
b) case A | case a case ‘3’:
c) case B | case b printf(“”Three”);
d) case D | case d default:
Printf(“Default”);
Answer: d break;
Explanation: case D|case d }
10. Select the output for following set of Code: What will be printed when input is 2?
static void Main(string[] args) a) Two Three default
{ b) Two
char ch = ‘p’; c) Two default
switch (ch) d) Two Two default
{
case ‘p’: Answer: a
Console.WriteLine(“coco” + “\t” + Explanation: because in between cases t no break
Convert.ToInt32(ch)); statement
break; 3. The advantage of ‘switch’ statement over ‘if’ is that it
default: leads to more structured program.
Console.WriteLine(“default”); a) True
break; b) False
}
Console.WriteLine(“main”); Answer: a
} Explanation: switch is more convenient to use as it
a) coco main avoids confusion in case of more nested structure
b) coco 112 4. Consider the following C program
c) coco 112 main #include
d) compile time error int main()
{
71
int a=7, b=5; d) 4
switch(a = a % b)
{ Answer: a
case 1: Explanation: infinite times it runs.
a = a – b; 8. An if statement may contain compound statements
case 2: only in the else clause
a = a + b; a) True
case 3: b) False
a = a * b;
case 4: Answer: b
a = a / b; Explanation: if can also have compound statements
default: 9. A ‘while’ loop may always be converted to an
a = a; equivalent ‘for’ loop
} a) True
return 0; b) False
}
Value of a? Answer: a
a) 7 Explanation: Can be converted to for loop
b) 5 10. Default’ case is mandatory in a switch statement
c) Both of the mentioned a) True
d) None of the mentioned b) False
Answer: a Answer: b
Explanation: Initially a=a%b gives 2.then in case 2 Explanation: Default cases may or may not be written.
a=a+b gives 2+5=7 .hence a=7
5. The statement for(;;) is perfectly valid C statement .
a) True
b) False Symbol Table Management-1 -
“Symbol Table Management”.
Answer: b 1. Which phase of compiler is Syntax Analysis
Explanation: Infinite loop a) First
6. void main() b) Second
{ c) Third
static a,b; d) None of the mentioned
while(a > b++)
} Answer: b
What is the output? Explanation: It is Second Phase Of Compiler after
a) a=0 b=0 Lexical Analyzer.
b) a=0 b=0 2. What is Syntax Analyser also known as
c) a=1 b=1 a) Hierarchical Analysis
d) None of the mentioned b) Hierarchical Parsing
c) None of the mentioned
Answer: a d) Both of the mentioned
Explanation: Static variables have an initial value 0
7. for(digit = 0;digit < 9; digit++) Answer: d
{ Explanation: It is also called as Hierarchical Analysis or
digit = digit *2; Parsing.
digit–; 3. Syntax Analyser takes Groups Tokens of source
} Program into Grammatical Production
No . of times the loop will run. a) True
a) Infinite b) False
b) 9
c) 0
72
Answer: a d) Not Logical and Syntax Error
Explanation: It Groups Tokens of source Program into
Grammatical Production Answer: b
4. From where it take its input from? Explanation: No compiler can ever check logical errors
a) Lexical analyser 10. The fourth Generation computer was made up of?
b) Syntactic Analyser a) Transistor
c) Semantic Analyser b) Vacuum tubes
d) None of the mentioned c) Chips
d) Microprocessor chips
Answer: a
Explanation: A syntax analyzer or parser takes the input Answer: d
from a lexical analyzer in the form of token streams. Explanation: It is the only way to increase its throughput
5. Parsers are expected to parse the whole code
a) True .
b) False
Symbol Table Management-2 -
Answer: a “Symbol Table Management”.
Explanation: Parsers are expected to parse the whole 1. Select a Machine Independent phase of the compiler
code even if some errors exist in the program. a) Syntax Analysis
6. A grammar for a programming language is a formal b) Intermediate Code generation
description of c) Lexical Analysis
a) Syntax d) All of the mentioned
b) Semantics
c) Structure Answer: d
d) Library Explanation: All of them work independent of a machine
2. A system program that combines the separately
Answer: c compiled modules of a program into a form suitable for
Explanation: The grammar clearly indicates that which execution?
type of a structure does a program has. a) Assembler
7. Which of these is not true about Symbol Table? b) Compiler
a) All the labels of the instructions are symbols c) Linking Loader
b) Table has entry for symbol name address value d) Interpreter
c) Perform the processing of the assembler directives
d) Created during pass 1 Answer: c
Explanation: A loader which combines the functions of a
Answer: c relocating loader with the ability to combine a number of
Explanation: The Symbol table does not ever perform the program segments that have been independently
processing of the assembler derivative compiled
8. Which of these features of assembler are Machine- 3. Which of the following system software resides in the
Dependent main memory always
a) Instruction formats a) Text Editor
b) Addressing modes b) Assembler
c) Program relocation c) Linker
d) All of the mentioned d) Loader
Answer: d Answer: d
Explanation: All of these options are features of Explanation: Loader is used to loading programs.
assembler which are machine dependent 4. Output file of Lex is _____ the input file is Myfile?
9. A compiler can check? a) Myfile.e
a) Logical Error b) Myfile.yy.c
b) Syntax Error c) Myfile.lex
c) Both Logical and Syntax Error d) Myfile.obj
73
Answer: b Answer: d
Explanation: This Produce the file “myfile.yy.c” which Explanation: Maintaining the Symbol Table for each
we can then compile with g++ block. Source Program for Semantic Errors. Collects
5. Type checking is normally done during? Type Information for Code Generation. Reporting
a) Lexical Analysis compile-time errors in the code generating the object
b) Syntax Analysis code (e.g., assembler or intermediate code)
c) Syntax Directed Translation
d) Code generation .
Answer: a Answer: a
Explanation: Syntax analyzer does not check the type of Explanation: Accumulator is the process register.
the operand. 2. A group of bits that tell the computer to perform a
7. In Short Syntax Analysis Generates Parse Tree specific operation is known as____
a) True a) Instruction code
b) False b) Micro-operation
c) Accumulator
Answer: a d) Register
Explanation: Short Syntax Analysis generates a parse tree
8. By whom is the symbol table created? Answer: a
a) Compiler Explanation: Instruction code is the set of specific tasks
b) Interpreter to be performed
c) Assembler 3. The time interval between adjacent bits is called
d) None of the mentioned the_____
a) Word-time
Answer: a b) Bit-time
Explanation: symbol table is created by the compiler c) Turnaround time
which contains the list of lexemes or tokens. d) Slice time
9. What does a Syntactic Analyzer do?
a) Maintain Symbol Table Answer: b
b) Collect type of information Explanation: Bit time is the interval time here
c) Create parse tree 4. A k-bit field can specify any one of_____
d) None of the mentioned a) 3k registers
b) 2k registers
Answer: c c) K2 registers
Explanation: Syntax analyzer will just create parse tree. d) K3 registers
Semantic Analyzer checks the meaning of the string
parsed. Answer: b
10. Semantic Analyzer is used for? Explanation: 2k is the answer
a) Generating Object code 5. MIMD stands for _____
b) Main ting symbol table a) Multiple instruction multiple data
c) None of the mentioned b) Multiple instruction memory data
d) Both of the mentioned c) Memory instruction multiple data
74
d) Multiple information memory data
Runtime Storage Location-2 -
Answer: a “Runtime Storage Location”.
Explanation: MIMD stands for multiple instructions 1. The instruction ‘ORG O’ is a______
multiple data a) Machine Instruction
6. Logic gates with a set of input and outputs are b) Pseudo instruction
arrangement of______ c) High level instruction
a) Computational circuit d) Memory instruction
b) Logic circuit
c) Design circuits Answer: b
d) Register Explanation: It is a pseudo instruction
2. ‘Aging registers’ are _______
Answer: a a) Counters which indicate how long ago their associated
Explanation: The answer is computational circuit pages have been Referenced.
7. The average time required to reach a storage location b) Registers which keep track of when the program was
in memory and obtain its contents is called_____ last accessed
a) Latency time c) Counters to keep track of last accessed instruction
b) Access time d) Counters to keep track of the latest data structures
c) Turnaround time referred
d) Response time
Answer: a
Answer: b Explanation:This is known as aging
Explanation: Access time is the time from the start of one 3. Memory unit accessed by content is called______
storage device access to the time when the next access a) Read only memory
can be started. b) Programmable Memory
8. The BSA instruction is______ c) Virtual Memory
a) Branch and store accumulator d) Associative Memory
b) Branch and save return address
c) Branch and shift address Answer: d
d) Branch and show accumulator Explanation: Associative Emory is accessed by content
4. _________ register keeps tracks of the instructions
Answer: b stored in program stored in memory.
Explanation: BSA is branch and save return address a) AR (Address Register)
9. A floating point number that has an O in the MSB of b) XR (Index Register)
mantissa is said to have_____ c) PC (Program Counter)
a) Overflow d) AC (Accumulator)
b) Underflow
c) Important number Answer: c
d) Undefined Explanation: program counter keeps a track
5. N bits in operation code imply that there are
Answer: b ___________ possible distinctOperators.
Explanation: It is an underflow condition. a) 2n
10. Translation from symbolic program into Binary is b) 2n
done in_____ c) n/2
a) Two passes d) n2
b) Directly
c) Three passes Answer: b
d) Four passes Explanation: 2n possible combinations
6. A three input NOR gate gives logic high output only
Answer: a when_____
Explanation: two passes are required a) One input is high
b) One input is low
. c) Two input are low
75
d) All input are high Answer: d
Explanation: it is made up of cache memory and RAM.
Answer: d 2. Cache memory works on the principle of_____
Explanation: all inputs are high a) Locality of data .
7. The circuit converting binary data in to decimal b) Locality of memory
is_____ c) Locality of reference
a) Encoder d) Locality of reference & memory
b) Multiplexer
c) Decoder Answer: c
d) Code converter Explanation: Cache works on Locality of reference
3. An n-bit microprocessor has_____
Answer: d a) n-bit program counter
Explanation: It is the code converter b) n-bit address register
8. The multiplicand register & multiplier register of a c) n-bit ALU
hardware circuit implementing booth’s algorithm have d) n-bit instruction register
(11101) & (1100). The result shall be ______
a) (812)10 Answer: d
b) (-12)10 Explanation: N bit microprocessor has bit instruction
c) (12)10 register
d) (-812)10 4. When CPU is executing a Program that is part of the
Operating System, it is said to be in _____
Answer: a a) Interrupt mode
Explanation: on multiplying we get 81210 b) System mode
9. PSW is saved in stack when t a _____ c) Half mode
a) Interrupt recognized d) Simplex mode
b) Execution of RST instruction
c) Execution of CALL instruction Answer: b
d) All of these Explanation: It is in System Mode
5. Logic X-OR operation of (4ACO) H & (B53F) H
Answer: a results _____
Explanation: It can be interrupted a) AACB
10. In computers, subtraction is carried out generally b) 0000
by____ c) FFFF
a) 1’s complement method d) ABCD
b) 2’s complement method
c) signed magnitude method Answer: c
d) BCD subtraction method Explanation: Xoring the two operands we get FFFF
6. If the main memory is of 8K bytes and the cache
Answer: b memory is of 2K words. It uses associative mapping.
Explanation: subtraction done by 2’s complement Then each word of cache memory shall be_____
a) 11 bits
. b) 21 bits
c) 16 bits
Symbol Table Organization-1 - d) 20 bits
” Symbol Table Organization”.
1. The main memory in a Personal Computer (PC) is Answer: c
made of_____ Explanation: Each should be 8*2=16 bits
a) Cache memory. 7. A Stack-organised Computer uses instruction of _____
b) Static RAM a) Indirect addressing
c) Dynamic Ram b) Two-addressing
d) Both of the mentioned c) Zero addressing
d) Index addressing
76
Answer: c Answer: d
Explanation: Zero addressing modes are used in stack Explanation: The answer is cache memory
organised computer. 3. Cache memory acts between_______
8. In a program using subroutine call instruction, it is a) CPU and RAM
necessary______ b) RAM and ROM
a) Initialize program counter c) CPU and Hard Disk
b) Clear the accumulator d) None of the mentioned
c) Reset the microprocessor
d) Clear the instruction register Answer: a
Explanation: it acts between CPU and RAM
Answer: d 4. The circuit used to store one bit of data is known as
Explanation: It is mandatory to clear the instruction ______
register a) Encoder
9. Virtual memory consists of _______ b) OR gate
a) Static RAM c) Flip Flop
b) Dynamic RAM d) Decoder
c) Magnetic memory
d) None of the mentioned Answer: c
Explanation: Flip flop is 1 bit circuit
Answer: a 5. Von Neumann architecture is ______
Explanation: It does consist of static RAM a) SISD
10. In signed-magnitude binary division, if the dividend b) SIMD
is (11100)2 and divisor is (10011)2 then the result is c) MIMD
______ d) MISD
a) (00100)2
b) (10100)2 Answer: a
c) (11001)2 Explanation: It is single instruction single data
d) (01100)2 6. In a vectored interrupt.
a) The branch address is assigned to a fixed location in
Answer: b memory
Explanation: After division we get 20 which is 10100 b) The interrupting source supplies the branch
information to the processor through an interrupt vector
. c) The branch address is obtained from a register in the
processor
Compilers Assessment Questions - d) None of the mentioned
This set of Compilers Assessment focuses on “Symbol
Table Organization – 2”. Answer: b
1. Generally Dynamic RAM is used as main memory in a Explanation: It branches to process the interrupt
computer system as it______ 7. In a memory-mapped I/O system, which of the
a) Consumes less power following will not be there?
b) Has higher speed a) LDA
c) Has lower cell density b) IN
d) Needs refreshing circuitry c) ADD
d) OUT
Answer: b
Explanation: Because of higher speed it is Dynamic Answer: a
2. Write Through technique is used in which memory for Explanation: T no LDA
updating the data _____ 8. If memory access takes 20 ns with cache and 110 ns
a) Virtual memory without it, then the ratio (cache uses a 10 ns memory) is
b) Main memory _____
c) Auxiliary memory a) 93%
d) Cache memory b) 90%
c) 88%
77
d) 87% Answer: C
Explanation:Times used to access the contents
Answer: b 4. (2FAOC) 16 is equivalent to _____
Explanation:The answer is 90% a) (195 084)10
9. The addressing mode used in an instruction of the form b) (001011111010 0000 1100)2
ADD X Y, is _____ c) Both of the mentioned
a) Absolute d) None of the mentioned
b) Indirect
c) Index Answer: B
d) None of the mentioned Explanation:It is equivalent to (001011111010 0000
1100)2
Answer: c 5. The circuit used to store one bit of data is known
Explanation: This addressing mode is indexed as_______
10. _________ register keeps track of the instructions a) Register
stored in program stored in memory. b) Encoder
a) AR (Address Register) c) Decoder
b) XR (Index Register) d) Flip Flop
c) PC (Program Counter)
d) AC (Accumulator) Answer: D
Explanation:1 bit circuit is known as Flip Flop
Answer: c 6. Computers use addressing mode techniques for
Explanation: Program Counter keeps track of the next ____________
instruction a) Giving programming versatility to the user by
providing facilities as pointers to memory counters for
To practice all areas of Compilers Assessment Questions, loop control
. b) To reduce no. of bits in the field of instruction
c) Specifying rules for modifying or interpreting address
Storage Allocation-1 - field of the instruction
“Storage Allocation”. d) All of the mentioned
1. The idea of cache memory is based ______
a) On the property of locality of reference Answer: D
b) On the heuristic 90-10 rule Explanation: All of these are addressing mode techniques
c) On the fact that references generally tend to cluster 7. What characteristic of RAM memory makes it not
d) All of the mentioned suitable for permanent storage?
a) Too slow
Answer: A b) Unreliable
Explanation:Cache memory is based on locality of c) It is volatile
references. d) Too bulky
2. Which of the following is not a weighted code?
a) Decimal Number system Answer: C
b) Excess 3-cod Explanation: Ram is volatile
c) Binary number System 8. The amount of time required to read a block of data
d) None of the mentioned from a disk into memory is composed of seek time,
rotational latency, and transfer time. Rotational latency
Answer: B refers to ______
Explanation:Excess 3 is not a weighted code a) The time it takes for the platter to make a full rotation
3. The average time required to reach a storage location b) The time it takes for the read-write head to move into
in memory and obtain its contents is called the _____ position over the appropriate track
a) Seek time c) The time it takes for the platter to rotate the correct
b) Turnaround time sector under the head
c) Access time d) None of the mentioned
d) Transfer time
78
Answer: A c) Includes many processing units under the supervision
Explanation:Rotational latency is the time taken to make of a common control unit
full rotation d) None of the mentioned
9. In computers, subtraction is generally carried out by
______ Answer: C
a) 9’s complement Explanation: SIMD includes processing units under the
b) 10’s complement super vision of a common control
c) 1’s complement 4. In Reverse Polish notation, expression A*B+C*D is
d) 2’s complement written as
Answer: a) AB*CD*+
Answer: D b) A*BCD*+
Explanation:Subtraction is done by 2’s complement c) AB*CD+*
10. Assembly language ________ d) A*B*CD+
a) Uses alphabetic codes in place of binary numbers used
in machine language Answer: A
b) Is the easiest language to write programs Explanation: RPN is AB*CD*+
c) Need not be translated into machine language 5. _________ register keeps tracks of the instructions
d) None of the mentioned stored in program stored in memory.
a) AR (Address Register)
Answer: A b) XR (Index Register)
Explanation:Uses binary numbers in machine language c) PC (Program Counter)
d) AC (Accumulator)
.
Answer: C
Storage Allocation-2 - Explanation: program counter keeps a track
“Storage Allocation”. 6. A three input NOR gate gives logic high output only
1. Suppose that a bus has 16 data lines and requires 4 when_____
cycles of 250 nests each to transfer data. The bandwidth a) One input is high
of this bus would be 2 Megabytes/sec. If the cycle time b) One input is low
of the bus was reduced to 125 nsecs and the number of c) Two input are low
cycles required for transfer stayed the same what would d) All input are high
the bandwidth of the bus?
a) 1 Megabyte/sec Answer: D
b) 4 Megabytes/sec Explanation: all inputs are high
c) 8 Megabytes/sec 7. The circuit converting binary data in to decimal
d) 2 Megabytes/sec is_____
a) Encoder
Answer: D b) Multiplexer
Explanation:The bandwidth is 2 mb/s c) Decoder
2. Floating point representation is used to store ______ d) Code converter
a) Boolean values
b) Whole numbers Answer: D
c) Real integers Explanation: It is the code converter
d) Integers 8. The multiplicand register & multiplier register of a
hardware circuit implementing booth’s algorithm have
Answer: C (11101) & (1100). The result shall be ______
Explanation:They are real Integers a) (812)10
3. SIMD represents an organization that b) (-12)10
______________ c) (12)10
a) Refers to a computer system capable of processing d) (-812)10
several programs at the same time
b) Represents organization of single computer containing Answer: A
a control unit, processor unit and a memory unit Explanation: on multiplying we get 81210
79
9. PSW is saved in stack when t a _____ c) 3
a) Interrupt recognized d) 4
b) Execution of RST instruction
c) Execution of CALL instruction Answer: b
d) All of the mentioned Explanation: 2
4. The number of states in DFA that accepts the language
Answer: A L(M) ∩ L(N) is ________
Explanation: It can be interrupted a) 0
10. In computers, subtraction is carried out generally b) 1
by____ c) 2
a) 1’s complement method d) 3
b) 2’s complement method
c) signed magnitude method Answer: B
d) BCD subtraction method Explanation: In DFA M: all strings must end with ‘a’. In
DFA N: all strings must end with ‘b’. So the intersection
Answer: B is empty. For an empty language, only one state is
Explanation: subtraction done by 2’s complement needed.
5. Consider alphabet ∑ = {0, 1}, the null/empty string λ
. and the sets of strings X0, X1 and X0.How are X1 and
X2 are related ?
Activation of the Procedure and the Activation X0 = 1 X1
Record-1 - X1 = 0 X1 + 1 X2
“Activation of the Procedure and the Activation X2 = 0 X1 + {λ}
Record”. Which one of the following represents the strings in X0?
1. Given an arbitrary non-deterministic finite automaton a) 10 (0* + (10)*)1
(NFA) with N states, the maximum number of states in b) 10 (0* + (10)*)*1
an equivalent minimized DFA is at least c) 10 (0* + (10)*)*1
a) N^2 d) 10 (0 + 10)*1 + 110 (0 + 10)*1
b) 2^N
c) 2N Answer: c
d) N! Explanation: The smallest possible string by given
grammar is “11”.
Answer: b X0 = 1X1
Explanation: if the NFA has n states, the resulting DFA = 11X2 [Replacing X1 with 1X2] = 11 [Replacing X2
may have up to 2n states, an exponentially larger number, with λ] The string “11” is only possible with option (C).
Answer: d Answer: a
Explanation: There are two states. When first state is Explanation: L3 is simple to guess, it is regular.
final, it accepts even no. of a’s. When second state is 7. The reorganizing capability of NDFA and DFA
final, it accepts odd no. of a’s. a) May be diffent
3. How many minimum states are required to find b) Must be different
whether a string has odd number of 0’s or not? c) Must be same
a) 1
b) 2
80
d) None of the mentioned 3. The set of all strings over ∑ ={a,b} in which a single a
is followed by any number of b’s a single b followed by
Answer: c any number of a’s is
Explanation: Given any NDFA one can construct an a) ab* + ba*
equivalent DFA b) ab*ba*
8. Which of the following is not regular? c) a*b + b*a
a) String whose length is perfect square and consists of d) None of the mentioned
0s
b) Palindromes consisting of 0’s and 1’s Answer: a
c) Both of the mentioned Explanation: ab*+ba* is the expression in which which a
d) None of the mentioned single a is followed by any number of b’s a single b
followed by any number of a’s
Answer: c 4. Regular expressions are used to represent which
Explanation: Strings of odd numbers of zeros can be language
generated by regular expression (00)*0. a) Recursive language
9. Which of the following pairs of regular expression are b) Context free language
equivalent? c) Regular language
a) 1(01)* and (10)*1 d) All of the mentioned
b) X(xx)* and (xx)*x
c) None of the mentioned Answer: c
d) Both of the mentioned Explanation: Regular expression is represented by
regular language
Answer: D 5. The set of all strings over ∑ = {a,b} in which strings
Explanation: R1 and R2 are reverse of each other. If ant consisting a’s and b’s and ending with in bb is
one of them can be generated them the other can be a) ab
generated as well. b) a*bbb
c) (a+b)* bb
. d) All of the mentioned
81
8. Regular expression a/b denotes the set b) False
a) {a}
b) {ab} Answer: a
c) {a,b} Explanation: It Groups Tokens of source Program into
d) None of the mentioned Grammatical Production
4. From where it take its input from?
Answer: c a) Lexical analyser
Explanation: Because it would give either a or b b) Syntactic Analyser
9. Which of the following regular expression denotes c) Semantic Analyser
zero or more instances of an a or b? d) None of the mentioned
a) a/b
b) (a/b)* Answer: a
c) (ab)* Explanation: A syntax analyzer or parser takes the input
d) A*Ib from a lexical analyzer in the form of token streams.
5. Parsers are expected to parse the whole code
Answer: b a) True
Explanation: this expression gives o or more instances of b) False
a or b .
10. The string (a)|((b)*(c)) is equivalent to Answer: a
a) Empty Explanation: Parsers are expected to parse the whole
b) abcabc code even if some errors exist in the program.
c) b*c|a 6. A grammar for a programming language is a formal
d) None of the mentioned description of
a) Syntax
Answer: c b) Semantics
Explanation: Either b or a can lead followed by c this c) Structure
expression can be achieved by C as well. d) Library
Answer: d Answer: d
Explanation: It is also called as Hierarchical Analysis or Explanation: All of these options are features of
Parsing. assembler which are machine Dependant
3. Syntax Analyser takes Groups Tokens of source 9. A compiler can check?
Program into Grammatical Production a) Logical Error
a) True b) Syntax Error
82
c) Both Logical and Syntax Error d) Myfile.obj
d) Not Logical and Syntax Error
Answer: b
Answer: b Explanation: This Produce the filr “myfile.yy.c” which
Explanation: No compiler can ever check logical errors we can then compile with g++
10. The fourth Generation computer was made up of? 5. Type checking is normally done during?
a) Transistor a) Lexical Analysis
b) Vacuum tubes b) Syntax Analysis
c) Chips c) Syntax Directed Translation
d) Microprocessor chips d) Code generation
Answer: d Answer: c
Explanation: It is the only way to increase its throughput 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
Static Allocation-2 - whether there are two operands associated with ‘+’ or not
“Static Allocation”. .
1. Select a Machine Independent phase of the compiler a) True
a) Syntax Analysis b) False
b) Intermediate Code generation
c) Lexical Analysis Answer: a
d) All of the mentioned Explanation: Syntax analyser does not check the type of
the operand.
Answer: d 7. In Short Syntax Analysis Generates Parse Tree
Explanation: All of them work independent of a machine a) True
2. A system program that combines the separately b) False
compiled modules of a program into a form suitable for
execution? Answer: a
a) Assembler Explanation: Short Syntax Analysis generates a parse tree
b) Compiler 8. By whom is the symbol table created?
c) Linking Loader a) Compiler
d) Interpreter b) Interpreter
c) Assembler
Answer: c d) None of the mentioned
Explanation: A loader which combines the functions of a
relocating loader with the ability to combine a number of Answer: a
program segments that have been independently Explanation: symbol table is created by the compiler
compiled which contains the list of lexemes or tokens.
3. Which of the following system software resides in the 9. What does a Syntactic Analyser do?
main memory always a) Mainting Symbol Table
a) Text Editor b) Collect type of information
b) Assembler c) Create parse tree
c) Linker d) None of the mentioned
d) Loader
Answer: c
Answer: d Explanation: Syntax analyzer will just create parse tree.
Explanation: Loader is used to loading programs. Semantic Analyzer checks the meaning of the string
4. Output file of Lex is _____ the input file is Myfile? parsed.
a) Myfile.e 10. Semantic Analyser is used for?
b) Myfile.yy.c a) Generating Object code
c) Myfile.lex b) Main ting symbol table
c) None of the mentioned
83
d) Both of the mentioned like * and / and that ^ associates to the right. Choose the
correct for the ordered pairs (^,^) , (-,-) , (+,+) , (*,*) in
Answer: d the operator precedence table constructed for the
Explanation: Maintaining the Symbol Table for each grammar
block. Source Program for Semantic Errors. Collects a) All < b) All >
Type Information for Code Generation. Reporting c) < > , =
compile-time errors in the code generating the object d) < > > >
code (e.g., assembler or intermediate code)
Answer: d
. Explanation: This relation is established of basis of the
precedence of operators
Stack Allocation-1 - 5. Recursively enumerable languages are not closed
“Stack Allocation”. under
1. Assume the statements S1 and S2 given as : a) Union
S1 : Given a context free grammar, there exists an b) Intersection
algorithm for determining whether L(G) is infinite. c) Complementation
S2 : There exists an algorithm to determine whether two d) Concatenation
context free grammars generate the same language.
Which of the following is true ? Answer: c
a) S1 is correct and S2 is not correct. Explanation: Recursive languages are closed under the
b) Both S1 and S2 are correct. following operations
c) Both S1 and S2 are not correct. the Kleene star L * of L
d) S1 is not correct and S2 is correct. the concatenation L * o P of L and P
the union L U P
Answer: a the intersection L ∩ P
Explanation: The proof of S1 can be seen in various book 6. Grammar that produce more than one Parse tree for
of theory of computation but s2 is a problem of category same sentence is
undecidable so a contradiction to this assumption can be a) Ambiguous
easily obtained. b) Unambiguous
2. If P & R are regular and also given that if PQ=R, then c) Complementation
a) Q has to be regular d) Concatenation Intersection
b) Q cannot be regular
c) Q need not be regular Answer: a
d) Q has to be a CFL Explanation: an ambiguous grammar is one for which t
more than one parse tree for a single sentence.
Answer: c 7. Automaton accepting the regular expression of any
Explanation: If two regular languages when combined do number of a ‘ s is
not always produce a regular language a) a*
3. Which of the following conversion is not possible b) ab*
(algorithmically)? c) (a/b)*
a) Regular grammar to CFG d) a*b*c
b) NDFA to DFA
c) NDPDA to DPDA Answer: a
d) NDTM to DTM Explanation: it gives any number of a’s
8. Grammars that can be translated to DFAs
Answer: c a) Left linear grammar
Explanation: Not every NDPDA has an equivalent b) Right linear grammar
deterministic PDA. c) Generic grammar
4. Consider the grammar given below E? E+E | E*E | E-E d) All of the mentioned
| E/E | E^E | (E) | id Assume that + and ^ have the same
but least precedence, * and / have the next higher Answer: b
precedence but the same precedence and finally ^ has the Explanation: Right linear grammar can be translated to
highest precedence. Assume + and ^ associate to the left the DFAs
84
9. The language accepted by a Push down Automata recursive rewriting rules (or productions) used to
a) Type0 generate patterns of strings
b) Type1 3. Which of the following statement is false?
c) Type2 a) The CFG can be converted to Chomsky normal form
d) Type3 b) The CFG can be converted to Greibach normal form
c) CFG is accepted by pushdown automata
Answer: c d) None of the mentioned
Explanation: A known fact that type 2 grammar is
accepted by PDA Answer: d
10. Given the following statements : (i) Recursive Explanation: All the statements follow the rules
enumerable sets are closed under complementation. (ii) 4. The context free grammar S → A111|S1, A → A0 | 00
Recursive sets are closed under complements. Which is equivalent to
is/are the correct statements ? a) {0ⁿ1ᵐ | n=2, m=3}
a) I only b) {0ⁿ1ᵐ | n=1, m=5}
b) II only c) {0ⁿ1ᵐ | n should be greater than two and m should be
c) Both I and II greater than four}
d) Neither I nor II d) None of the mentioned
Answer: b Answer: a
Explanation: Recursive languages are closed under the Explanation: S-> A111
following operations. S->00111 (A->00)
the Kleene star L * of L 5. The context free grammar S → SS | 0S1 | 1S0 | ɛ
the concatenation L * o P of L and P generates
the union L U P a) Equal number of 0’s and 1’s
the intersection L ∩ P b) Unequal number of 0’s and 1’s
c) Number of 0’s followed by any number of 1’s
. d) None of the mentioned
Answer: b Answer: b
Explanation: A context-free grammar (CFG) is a set of Explanation: PDA accepts CFG
85
8. A regular Grammar is a? 3. Linear grammar has more than one non-terminal on
a) CFG the right-hand side.
b) Non CFG a) True
c) English Grammar b) False
d) None of the mentioned
Answer: a
Answer: a Explanation: Grammar is linear because no rule has more
Explanation: Regular grammar is CFG.It restricts its than one non terminal on the right-hand side.
rules to a single non terminal on left hand side. 4. In Right-Linear grammars, all productions have the
9. A CFG is closed under form: A → xB.
a) Union a) True
b) Kleene star b) False
c) Concatenation
d) None of the mentioned Answer: a
Explanation: Right-Linear grammars, following are the
Answer: d form of productions: A → xB or A → x where x is some
Explanation: CFG is closed under the above mentioned 3 string of terminals.
operations 5. S → abS S → a is which grammar
10. Which of these does not belong to CFG a) Right Linear Grammar
a) Terminal Symbol b) Left Linear Grammar
b) Non terminal Symbol c) Both of the mentioned
c) Start symbol d) None of the mentioned
d) End Symbol
Answer: a
Answer: d Explanation: grammars in which all of the rules contain
Explanation: CFG consist of terminal non terminal start only one non-terminal on the left-hand side, and where in
symbol set of production rules but does not have an end every case that non-terminal is the first symbol are called
symbol. right Linear
6. What are the two types of Linear Grammar?
. a) Right Linear
b) Left Linear
Compilers – Error Handling-1 c) None of the mentioned
“Error Handling”. d) Both of the mentioned
1. Non-Linear grammar has has two non-terminals on the
right-hand side. Answer: d
a) True Explanation: Linear grammar is of 2 types Left and Right
b) False Linear Grammar
7. Which Grammar is it?
Answer: a a) Right Linear
Explanation: The above stated grammar is non-linear b) Left Linear
because it has two non-terminals on the right-hand side. c) None of the mentioned
2. S → SS S → λ S → aSb S → bSa which type of d) Both of the mentioned
grammar is it?
a) Linear Answer: b
b) Nonlinear Explanation: In Left-Linear grammars, all productions
c) Both of the mentioned have the form: A→Bx or A→ x where x is some string of
d) None of the mentioned terminals.
8. Which Type of Grammar is it?
Answer: a S → Aa A → Aab | λ
Explanation: grammar is non-linear because one of the a) Right Linear
rules (the first one) has two non-terminals on the right- b) Left Linear
hand side. c) None of the mentioned
86
d) Both of the mentioned c) Node Diagram
d) E-R Diagram
Answer: b
Explanation: In this case they both correspond to the Answer: b
regular expression (ab)*a. Explanation: Transition of finite automata is Finite
9. A Regular Grammar is any right-linear or left-linear Diagram
grammar. 5. A context free language is called ambiguous if
a) True a) It has 2 or more than 2 left derivations for some
b) False terminal string ѡ є L (G)
b) It has 2 or more than 2 left derivations for some
Answer: a terminal string ѡ є L (G)
Explanation: As it turns out the languages that can be c) Both (a) and (b)
generated by Regular Grammars is equivalent to those d) None of the mentioned
that can be specified by Regular Expressions
10. Regular Grammars generate Regular Languages. Answer: c
a) True Explanation: When two or more Left and right most
b) False derivative occur the grammar turn ambiguous
6. Which of the following statement is true?
Answer: a a) Every language that is defined by regular expression
Explanation: That’s why tey are called regular languages can also be defined by finite automata
b) Every language defined by finite automata can also be
Error Handling-2 - defined by regular expression
“Error Handling”. c) We can convert regular expressions into finite
1. Can Left Linear grammar be converted to Right Linear automata
grammar d) All of the mentioned
a) Yes
b) No Answer: d
Explanation: All these statements are true w.r.t regular
Answer: a expression
Explanation: Since right-linear grammars are regular, it 7. Which of the following identity is wrong?
follows that left-linear grammars are also regular. a) R + R = R
2. CFG is b) (R*)* = R*
a) Compiler c) ɛR = Rɛ = R
b) A language expression d) ØR = RØ = RR*
c) Regular Expression
d) None of the mentioned Answer: d
Explanation: Regular grammar combined with empty
Answer: b does not give R* instead gives empty
Explanation: they are defined by rule A->b where A is 8. Grammars that can be translated to DFAs
non terminal and b is terminal a) Left linear grammar
3. The idea of an automation with a stack as auxiliary b) Right linear grammar
storage c) Generic grammar
a) Finite automata d) All of the mentioned
b) Push Down Automata
c) Deterministic Automata Answer: b
d) None of the mentioned Explanation: Right Linear grammar can be translate to
DFA
Answer: b 9. A language is regular if and only if it is accepted by
Explanation: Push Down Automata manipulate the Stack finite automata
as a part of performing a transition a) The given statement statement is true
4. Transition of finite automata is b) Given statement is false
a) Finite Diagram c) Statement is partially true
b) State Diagram
87
d) None of the mentioned d) All of the mentioned
Answer: a Answer: d
Explanation: Regular Language is accepted by Finite Explanation: All these symbols are used to recover
Automata. Every regular language is Context free operator precedence parser from an error
10. A Push Down Automata is if t at most one transition 5. The output of lexical analyzer is
applicable to each configuration a) A set of regular expression
a) Deterministic b) Syntax tress
b) Non deterministic c) Set of Token
c) Finite d) String of Characters
d) Non finite
Answer: c
Answer: a Explanation: lexical analysis is the process of converting
Explanation: In every situation only one transition is a sequence of characters into a sequence of tokens
available as continuation then the result is deterministic 6. Which of the following is used for grouping of
push down automata. characters into tokens?
a) Parser
. b) Code optimization
c) Code generator
Recovery from Lexical Phase Errors-1 - d) Lexical analyser
“Recovery from Lexical Phase Errors”.
1. DAG representation of a basic block allows Answer: d
a) Automatic detection of local common sub expressions Explanation: lexical analysis is the process of converting
b) Detection of induction variables a sequence of characters into a sequence of tokens.
c) Automatic detection of loop variant 7. Shift reduce parsers are
d) None of the mentioned a) Top down parser
b) Bottom up parser
Answer: a c) Maybe both
Explanation: it detects local sub expression d) None of the mentioned
2. Inherited attribute is a natural choice in
a) Tracking declaration of a variable Answer: b
b) Correct use of L and R values Explanation: This corresponds to starting at the leaves of
c) Both of the mentioned the parse tree. It can be thought of. A process of reducing
d) None of the mentioned the string in question to the start symbol of the grammar.
Bottom-up parsing is also known as shift-reduce parsing.
Answer: a 8. A bottom up parser generates
Explanation: These attribute keep a check on variable a) Right most derivation
declaration b) Right most derivation in reverse
3. An intermediate code form is c) Left most derivation
a) Post-fix notation d) Left most derivation in reverse
b) Syntax Trees
c) Three Address code Answer: b
d) All of the mentioned Explanation: This corresponds to starting at the leaves of
the parse tree. It can be thought of. a process of reducing
Answer: d the string in question to the start symbol of the grammar.
Explanation: Intermediate code generator receives input Bottom-up parsing is also known as shift-reduce parsing.
from its predecessor phase, semantic analyzer, in the 9. A garbage is
form of an annotated syntax tree. a) Unallocated storage
4. Which of the following actions an operator precedence b) Allocated storage whose access paths are destroyed?
parser may take to recover from an error? c) Allocated storage
a) Insert symbols onto the stack d) Uninitialized storage
b) Delete symbols from the stack
c) Inserting or deleting symbols from the input
88
Answer: b c) Control Graph
Explanation: these are more like memory loacations with d) Hamilton graph
values whose pointers have been revoked
10. A optimizing compiler Answer: b
a) Is optimized to occupy less space Explanation: Flow chart shows basic blocks
b) Is optimized to take less time for execution 5. _________ or scanning is the process where the stream
c) Optimized the code of characters making up the source program is read from
d) None of the mentioned left to right and grouped into tokens.
a) Lexical Analysis
Answer: c b) Diversion
Explanation: As the name suggests that it optimizes the c) Modelling
code d) None of the mentioned
. Answer: a
Explanation: Lexical analysis is the process of converting
Basic a sequence of characters into a sequence of tokens
This set of Basic Compilers focuses on “Recovery from 6. The output of a lexical analyzer is
Lexical Phase Errors – 2”. a) Machine code
1. Input to code generator b) Intermediate code
a) Source code c) A stream of tokens
b) Intermediate code d) A parse tree
c) Target code
d) All of the mentioned Answer: c
Explanation: the output of lexical analyser is output
Answer: b token
Explanation: Intermediate code is the input to the code 7. _____________ is a graph representation of a
generator derivation
2. A synthesized attribute is an attribute whose value at a a) The parse tree
parse tree node depends on b) Oct tree
a) Attributes at the siblings only c) Binary tree
b) Attributes at parent node only d) None of the mentioned
c) Attributes at children nodes only
d) None of the mentioned Answer: a
Explanation: parse tree is a representation of the
Answer: c derivation
Explanation: Synthesized attribute’s value depend on 8. Which of the following symbols table implementation
children node only is based on the property of locality of reference?
3. In a bottom up evaluation of a syntax direction a) Hash Table
definition ,inherited attributes can b) Search tree
a) Always be evaluated c) Self organizing list
b) Be evaluated only if the definition is L –attributed d) Linear list
c) Evaluation only done if the definition has synthesized
attributes Answer: c
d) None of the mentioned Explanation: Self Organizing list is based on locality of
reference
Answer: c 9. Which one of the following is a top-down parser?
Explanation: Bottom-up parsing identifies and processes a) Recursive Descent parser
the text’s lowest-level, before its mid-level structures, b) Operator precedence parser
and the highest-level overall structure to last are left c) An LR(k) parser
4. The graph that shows basic blocks and their successor d) An LALR(k) parser
relationship is called
a) DAG
b) Flow Chart
89
Answer: a Sometimes in unambiguous grammar the rightmost
Explanation: Recursive Descent parsing is LL (1) parsing derivation and leftmost derivations may differ.
which is top down parsing 4. Which of the following grammar rules violate the
10. Assume that the SLR parser for a grammar G has N1 requirements of an operator grammar?
states and the LALR parser for G has n2 states. Hence (i) P -> QR
which one is true? (ii) P -> QsR
a) N1 is necessarily less than n2 (iii) P -> ε
b) N1 is necessarily equal to n2 (iV) P -> QtRr
c) N1 is necessarily greater than n2 a) (i) only
d) None of the mentioned b) (i) and (iii) only
c) (ii) and (iii) only
Answer: b d) (iii) and (iv) only
Explanation:SLR parser which has N1 states is equal to
LALR parser with N2 states. Answer: b
Explanation:
To practice basic on all areas of Compilers, . An operator precedence parser is a bottom-up parser that
interprets an operator-precedence grammar.
Recovery from Syntactic Phase Errors-1 - 5. Consider the grammar with the following translation
“Recovery from Syntactic Phase Errors”. rules and E as the start symbol.
1. Which of the following derivations does a top-down A -> A1 #B {A.value = A1.value * B.value}
parser use while parsing an input string? | B {A.value = B.value}
a) Leftmost derivation B-> B1 & F {B.value = B1.value + C.value}
b) Leftmost derivation in reverse | C {B.value= C.value }
c) Rightmost derivation C -> num {C.value = num.value}
d) Rightmost derivation in reverse Compute E.value for the root of the parse tree for the
expression:2 # 3 & 5 # 6 &4.
Answer: a a) 200
Explanation: In top down parser takes input from Left to b) 180
right constructing a leftmost derivation of the sentence. c) 160
2. The process of assigning load addresses to the various d) 40
parts of the program and adjusting the code and data in
the program to reflect the assigned addresses is called Answer: c
a) Assembly Explanation:higher precedence operator will never
b) Parsing produce an expression with operator with lower
c) Relocation precedence.&># in terms of precedence order
d) Symbol resolution 6. Given the following expression grammar:
E -> E * F | F+E | F
Answer: c F -> F-F | id
Explanation: Relocation is the process of replacing which of the following is true?
symbolic references or names of libraries with actual a) * has higher precedence than +
usable addresses in memory before running a program. b) – has higher precedence than *
Linker performs it during compilation. c) + and — have same precedence
3. Which of the following statements is false? d) + has higher precedence than *
a) Left as well as right most derivations can be in
Unambiguous grammar Answer: b
b) An LL(1) parser is a top-down parser Explanation: Precedence is that a higher precedence
c) LALR is more powerful than SLR operator will never produce an expression with operator
d) Ambiguous grammar can’t be LR(k) with lower precedence.
In the given grammar MINUS has higher precedence
Answer: a than ASTERIX
Explanation: If a grammar has more than one leftmost (or 7. Consider a program P that consists of two source
rightmost) derivation the grammar is ambiguous. modules M1(contains reference to a function defined in
M2) and M2 contained in two different files.
90
a) Edit time related to syntax analysis Register allocation is used in
b) Compile time reference with code generation.
c) Link time
d) Load time .
Answer: a Answer: c
Explanation: If a grammar has more than one leftmost (or Explanation: Successors depends on input
rightmost) derivation the grammar is ambiguous. 7. Match the following:
3. Which of the following derivations does a top-down List-I List-II
parser use while parsing an input string? A. Lexical analysis 1. Graph colouring
a) Leftmost derivation B. Parsing 2. DFA minimization
b) Leftmost derivation in reverse C. Register allocation 3. Post-order traversal
c) Rightmost derivation D. Expression evaluation 4. Production tree
d) Rightmost derivation in reverse ABCD
(a) 2 3 1 4
Answer: a (b) 2 1 4 3
Explanation: Left to right constructing leftmost (c) 2 4 1 3
derivation of the sentence. (d) 2 3 4 1
4. Given the following expression grammar:
E -> E * F | F + E | F Answer: c
F -> F – F | id Explanation: The entire column an items matches the
Which of the following is true? Column B items in a certain way.
a) * has higher precedence than + 7. Which of the following pairs is the most powerful?
b) – has higher precedence than * a) SLR, LALR
c) + and — have same precedence b) Canonical LR ,LALR
d) + has higher precedence than * c) SLR canonical LR
d) LALR canonical LR
Answer: b
Explanation: e.g. input is 3*4-5 r Answer: c
E Explanation parser algorithm is simple.
S→F⎪H
/ | \ 8. Consider the following grammar G.
F→p⎪c
E * F
| /|\
F F-F H→d⎪c
| | | Which one is true?
id(3) id(4) id(5) S1: All strings generated by G can be parsed with help of
First ‘- ‘ is be evaluated then ‘ *’ LL (1).
5. Which one of the following is true at any valid state in S2: All strings generated by G can be parsed with help of
shift-reduce parsing? LR (1).
a) At the bottom we find the prefixes. a) Only S1
b) None of the mentioned b) Only S2
c) Stack contains only viable prefixes
93
c) Both S1 S2 c) Both of the mentioned
d) None of the mentioned d) None of the mentioned
Answer: d Answer: c
Explanation: T ambiguity as the string can be derived in Explanation:
2 possible ways. First(aSa) = a
First Leftmost Derivation First(bS) = b
S→F First(c) = c
F→c LR parsers are more powerful than LL (1) parsers and
Second Leftmost Derivation LR (1)
S→H 2. Recursive descent parsing is an example of
H→c a) Top down parsing
9. What is the maximum number of reduce moves that b) Bottom up parsing
can be taken by a bottom-up parser for a grammar with c) Predictive parsing
no epsilon- and unit-production to parse a string with n d) None of the mentioned
tokens?
a) n/2 Answer: a
b) n-1 Explanation: Top down is the answer.
c) 2n-1 3. LR stands for
d) 2^n a) Left to right
b) Left to right reduction
Answer: b c) Right to left
Explanation: the moves are n-1 d) Right most derivation and Left to right and a in reverse
10. Consider the following two sets of LR (1) items of an
LR (1) grammar. Answer: d
X -> c.X, c/d Explanation: Right most derivation and left to right and
X -> .cX, c/d in reverse is used for LR
X -> .d, c/d 4. Lr parser are attractive because
X -> c.X, $ a) CFG acknowledged
X -> .cX, $ b) It does not backtrack
X -> .d, $ c) Both of the mentioned
Which one is false? d) None of the mentioned
1. Cannot be merged since look ahead’s are different.
2. Can be merged but will result in S-R conflict. Answer: c
3. Can be merged but will result in R-R conflict. Explanation: it is attractive because of these reasons
4. Cannot be merged since goto on c will lead to two 5. Which is the most powerful parser?
different sets. a) SLR
a) 1 only b) LALR
b) 2 only c) Canonical LR
c) 1 and 4 only d) Operator-precedence
d) 1, 2, 3 and 4 only
Answer: c
Answer: d Explanation: Canonical tops all other parsers.
Explanation: All these are valid reasons 6. Choose the correct statement
a) CFG is not LR
. b) Ambiguous Grammar can never be LR
c) Both of the mentioned
Error Recovery in LR phase-2 - d) None of the mentioned
“Error Recovery in LR phase -2”.
1. The grammar S → aSa | bS | c is Answer: c
a) LL(1) but not LR(1) Explanation: Mentioned reason is true
b) LR(1) but not LR(1) 7. How is the parsing precedence relations defined
a) None of the mentioned
94
b) Both of the mentioned Answer: a
c) To delimit the handle Explanation: Large number variables onto a small
d) Only for a certain pair of terminals number of CPU register.
4. A parser with the valid prefix property is advantageous
Answer: b because it
Explanation: The reason why the precedence operations a) Detects errors
is performed. b) None
8. When will the relationship between ‘+’ and ‘-’ be < c) Errors are passed to the text phase
a) For unary minus d) All of the mentioned
b) Minus is right associative
c) Both of the mentioned Answer: c
d) None of the mentioned Explanation: Advantage for a valid prefix property
5. The action of parsing the source program into proper
Answer: c syntactic classes is called
Explanation: both statements are true. a) Syntax Analysis
9. When will the relationship between ‘<’ and ‘>’ be < b) Lexical Analysis
a)> c) Interpretation analysis
b)< d) General Syntax Analysis
c)=
d)Undefined Answer: b
Explanation: Conversion of characters to tokens.
Answer: d 6. Relocating bits used by relocating loader are specified
Explanation: Undefined. T no existing relationship by
between the two a) Relocating loader itself
b) Linker
. c) Assembler
d) Macro Processor
Automatic Error Recovery in YACC-1 -
“Automatic Error Recovery in YACC”. Answer: b
1. Inherited attribute is a natural choice in Explanation: Takes an object files and combines them
a) Variable declarations record is maintained into a single executable file, library file, or another object
b) L values and R values file.
c) Both of the mentioned 7. What is the binary equivalent of the decimal number
d) None of the mentioned 368
a) 10111000
Answer: a b) 110110000
Explanation: It keeps track of variable c) 111010000
2. YACC builds up d) 111100000
a) SLR parsing table
b) Canonical LR parsing table Answer: b
c) LALR parsing table Explanation: 368 binary equivalents is
d) None of the mentioned 8=1000
6=0110
Answer: c 3=0011
Explanation: It is a parser generator, So 1101101000
3. In an absolute loading scheme which loader function is 8. AB+(A+B)’ is equivalent to
accomplished by assembler a) A?B
a) Re-allocation b) A+B
b) Allocation c) (A+B)A
c) Linking d) (A+B)B
d) Loading
Answer: a
Explanation: It is equivalent to A? B
95
9. A top down parser generates 4. An optimizer Compiler
a) Rightmost Derivation a) Is optimized to occupy less space
b) Right most derivation in reverse b) Both of the mentioned
c) Left most derivation c) Optimize the code
d) Left most derivation in reverse d) None of the mentioned
Answer: c Answer: d
Explanation: Top-down parsing is a parsing strategy Explanation: In computing, an optimizing compiler is a
where one first looks at the highest level of the parse tree compiler that tries to minimize or maximize some
and works down the parse tree by using the rewriting attributes of an executable computer program
rules of a formal grammar. 5. The linker
10. Running time of a program depends on a) Is similar to interpreter
a) Addressing mode b) Uses source code as its input
b) Order of computations c) I s required to create a load module
c) The usage of machine idioms d) None of the mentioned
d) All of the mentioned
Answer: c
Answer: d Explanation: It is a program that takes one or more object
Explanation: Run time, runtime or execution time is the files generated by a compiler and combines them into a
time during which a program is running (executing) single executable file, library file, or another object file.
6. A latch is constructed using two cross coupled
. a) AND OR gates
b) AND gates
Automatic Error Recovery in YACC-2 - c) NAND and NOR gates
“Automatic Error Recovery in YACC”. d) NAND gates
1. Which of the following is the fastest logic ?
a) TTL Answer: d
b) ECL Explanation: It has two inputs and one output
c) CMOS 7. Pee Hole optimization
d) LSI a) Loop Optimization
b) Local Optimization
Answer: b c) Constant folding
Explanation: In electronics, emitter-coupled logic (ECL) d) Data Flow analysis
is a high-speed integrated circuit.
2. A bottom up parser generates Answer: a
a) Right most derivation Explanation: More loops are added
b) Rightmost derivation in reverse 8. The optimization which avoids test at every iteration is
c) Leftmost derivation a) Loop unrolling
d) Leftmost derivation in reverse b) Loop jamming
c) Constant folding
Answer: b d) None of the mentioned
Explanation: This corresponds to starting at the leaves of
the parse tree also known as shift-reduce parsing. Answer: a
3. A grammar that produces more than one parse tree for Explanation: Execution speed is enhanced by sacrificing
some sentence is called bits
a) Ambiguous 9. Scissoring enables
b) Unambiguous a) A part of data to be displayed
c) Regular b) Entire data to be displayed
d) None of the mentioned c) None of the mentioned
d) No data to be displayed
Answer: a
Explanation: ambiguous grammar has more than one Answer: a
parse tree. Explanation: Displays only some part of the data
96
10. Shift reduce parsers are c) Set of Token
a) Top down Parser d) String of Characters
b) Bottom Up parser
c) May be top down or bottom up Answer: c
d) None of the mentioned Explanation: lexical analysis is the process of converting
a sequence of characters into a sequence of tokens
Answer: b 6. Which of the following is used for grouping of
Explanation: Also known as shift reduce parser characters into tokens?
a) Parser
. b) Code optimization
c) Code generator
Predictive Parsing Error Recovery-1 - d) Lexical analyzer
“Predictive Parsing Error Recovery”.
1. DAG representation of a basic block allows Answer: d
a) Automatic detection of local common sub expressions Explanation: lexical analysis is the process of converting
b) Detection of induction variables a sequence of characters into a sequence of tokens.
c) Automatic detection of loop variant 7. Shift reduce parser are
d) None of the mentioned a) Top down parser
b) Bottom up parser
Answer: a c) Maybe both
Explanation: it detects local sub expression . d) None of the mentioned
2. Inherited attribute is a natural choice in
a) Tracking declaration of a variable Answer: b
b) Correct use of L and R values Explanation: This corresponds to starting at the leaves of
c) Both of the mentioned the parse tree. It can be thought of. A process of reducing
d) None of the mentioned the string in question to the start symbol of the grammar.
Bottom-up parsing is also known as shift-reduce parsing.
Answer: a 8. A bottom up parser generates
Explanation: These attribute keep a check on variable a) Right most derivation
declaration b) Right most derivation in reverse
3. An intermediate code form is c) Left most derivation
a) Post-fix notation d) Left most derivation in reverse
b) Syntax Trees
c) Three Address code Answer: b
d) All of the mentioned Explanation: This corresponds to starting at the leaves of
the parse tree. It can be thought of. a process of reducing
Answer: d the string in question to the start symbol of the grammar.
Explanation: Intermediate code generator receives input Bottom-up parsing is also known as shift-reduce parsing.
from its predecessor phase, semantic analyzer, in the 9. A garbage is
form of an annotated syntax tree. a) Unallocated storage
4. Which of the following actions an operator precedence b) Allocated storage whose access paths are destroyed?
parser may take to recover from an error? c) Allocated storage
a) Insert symbols onto the stack d) Uninitialized storage
b) Delete symbols from the stack
c) Inserting or deleting symbols from the input Answer: b
d) All of the mentioned Explanation: these are more like memory locations with
values whose pointers have been revoked
Answer: d 10. A optimizing compiler
Explanation: All these symbols are used to recover a) Is optimized to occupy less space
operator precedence parser from an error b) Is optimized to take less time for execution
5. The output of lexical analyzer is c) Optimized the code
a) A set of regular expression d) None of the mentioned
b) Syntax tress
97
Answer: c c) Modelling
Explanation: As the name suggests that it optimizes the d) None of the mentioned
code
Answer: a
. Explanation: Lexical analysis is the process of converting
a sequence of characters into a sequence of tokens
Predictive Parsing Error Recovery-2 - 6. The output of a lexical analyzer is
“Predictive Parsing Error Recovery”. a) Machine code
1. Input to code generator b) Intermediate code
a) Source code c) A stream of tokens
b) Intermediate code d) A parse tree
c) Target code
d) All of the mentioned Answer: c
Explanation: the output of lexical analyser is output
Answer: b token
Explanation: Intermediate code is the input to the code 7. _____________ is a graph representation of a
generator derivation
2. A synthesized attribute is an attribute whose value at a a) The parse tree
parse tree node depends on b) Oct tree
a) Attributes at the siblings only c) Binary tree
b) Attributes at parent node only d) None of the mentioned
c) Attributes at children nodes only
d) None of the mentioned Answer: a
Explanation: parse tree is a representation of the
Answer: c derivation
Explanation: Synthesized attribute’s value depend on 8. Which of the following symbols table implementation
children node only is based on the property of locality of reference?
3. In a bottom up evaluation of a syntax direction a) Hash Table
definition ,inherited attributes can b) Search tree
a) Always be evaluated c) Self organizing list
b) Be evaluated only if the definition is L –attributed d) Linear list
c) Evaluation only done if the definition has synthesized
attributes Answer: c
d) None of the mentioned Explanation: Self Organizing list is based on locality of
reference
Answer: c 9. Which one of the following is a top-down parser?
Explanation: Bottom-up parsing identifies and processes a) Recursive Descent parser
the text’s lowest-level, before its mid-level structures, b) Operator precedence parser
and the highest-level overall structure to last are left c) An LR(k) parser
4. The graph that shows basic blocks and their successor d) An LALR(k) parser
relationship is called
a) DAG Answer: a
b) Flow Chart Explanation: Recursive Descent parsing is LL (1) parsing
c) Control Graph which is top down parsing
d) Hamilton graph 10. Assume that the SLR parser for a grammar G has n1
states and the LALR parser for G has n2 states. Hence
Answer: b which one is true?
Explanation: Flow chart shows basic blocks a) n1 is necessarily less than n2
5. _________ or scanning is the process where the stream b) n1 is necessarily equal to n2
of characters making up the source program is read from c) n1 is necessarily greater than n2
left to right and grouped into tokens. d) None of the mentioned
a) Lexical Analysis
b) Diversion
98
Answer: b Answer: c
Explanation: Bottom-up parsing identifies and processes Explanation: Only reject out of the following is a correct
the text’s lowest-level, before its mid-level structures, LR parser action
and the highest-level overall structure to last are left 6. If a state does not know whether it will make a shift
operation or reduction for a terminal is called
. a) Shift/reduce conflict
b) Reduce /shift conflict
Recovery from Semantic Errors-1 - c) Shift conflict
“Recovery from Semantic Errors”. d) Reduce conflict
1. Which of these is also known as look-head LR parser?
a) SLR Answer: a
b) LR Explanation: as the name suggests that the conflict is
c) LLR between shift and reduce hence it is called shift reduce
d) None of the mentioned conflict
7. When t a reduce/reduce conflict?
Answer: c a) If a state does not know whether it will make a shift
Explanation: LLR is the look ahead parser. operation using the production rule i or j for a terminal
2. What is the similarity between LR, LALR and SLR? b) If a state does not know whether it will make a shift or
a) Use same algorithm, but different parsing table reduction operation using the production rule i or j for a
b) Same parsing table, but different algorithm terminal
c) Their Parsing tables and algorithm are similar but uses c) If a state does not know whether it will make a
top down approach reduction operation using the production rule i or j for a
d) Both Parsing tables and algorithm are different terminal
d) None of the mentioned
Answer: a
Explanation: The common grounds of these 3 parser is Answer: c
the algorithm but parsing table is different Explanation:It occurs when If a state does not know
3. An LR-parser can detect a syntactic error as soon as whether it will make a reduction operation using the
a) The parsing starts production rule i or j for a terminal.
b) It is possible to do so a left-to-right scan of the input 8. When ß ( in the LR(1) item A -> ß.a,a ) is not empty,
c) It is possible to do so a right-to-left scan of the input the look-head
d) Parsing ends a) Will be affecting
b) Does not have any affect
Answer: b c) Shift will take place
Explanation: Error is found when it the input string is d) Reduction will take place
scanned
4. Which of these is true about LR parsing ? Answer: b
a) Is most general non-backtracking shift-reduce parsing Explanation: T no terminal before the non-terminal beta
b) It is still efficient 9. When ß is empty (A -> ß.,a ), the reduction by A-> a is
c) Both of the mentioned done
d) None of the mentioned a) If next symbol is a terminal
b) Only If the next input symbol is a
Answer: c c) Only If the next input symbol is A
Explanation: LR parsers are a type of bottom-up parsers d) Only if the next input symbol is a
that efficiently handle deterministic context-free
languages in guaranteed linear time. Answer: d
5. Which of the following is incorrect for the actions of A Explanation: the next token is considered in this case it’s
LR-Parser I) shift s ii) reduce A->ß iii) Accept iv) reject? a
a) Only I) 10. The construction of the canonical collection of the
b) I) and ii) sets of LR (1) items are similar to the construction of the
c) I), ii) and iii) canonical collection of the sets of LR (0) items. Which is
d) I), ii) , iii) and iv) an exception?
a) Closure and goto operations work a little bit different
99
b) Closure and goto operations work similarly Answer: c
c) Closure and additive operations work a little bit Explanation: Lexical analysis and code generation is a
different phase of compilation process
d) Closure and associatively operations work a little bit 4. System program such a s compiler are designed so that
different they are
a) Re-enterable
Answer: a b) Non reusable
Explanation: closure and goto do work differently in case c) Serially usable
of LR (0) and LR (1) d) None of the mentioned
. Answer: a
Explanation: Re-enterable is the keyword for compiler
Tricky being designed
This set of Tricky Compilers focuses on “Recovery from 5. A series of statements explaining how the data is to be
Semantic Errors – 2”. processed is called
1. Terminal table a) Assembly
a) Contains all constants in the program b) Machine
b) Is a permanent table of decision rules in the form of c) COBOL
patterns for matching with the uniform symbol table to d) Program
discover syntactic structure
c) Consist of a full or partial list of the token is as they Answer: d
appear in the program created by lexical analysis and Explanation: A program is a sequence of instructions,
used for syntax analysis and interpretation written to perform a task by computer. It requires
d) Is a permanent table which lists all keywords and programs to function, typically executing the program’s
special symbols of the language in symbolic form instructions in a central processor.
6. A loader is a program that
Answer: d a) Program that places functions into memory and
Explanation: A permanent database that has entry for prepares them for execution
each terminal symbols such as arithmetic operators, b) Program that automates the translation of assembly
keywords, punctuation characters such as ‘;’, ‘,’etc. language into machine language
Fields: Name of the symbol. c) Program accepting another program written in a high
2. Advantage of incorporating the macro-processor into level language and produces as object program
pass 1 is that d) None of the mentioned
a) Many functions have to be implemented twice
b) Functions are combined not necessarily creating Answer: a
intermediate files as output from the macro-processor and Explanation: A loader is the part of an operating system
input to the assembler that is responsible for loading programs and libraries. It
c) More flexibility is provided to the programmer in that is important in the process of placing the programs into
he may use all the features of the assembler in memory and executing them.
conjunction with macros 7. A system program that setup an executable program in
d) All of the mentioned main memory ready for execution is
a) Assembler
Answer: d b) Linker
Explanation: A general-purpose macro processor or c) Loader
general purpose pre-processor is a macro …designed d) Load and go
primarily for string manipulation, macro definition
3. Which of the following is a phase of a compilation Answer: c
process? Explanation: a loader is the part of an operating system
a) Lexical Analysis that is responsible for loading programs and libraries. It
b) Code Generation is one of the essential stages in the process of starting a
c) Both of the mentioned program, as it places programs into memory and prepares
d) None of the mentioned them for execution
100
8. Which of the following system program forgoes the Answer: a
production of object code to generate absolute machine Explanation: Only syntactical errors can be detected by
code and load it into the physical main storage location the compiler
from which it will be executed immediately upon 2. A simple two-pass assembler does which of the
completion of the assembly? following in the first pass?
a) Two pass assembler a) It allocates space for the literals
b) Load and go assembler b) Calculates total length of the program
c) Macro processor c) Symbol table is built for the symbols and their value
d) Linker d) All of the mentioned
Answer: b Answer: d
Explanation: A load and go assembler generates absolute Explanation: A two-pass assembler. Each pass scans the
machine code and loads it to physical memory program, the first pass generates the symbol table and the
9. Uniform symbol table second pass generates the machine code…
a) Has all constants in the program 3. A system program that set-up an executable program
b) Permanent table of rules in the form of patterns for in main memory ready for execution is
matching with the uniform symbol table to discover a) Assembler
syntactic structure b) Linker
c) Consists of full or partial list of the tokens as they c) Loader
appear in the program created by Lexical analysis and d) Text editor
used for syntax analysis and interpretation
d) A permanent table which has all key words and special Answer: c
symbols of the language in symbolic form Explanation: A loader is the part of an operating system
that is responsible for loading programs and libraries. It
Answer: c is important that with the starting of a program, as it
Explanation: Each pass scans the program, the first pass places programs into memory and executes it.
generates the symbol table and the second pass generates 4. A compiler is a program that
the machine code. a) Program is put into memory and executes it
10. Assembler is a program that b) Translation of assembly language into machine
a) Puts programs into memory and executes them language
b) Translates the assembly language into machine c) Acceptance of a program written in a high level
language language and produces an object program
c) Writes in high level language and produces an object d) None of the mentioned
program
d) None of the mentioned Answer: c
Explanation: A compiler is a computer program (or set of
Answer: b programs) that transforms source code written in a
Explanation: An assembler is a program that takes basic programming language (the source language) into
computer instructions and converts them into a pattern of another computer language (the target language, often
bits that the computer’s processor can use to perform its having a binary form known as object code).
basic operations. 5. A programmer by mistake writes multiplication
instead of division, such error can be detected by a/an
To practice Tricky on all areas of Compilers, . a) Compiler
b) Interpreter
Code Optimization-1 - c) Compiler or interpreter test
“Code Optimization”. d) None of the mentioned
1. Compiler can diagnose
a) Grammatical errors only Answer: d
b) Logical errors only Explanation: No Logical errors can’t be detected
c) Grammatical and logical errors 6. The computer language generally translated to pseudo-
d) None of the mentioned code is
a) Assembly
b) Machine
101
c) Pascal a) 23131
d) FORTRAN b) 11233
c) 11231
Answer: a d) 33211
Explanation: An assembly language (or assembler
language) is a low-level programming language for a Answer: a
computer, or other programmable device, in which t a Explanation: initially 2 is printed then 3 then 1 3 1
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 Code Optimization-2 -
modules of a program into a form suitable for execution “Code Optimization”.
is 1. The symbol table implementation is based on the
a) Assembler property of locality of reference is
b) Linking Loader a) Linear List
c) Cross Compiler b) Search Tree
d) None of the mentioned c) Hash table
d) Self Organization
Answer: b
Explanation: A loader which combines the functions of a Answer: c
relocating loader with the ability to combine a number of Explanation: a hash table (hash map) is a data structure
program segments that have been independently used to implement an associative array. A hash table uses
compiled into an executable program. a hash function to compute an index into an array, from
8. In which way a macro processor for assembly which the correct value can be found.
language can be implemented? 2. In operator precedence parsing whose precedence
a) Independent two-pass processor relations are defined
b) Independent one-pass processor a) For all pair of non-terminals
c) Processor put into pass 1 of a standard two pass b) For all pair of terminals
assembler c) To delimit the handle
d) All of the mentioned d) None of the mentioned
Answer: d Answer: a
Explanation: A general-purpose macro processor or Explanation: There are two important properties for these
general purpose preprocessor is a macro …designed for operator precedence parsers is that it does not appear on
string manipulation, macro definition the right side of any production and no production has
9. Resolution of externally defined symbols is performed two adjacent no terminals.
by 3. LR parser are attractive because
a) Linker a) It can be constructed to recognize CFG corresponding
b) Loader to almost all programming constructs
c) Compiler b) It does not backtrack
d) Interpreter c) Both of the mentioned
d) None of the mentioned
Answer: a
Explanation: a linker or link editor is a computer program Answer: c
that takes one or more object files generated by a Explanation: These above mentioned are the reasons why
compiler and combines them into a single executable file, LR parser is considered to be attractive
library file, or another object file. 4. The most powerful parser is
10. A shift reduce parser carries out the actions specified a) SLR
within braces immediately after reducing with the b) LALR
corresponding rule of grammar S—-> xxW ( PRINT “1”) c) Canonical LR
S—-> y { print ” 2 ” } S—-> Sz { print ” 3 ” ) What is d) Operator Precedence
the translation of xxxxyzz using the syntax directed
translation scheme described by the above rules ?
102
Answer: c 10. Relocating bits used by relocating loader are
Explanation: The most powerful parser is Canonical LR specified by
5. Yacc Builds up a) Relocation loader itself
a) SLR parsing Table b) Linker
b) Canonical LR parsing Table c) Assembler
c) LALR parsing Table d) Macro Processor
d) None of the mentioned
Answer: b
Answer: c Explanation: A linker or link editor is a computer
Explanation: Yacc provides a general tool for describing program that takes one or more object files generated by
the input to a computer program. a compiler and combines them into a single executable
6. Object program is a file, library file, or another object file.
a) Program written in machine language
b) Translated into machine language .
c) Translation of high-level language into machine
language Loop Optimization-1 -
d) None of the mentioned “Loop Optimization”.
1. In a single pass assembler, most of the forward
Answer: c references can be avoided by putting the restriction
Explanation: A computer program when from the a) On the number of strings/life reacts
equivalent source program into machine language by the b) Code segment to be defined after data segment
compiler or assembler. c) On unconditional rump
7. ( Z,* ) be a structure, and * is defined by n * m d) None of the mentioned
=maximum ( n , m ) Which of the following statements is
true for ( Z, * ) ? Answer: b
a) ( Z,* ) is a monoid Explanation: A single pass assembler scans the program
b) ( Z,* ) is an algebraic group only once and creates the equivalent binary program.
c) ( Z,* ) is a group 2. The method which merges the bodies of two loops is
d) None of the mentioned a) Loop rolling
b) Loop jamming
Answer: d c) Constant folding
Explanation: It is neither a monoid nor a simple group d) None of the mentioned
nor algebraic group
8. The address code involves Answer: b
a) Exactly 3 address Explanation: In computer science, loop fusion (or loop
b) At most Three address jamming) is a compiler optimization and loop
c) No unary operators transformation which replaces multiple loops with a
d) None of the mentioned single one.
3. Assembly code data base is associated with
Answer: d a) Code is converted into assembly
Explanation: In computer science, three-address is an b) Table of rules in the form of patterns for matching
intermediate code used by optimizing compilers to aid in with the uniform symbol table to discover syntactic
the implementation of code-improving transformations. structure
9. An intermediate code form is c) None of the mentioned
a) Post-fix Notation d) Both of the mentioned
b) Syntax Trees
c) Three address code Answer: a
d) All of the mentioned Explanation: An assembly language is a low-level
programming language for a computer, or other
Answer: d programmable device, in which t a very strong (generally
Explanation: Intermediate code generator takes an input one-to-one) correspondence between the language and
from its predecessor phase, semantic analyzer, in the the architecture’s machine code instructions.
form of an annotated syntax tree.
103
4. The process manager has to keep track of 9. Which of the following functions is performed by
a) Status of each program loader?
b) Information to a programmer using the system a) Allocate memory for the programs and resolve
c) Both of the mentioned symbolic references between objects decks
d) None of the mentioned b) Address dependent locations, such as address
constants, to correspond to the allocated space
Answer: c c) Physically place the machine instructions and data into
Explanation: Process manager keep track of the status memory
and info about the program d) All of the mentioned
5. Function of the syntax phase is to
a) Recognize the language and to cal the appropriate Answer: d
action routines that will generate the intermediate form or Explanation: a loader is the part of an operating system
matrix for these constructs that is responsible for loading programs and libraries.
b) Build a literal table and an identifier table 10. The root directory of a disk should be placed
c) Build a uniform symbol table a) At a fixed address in main memory
d) Parse the source program into the basic elements or b) At a fixed location on the disk
tokens of the language c) Anywhere on the disk
d) None of the mentioned
Answer: a
Explanation: In this phase symbol table is created by the Answer: b
compiler which contains the list of lexemes or tokens. Explanation: Root directory is placed at a fixed disk
6. If E be a shifting operation applied to a function f, location
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β) Loop Optimization-2 -
d) E (αf +β g )=αβ E (f + g) “Loop Optimization”.
1. The segment base is specified using the register named
Answer: a is
Explanation: Shifting operation when performed gives a) ORG instructions
this result b) TITLE instruction
7. Pass I c) ASSUME instruction
a) Assign address to all statements d) SEGMENT instruction
b) Save the values assigned to all labels for use in pass 2
c) Perform some processing Answer: a
d) All of the mentioned Explanation: ORG segment base register is used to
specify the register
Answer: d 2. In what module multiple instances of execution will
Explanation: The pass 1 of a compiler the above yield the same result even if one instance has not
mentioned functions are performed terminated before the next one has begun?
8. Which table is a permanent database that has an entry a) Non- usable module
for each terminal symbol? b) Serially usable
a) Terminal Table c) Re-enterable module
b) Literal Table d) None of the mentioned
c) Identifier Table
d) None of the mentioned Answer: c
Explanation: Re enterable module is the reason why the
Answer: a compiler is used in the first place.
Explanation: A database that has entry for each terminal 3. Dividing a project into segments and smaller units in
symbols such as arithmetic operators, keywords, order to simplify design and programming efforts is
punctuation characters such as ‘;’, ‘,’etc Fields: Name of called
the symbol. a) Modular approach
b) Top down approach
104
c) Bottom up approach Answer: d
d) Left right approach Explanation: a linker or link editor is a computer program
that takes one or more object files generated by a
Answer: a compiler and combines them into a single executable file,
Explanation: Modular design, or “modularity in design”, library file, or another object file.
is a design approach that subdivides a system into smaller 8. The table created by lexical analysis to describe all
parts called modules or skids that can be independently literals used in the source program is
created and then used in different systems. a) Terminal table
4. Which one of the following is the tightest upper bound b) Literal table
that represents the time complexity of inserting an object c) Identifier table
into a binary search tree of n nodes? d) Reductions
a) O(1)
b) O(long) Answer: b
c) O(n) Explanation: In computer science, and specifically in
d) O(long) compiler and assembler design, literal pool is a lookup
table used to hold literals during assembly and execution.
Answer: c 9. Which loader function is accomplished by loader?
Explanation: For skewed binary search tree on n nodes, a) Reallocation
the upper bound to insert a node is O (n) b) Allocation
5. Which of the following is true for machine language? c) Linking
a) Continuous execution of program segments d) Loading
b) Depicting flow of data in a system
c) A sequence of instructions which solves a problem Answer: d
d) The language which interacts with the computer using Explanation: Function of a loader
only the binary digits 1 and 0. 10. Pass 2
a) Assemble instruction and generate data
Answer: d b) Perform processing of assembler
Explanation: Machine code or machine language is a set c) Write the object program
of instructions executed directly by a computer’s central d) All of the mentioned
processing unit (CPU). Each instruction performs a very
specific task. Answer: d
6. Software that measures, monitors, and controls events Explanation: A multi-pass compiler is a type of compiler
is that processes the source code or abstract syntax tree of a
a) System S/w program several times. Each pass takes the result of the
b) Real Time software previous pass as the input, and creates an intermediate
c) Scientific software output…
d) Business Software
.
Answer: b
Explanation: In computer science, real-time computing Elimination of Induction Variables-1 -
(RTC), or reactive computing describes hardware and “Elimination of Induction Variables”.
software systems subject to a “real-time constraint”, for 1. Which is not true about syntax and semantic parts of a
example operational deadlines from event to system computer language?
response. a) Semantics is checked mechanically by a computer
7. A linker is given object module for a set of programs b) Semantics is the responsibility of the programmer
that were compiled separately. What is not true about an c) Both of the mentioned
object module d) None of the mentioned
a) Object code
b) Relocation bits Answer: d
c) Names and locations of all external symbols denied in Explanation: Both in terms of semantics is not true.
the object module 2. Which of the following statement is true?
d) Absolute addresses of internal symbols a) SLR powerful than LALR
b) LALR powerful than Canonical LR parser
105
c) Canonical LR powerful than LALR parser c) Both of the mentioned
d) The parsers SLR= Canonical LR=LALR d) None of the mentioned
Answer: c Answer: c
Explanation: LR >LALR>SLR In terms of parser Explanation: its basic function is that of the task storage
3. Which of the following features cannot be captured by manager
CFG ? 8. When a computer is rebooted, a special type of loader
a) Syntax of if-then-else statements is executed called
b) Syntax of recursive procedures a) Compile and GO ” loader
c) A variable is declared before its use b) Boot loader
d) Matching nested parenthesis c) Bootstrap Loader
d) Relating Loader
Answer: d
Explanation: It is because, it is equivalent to recognizing Answer: c
us, where the first w is the declaration and the second is Explanation: A boot loader, is a small program that
its use, we are not a CFG. places the operating system (OS) of a computer into
4. In which of the following no information hiding is memory
done? 9. Disadvantage of ” Compile and GO ” loading scheme
a) Compile prig 1, prig 2 is that
b) Run test, prog a) Memory is wasted because the case occupied by the
c) Load R1 , A assembler is unavailable to the object program
d) 001001000010101 b) Necessary to translate the users program
c) It is very difficult to handle multiple segments, even
Answer: d when the source programs are in different languages and
Explanation: The entire binary symbol gives the to produce orderly modular programs
information d) All of the mentioned
5. The identification of common sub-expression and
replacement of run-time computations by compile-time Answer: d
computations is Explanation: In computer programming, a compile and
a) Local optimization go system, compile, load, and go system, assemble and
b) Loop optimization go system, or load and go system[1][2][3] is a
c) Constant folding programming language processor in which the
d) Data flow analysis compilation, assembly, or link steps are not separated
from program execution.
Answer: c 10. Function of the storage assignment is
Explanation: Constant folding is the process of a) Assign storage to all variables referenced in the source
recognizing and evaluating constant expressions at program
compile time rather than computing them at runtime. b) Assign storage to all temporary locations that are
Terms in constant expressions are typically simple necessary for intermediate results
literals they may also be variables whose values are c) Assign storage to literals, and to ensure that the storage
assigned at compile time. is allocated and appropriate locations are initialized
6. The graph that shows basic blocks and their successor d) All of the mentioned
relationship is called
a) Dag Answer: d
b) Flow Graph Explanation: the storage assignment performs the above
c) Control Graph mentioned tasks
d) Hamilton Graph
.
Answer: b
Explanation: Flow graph shows the basic blocks Elimination of Induction Variables-2 -
7. The specific task storage manager performs “Elimination of Induction Variables”.
a) Allocation/ deal location of programs 1. A non relocatable program is the one which
b) Protection of storage area assigned to the program a) Cannot execute in any area of storage other than the
106
one designated c) Data located in other procedure
b) Consists of a program and information for its d) All of the mentioned
relocation
c) None of the mentioned Answer: b
d) All of the mentioned Explanation: External subroutines are routines that are
created and maintained separately from the program that
Answer: a will be calling them
Explanation: A non reloadable program is one which 6. Relocation bits used by relocating loader are specified
cannot be made to execute in any area of storage other by
than the one designated for it at the time of its coding or a) Relocating loader itself
translation. b) Linker
2. A relocatable program form is one which c) Assembler
a) Cannot execute in any area of storage other than the d) Macro processor
one designated
b) Consists of a program and information for its Answer: b
relocation Explanation: A linker or link editor is a computer
c) None of the mentioned program that takes one or more object files generated by
d) All of the mentioned a compiler and combines them into a single executable
file, library file, or another object file.
Answer: c 7. Generation of intermediate code based on a abstract
Explanation: A reloadable program form is one which machine model is useful in compilers because
consists of a program and relevant information for its a) Implementation of lexical analysis and syntax analysis
relocation. Using this information it is possible to is made easier
relocate the program to execute from a storage area then b) Writing for intermediate code generation
the one designated for it at the time of its coding or c) Portability of the front end of the compiler
translation. d) None of the mentioned
3. A self-relocating program is one which
a) Cannot execute in any area of storage other than the Answer: a
one designated Explanation: Intermediate code generator receives input
b) consists of a program and information for its from its predecessor phase, semantic analyzer, in the
relocation form of an annotated syntax tree.
c) None of the mentioned 8. Which of the following module does not incorporate
d) All of the mentioned initialization of values changed by the module?
a) Non reusable module
Answer: c b) Serially reusable module
Explanation: A self-relocating program is a program c) Re-enterable module
which can perform the relocation itself d) All of the mentioned
•A table of information about address sensitive
instruction in the program. Answer: a
•Relocating logic that can perform the relocation of the Explanation: Non reusable models can be used once for a
address sensitive instructions purpose they can’t be modified and used again
4. Scissoring enables 9. An intermediate code form is
a) A part of data to be displayed a) Postfix Notation
b) Entire data to be displayed b) Syntax Trees
c) Full data display on full screen c) Three address
d) No data to be displayed d) All of the mentioned
Answer: a Answer: d
Explanation: It displays a part of the data Explanation: all the specified options are type of
5. Which of the following can be accessed by transfer intermediate code form
vector approach of linking? 10. The best way to compare the different
a) External data segments implementations of symbol table is to compare the time
b) External sub-routines required to
107
a) Add a new name 5. Type checking is normally done during
b) Make an enquiry a) Lexical Analysis
c) Add a new name and make an enquiry b) Syntax Analysis
d) All of the mentioned c) Syntax Directed Translation
d) Code generation
Answer: d
Explanation: These are the different implementations of Answer: c
the symbol table as mentioned above. 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
Eliminating local Common Sub-expressions - whether there are two operands associated with ‘+’ or not
“Eliminating local Common Sub-expressions”. .
1. Select a Machine Independent phase of the compiler a) True
a) Syntax Analysis b) False
b) Intermediate Code generation
c) Lexical Analysis Answer: a
d) All of the mentioned Explanation: Syntax analyser does not check the type of
the operand.
Answer: a 7. In Short Syntax Analysis Generates Parse Tree.
Explanation: All of them work independent of a machine a) True
2. A system program that combines the separately b) False
compiled modules of a program into a form suitable for
execution? Answer: a
a) Assembler Explanation: Short Syntax Analysis generates a parse tree
b) Compiler 8. By whom is the symbol table created?
c) Linking Loader a) Compiler
d) Interpreter b) Interpreter
c) Assembler
Answer: c d) None of the mentioned
Explanation: A loader which combines the functions of a
relocating loader with the ability to combine a number of Answer: a
program segments that have been independently Explanation: symbol table is created by the compiler
compiled which contains the list of lexemes or tokens.
3. Which of the following system software resides in the 9. What does a Syntactic Analyser do?
main memory always a) Maintain Symbol Table
a) Text Editor b) Collect type of information
b) Assembler c) Create parse tree
c) Linker d) None of the mentioned
d) Loader
Answer: c
Answer: d Explanation: Syntax analyzer will just create parse tree.
Explanation: Loader is used to loading programs. Semantic Analyzer checks the meaning of the string
4. Output file of Lex is _____ the input file is Myfile. parsed.
a) Myfile.e 10. Semantic Analyser is used for
b) Myfile.yy.c a) Generating Object code
c) Myfile.lex b) Main ting symbol table
d) Myfile.obj c) None of the mentioned
d) Both of the mentioned
Answer: b
Explanation: This Produce the filr “myfile.yy.c” which Answer: d
we can then compile with g++ Explanation: Maintaining the Symbol Table for each
block.
108
Source Program for Semantic Errors. Collects Type grammar.
Information for Code Generation. Reporting compile- a) L = {aaaa,aabb,bbaa,bbbb}
time errors in the code generating the object code (e.g., b) L = {abab,abaa,aaab,baaa}
assembler or intermediate code) c) L = {aaab,baba,bbaa,bbbb}
d) L = {aaaa,abab,bbaa,aaab}
.
Answer: a
Eliminating Global Common Subexpressions-1 - Explanation: the production rules give aaaa or aabb or
“Eliminating Global Common Subexpressions”. bbaa or bbbb
1. Which of the following is not a regular expression? 7. Give a production grammar that specified language L
a) [(a+b)*-(aa+bb)]* = {ai b2i >= 1}:
b) [(0+1)-(0b+a1)*(a+b)]* a) {S->aSbb,S->abb}
c) (01+11+10)* b) {S->aSb, S->b}
d) (1+2+0)*(1+2)* c){S->aA,S->b,A->b}
d) None of the mentioned
Answer: b
Explanation: Except b all are regular expression. Answer: a
2. Regular expression are Explanation: S->aSbb, S->abb give a^I a’s and b^2i b’s
a) Type 0 language
b) Type 1 language .
c) Type 2 language
d) Type 3 language Eliminating Global Common Subexpressions-2 -
“Eliminating Global Common Subexpressions”.
Answer: An 1. Let R1 and R2 be regular sets defined over alphabet ∑
Explanation: According to Chomsky hierarchy. then
3. Which of the following is true? a) R1 UNION R2 is regular
a) All subsets of a regular set are always regular b) R1 INTERSECTION R2 is regular
b) All finite subsets of non-regular set are always regular c) ∑ INTERSECTION R2 IS NOT REGULAR
c) Union of two non regular set of language is not regular d) R2* IS NOT REGULAR
d) Infinite times union of finite set is always regular
Answer: a
Answer: b Explanation: union of 2 regular languages is regular
Explanation: None. 2. Which of the following String can be obtained by the
4. L and ~L are recursive enumerable then L is language L = {ai b2i / i >=1}?
a) Regular a) aaabbbbbb
b) Context free b) aabbb
c) Context sensitive c) abbabbba
d) Recursive d) aaaabbbabb
Answer: d Answer: a
Explanation: If L is recursive enumerable and its Explanation: above production rule gives suppose if 3 a’s
complement too if and only if L is recursive. the corresponding b’s are 6 b’s
5. Regular expressions are closed under
∈ (a,b)*, the number of a’s in x is multiple of 3}.
3. Give a production grammar for the language L = {x/x
a) Union
b) Intersection a) {S->bS, S->b,S->aA, S->bA, A->aB, B->bB, B->aS,
c) Kleen star S->a}
d) All of the mentioned b) {S->aS,S->bA,A->bB,B->bBa,B->bB}
c) {S->aaS,S->bbA,A->bB,B->ba}
Answer: d d) None of the above
Explanation: According to definition of regular
expression. Answer: a
6. Consider the production of the grammar S->AA A->aa Explanation: the above given condition is satisfied by
A->bb.Describe the language specified by the production
109
S->bS S->B 1. A system program that combines separately compiled
S->aA s->bA A->aB B->bB modules of a program into a form suitable for execution
B->aS S->a is
4. The production Grammar is {S->aSbb, S->abb} is a) Assembler
a) type-3 grammar b) Linking loader
b) type-2 grammar c) Cross compiler
c) type-1 grammar d) None of the mentioned
d) type-0 grammar
Answer: b
Answer: b Explanation: The definition of cross compiler
Explanation: Type 2 grammar satisfies this production 2. A compiler for a high-level language that runs on one
grammar machine and produces code for a different machine is
5. Regular expression (x/y)(x/y) denotes the set called
a) {xy,xy} a) Optimizing compiler
b) {xx,xy,yx,yy} b) One pass compiler
c) {x,y} c) Cross compiler
d) {x,y,xy} d) Multipass compiler
Answer: b Answer: c
Explanation: the expression gives aa or xy or yx or yy Explanation: So done by the definition
6. Regular expression x/y denotes the set 3. Cross-compiler is a compiler
a) {x,y} a) Which is written in a different language from the
b) {xy} source language?
c) {x} b) That generates object code for the machine it’s
d) {y} running on.
c) Which is written in the same language as the source
Answer: a language?
Explanation: x or y is given by the expression d) That runs on one machine but produces object code for
7. The regular expression denote a language comprising another machine
all possible strings of even length over the alphabet (0,1)
a) 1 + 0(1+0)* Answer: a
b) (0+1)(1+0)* Explanation: A compiler for a high-level language that
c) (1+0) runs on one machine and produces code for a different
d) (00+0111+10)* machine is called a cross compiler
4. Cross compiler is used in Bootstrapping.
Answer: d a) True
Explanation: the condition is satisfied by 00 or 0111 or b) False
10 or iterations of these
8. The regular expressions denote zero or more instances Answer: a
of an x or y is Explanation: Bootstrapping to a new platform. When a
a) (x+y) software is developed for a new platform, a cross
b) (x+y)* compiler is used to compile necessary tools such as the
c) (x* + y) OS and a native compiler.
d) (xy)* 5. Is GCC a cross Compiler ?
a) Yes
Answer: b b) No
Explanation: it says that either its x or y or iterations of
them Answer: a
Explanation:
. GCC, a free software collection of compilers, also can be
used as cross compile. It supports many languages and
Loop unrolling-1 - platforms.
“Loop unrolling”.
110
6. The __________ is a technique for building cross c) 8 4 4
compilers for other machines. d) 8 4 3
a) Brazilian Cross
b) Canadian Cross Answer: c
c) Mexican Cross Explanation: GCC compilers (32 bit compilers) size of:
d) X-cross double is 8 byte
long int is 8 byte
Answer: b Character constant is 2 byte
Explanation: The Canadian Cross is a technique for 3. What will be output of the following c code?
building cross compilers for other machines. Given three ( according to GCC compiler)
machines X, Y, and Z, one uses machine X (e.g. running #include
Windows XP on an IA-32 processor) to build a cross int main(){
compiler that runs on machine Y (e.g. running Mac OS X signed x;
on an x86-64 processor) to create executables for unsigned y;
machine Z x = 10 +- 10u + 10u +- 10;
7. __________ was developed from the beginning as a y = x;
cross compiler. if(x==y)
a) Free Pascal printf(“%d %d”,x,y);
b) GCC else if(x!=y)
c) Pascal printf(“%u %u”,x,y);
d) None of these return 0;
}
Answer: a a) 0 0
Explanation: Free Pascal was developed from the b) 65536 -10
beginning as a cross compiler. The compiler executable c) 0 65536
(ppcXXX where XXX is target architecture) is capable of d) Compilation error
producing executables for all OS of the same
architecture. Answer: a
Explanation: Consider on the expression:
. x = 10 +- 10u + 10u +- 10;
10: It is signed integer constant.
Loop unrolling-2 - 10u: It is unsigned integer constant.
“Loop unrolling”. X: It is signed integer variable.
1. If we compile the sam.c file with the command “gcc -o As we know operators enjoy higher precedence than
sam sam.c”, then the executable file will be binary operators. So
a) a.out x = 10 + (-10u) + 10u + (-10);
b) sam = 10 + -10 + 10 + (-10);
c) sam.out =0
d) None of the mentioned So, Corresponding signed value of unsigned 10u is +10
4. What will be output of the following c code?
Answer: b #include
Explanation: This is how the GCC is designed to take int main(){
names of executable files const int *p;
2. What will be output of the following code? int a=10;
#include p=&a;
int main(){ printf(“%d”,*p);
printf(“%d\t”,sizeof(6.5)); return 0;
printf(“%d\t”,sizeof(90000)); }
printf(“%d”,sizeof(‘A’)); a) 0
return 0; b) 10
} c) Garbage Value
a) 8 4 2 d) Any Memory address
b) 8 4 2
111
Answer: b 8. What will be output of the following c code?
Explanation: In the following declaration #include
const int *p; const enum Alpha{
p can keep address of constant integer. X,
5. What will be output of the following c code? Y=5,
#include Z
int main(){ }p=10;
int a= sizeof(signed) +sizeof(unsigned); int main(){
int b=sizeof(const)+sizeof(volatile); enum Alpha a,b;
printf(“%d”,a+++b); a= X;
return 0; b= Z;
} printf(“%d”,a+b-p);
a) 10 return 0;
b) 9 }
c) 8 a) -4
d) Error b) -5
c) 10
Answer: c d) 11
Explanation: Default data type of signed, unsigned, const
and volatile is intSo, a = 4 and b =4 Answer: a
Now, a+++b Explanation: Default value X is zero and
= a++ + b Z=Y+1=5+1=6
= 4 + 4 //due to post increment operator. So, a + b – p
=8 =0 + 6 -10 = -4
But in Linux gcc compiler size of int is 4 byte so your out
will be 16 .
6. Which of the following is integral data type? Compilers – Loop Jamming-1
a) void “Loop Jamming”.
b) char 1. What are the two types of Linear Grammar?
c) float a) Right Linear
d) double b) Left Linear
c) None of the mentioned
Answer: b d) Both of the mentioned
Explanation:
In c char is integral data type. It stores the ASCII value . Answer: d
7. What will be output of the following c code? Explanation: Linear grammar is of 2 types Left and Right
#include Linear Grammar
int main(){ 2. Which Grammar is it?
volatile int a=11; S → Aa A → Aab
printf(“%d”,a); a) Right Linear
return 0; b) Left Linear
} c) None of the mentioned
a) 11 d) Both of the mentioned
b) Garbage
c) -2 Answer: b
d) Cannot Predict Explanation: In Left-Linear grammars, all productions
have the form: A→Bx or A→ x where x is some string of
Answer: d terminals.
Explanation: Value of volatile variable can’t be predicted 3. Which Type of Grammar is it?
because its value can be changed by any microprocessor S → Aa A → Aab | λ
interrupt a) Right Linear
. b) Left Linear
c) None of the mentioned
112
d) Both of the mentioned 2. Transition of finite automata is
a) Finite Diagram
Answer: b b) State Diagram
Explanation: In this case they both correspond to the c) Node Diagram
regular expression (ab)*a. d) E-R Diagram
4. A Regular Grammar is any right-linear or left-linear
grammar. Answer: b
a) True Explanation: Transition of finite automata is Finite
b) False Diagram
3. A context free language is called ambiguous if
Answer: a a) It has 2 or more than 2 left derivations for some
Explanation: As it turns out the languages that can be terminal string ѡ є L (G)
generated by Regular Grammars is equivalent to those b) It has 2 or more than 2 left derivations for some
that can be specified by Regular Expressions terminal string ѡ є L (G)
5. Regular Grammars generate Regular Languages. c) Both of the mentioned
a) True d) None of the mentioned
b) False
Answer: c
Answer: a Explanation: When two or more Left and right most
Explanation: That’s why they are called regular derivative occur the grammar turn ambiguous
languages 4. Which of the following statement is true?
6. Can Left Linear grammar be converted to Right Linear a) Every language that is defined by regular expression
grammar? can also be defined by finite automata
a) Yes b) Every language defined by finite automata can also be
b) No defined by regular expression
c) We can convert regular expressions into finite
Answer: a automata
Explanation: Since right-linear grammars are regular, it d) All of the mentioned
follows that left-linear grammars are also regular.
7. CFG is Answer: d
a) Compiler Explanation: All these statements are true w.r.t regular
b) A language expression expression
c) Regular Expression 5. Which of the following identity is wrong?
d) None of the mentioned a) R + R = R
b) (R*)* = R*
Answer: b c) ɛR = Rɛ = R
Explanation: they are defined by rule A->b where A is d) ØR = RØ = RR*
non terminal and b is terminal
Answer: d
Tough Explanation: Regular grammar combined with empty
This set of Tough Compilers focuses on “Loop Jamming does not give R* instead gives empty
– 2”. 6. Grammars that can be translated to DFAs
1. The idea of an automation with a stack as auxiliary a) Left linear grammar
storage b) Right linear grammar
a) Finite automata c) Generic grammar
b) Push Down Automata d) All of the mentioned
c) Deterministic Automata
d) None of the mentioned Answer: b
Explanation: Right Linear grammar can be translate to
Answer: b DFA
Explanation: Push Down Automata manipulate the Stack 7. A language is regular if and only if it is accepted by
as a part of performing a transition finite automata
113
a) The given statement statement is true d) All of the mentioned
b) Given statement is false
c) Statement is partially true Answer: d
d) None of the mentioned Explanation: All these statements are true w.r.t regular
expression
Answer: a 4. Which of the following identity is wrong?
Explanation: Regular Language is accepted by Finite a) R + R = R
Automata. Every regular language is Context free b) (R*)* = R*
8. A Push Down Automata is if t at most one transition c) ɛR = Rɛ = R
applicable to each configuration d) ØR = RØ = RR*
a) Deterministic
b) Non deterministic Answer: d
c) Finite Explanation: Regular grammar combined with empty
d) Non finite does not give R* instead gives empty
5. Grammars that can be translated to DFAs
Answer: a a) Left linear grammar
Explanation: In every situation only one transition is b) Right linear grammar
available as continuation then the result is deterministic c) Generic grammar
push down automata. d) All of the mentioned
Answer: b Answer: a
Explanation: Transition of finite automata is Finite Explanation: Regular Language is accepted by Finite
Diagram Automata. Every regular language is Context free
2. A context free language is called ambiguous if 7. A Push Down Automata is if t at most one transition
a) It has 2 or more than 2 left derivations for some applicable to each configuration
terminal string ѡ є L (G) a) Deterministic
b) It has 2 or more than 2 left derivations for some b) Non deterministic
terminal string ѡ є L (G) c) Finite
c) Both of the mentioned d) Non finite
d) None of the mentioned
Answer: a
Answer: c Explanation: In every situation only one transition is
Explanation: When two or more Left and right most available as continuation then the result is deterministic
derivative occur the grammar turn ambiguous push down automata.
3. Which of the following statement is true?
a) Every language that is defined by regular expression .
can also be defined by finite automata
b) Every language defined by finite automata can also be Code Generation-1 -
defined by regular expression “Code Generation”.
c) We can convert regular expressions into finite 1. Grammar that produce more than one Parse tree for
automata same sentence is
a) Ambiguous
114
b) Unambiguous Turing machines is countable. Which of the following is
c) Complementary true ?
d) Concatenation Intersection a) S1 is correct and S2 is not correct.
b) Both S1 and S2 are correct.
Answer: a c) Both S1 and S2 are not correct.
Explanation: an ambiguous grammar is one for which t d) S1 is not correct and S2 is correct.
more than one parse tree for a single sentence.
2. Automaton accepting the regular expression of any Answer: b
number of a ‘ s is Explanation: The assumptions of statement S1 and S2 are
a) a* correct
b) ab* 7. A context free language is called ambiguous if
c) (a/b)* a) It has 2 or more left derivations for some terminal
d) a*b*c string ѡ є L (G)
b) It has 2 or more right derivations for some terminal
Answer: a string ѡ є L (G)
Explanation: it gives any number of a’s c) Both of th ementioned
3. Grammars that can be translated to DFAs: d) None of the mentioned
a) Left linear grammar
b) Right linear grammar Answer: b
c) Generic grammar Explanation: A context-free grammar (CFG) is a set of
d) All of the mentioned recursive rewriting rules (or productions) used to
generate patterns of strings
Answer: b
Explanation: Right linear grammar can be translated to .
the DFAs
4. The language accepted by a Push down Automata Code Generation-2 -
a) Type0 “Code Generation”.
b) Type1 1. Which of the following statement is false?
c) Type2 a) The CFG can be converted to Chomsky normal form
d) Type3 b) The CFG can be converted to Greibach normal form
c) CFG is accepted by push down automata
Answer: c d) None of the mentioned
Explanation: A known fact that type 2 grammar is
accepted by PDA Answer: d
5. Given the following statements : (i) Recursive Explanation: All the statements follow the rules
enumerable sets are closed under complementation. (ii) 2. The context free grammar S → A111|S1, A → A0 | 00
Recursive sets are closed under complements. Which is equivalent to
is/are the correct statements ? a) {0ⁿ1ᵐ | n=2, m=3}
a) I only b) {0ⁿ1ᵐ | n=1, m=5}
b) II only c) {0ⁿ1ᵐ | n should be greater than two and m should be
c) Both I and II greater than four}
d) Neither I nor II d) None of these
Answer: b Answer: a
Explanation: Recursive languages are closed under the Explanation: S-> A111
following operations. S->00111 (A->00)
The Kleene star L * of L 3. The context free grammar S → SS | 0S1 | 1S0 | ɛ
the concatenation L * o P of L and P generates
the union L U P a) Equal number of 0’s and 1’s
the intersection L ∩ P b) Unequal number of 0’s and 1’s
6. Assume statements S1 and S2 defined as : S1 : L2-L1 c) Number of 0’s followed by any number of 1’s
is recursive enumerable where L1 and L2 are recursive
and recursive enumerable respectively. S2 : The set of all
115
d) None of the mentioned symbol set of production rules but does not have an end
symbol.
Answer: a
Explanation: S->SS .
S->0S1S
S->0S11S0 Machine Model-1 -
S->0110 “Machine Model”.
4. Which of the following statement is false? 1. If a state does not know whether it will make a shift
a) In derivation tree, the label of each leaf node is operation or reduction for a terminal is called
terminal a) Shift/reduce conflict
b) In derivation tree, the label of all nodes except leaf b) Reduce /shift conflict
nodes is a variable c) Shift conflict
c) In derivation tree, if the root of a sub tree is X then it is d) Reduce conflict
called –tree
d) None of the mentioned Answer: a
Explanation: as the name suggests that the conflict is
Answer: d between shift and reduce hence it is called shift reduce
Explanation: All of them are true regarding a derivation conflict.
tree 2. When t a reduce/reduce conflict?
5. Push down automata accepts which language a) If a state does not know whether it will make a shift
a) Context sensitive language operation using the production rule i or j for a terminal
b) Context free language b) If a state does not know whether it will make a shift or
c) Recursive language reduction operation using the production rule i or j for a
d) None of the mentioned terminal
c) If a state does not know whether it will make a
Answer: b reduction operation using the production rule i or j for a
Explanation: PDA accepts CFG terminal
6. A regular Grammar is a d) None of the mentioned
a) CFG
b) Non CFG Answer: c
c) English Grammar Explanation: It occurs when If a state does not know
d) None of the mentioned whether it will make a reduction operation using the
production rule i or j for a terminal.
Answer: a 3. When ß ( in the LR(1) item A -> ß.a,a ) is not empty,
Explanation: Regular grammar is CFG. It restricts its the look-head
rules to a single non terminal on left hand side. a) Will be affecting
7. A CFG is closed under b) Does not have any affect
a) Union c) Shift will take place
b) Kleene star d) Reduction will take place
c) Concatenation
d) None of the mentioned Answer: b
Explanation: T no terminal before the non terminal beta
Answer: d 4. When ß is empty (A -> ß.,a ), the reduction by A-> a is
Explanation: CFG is closed under the above mentioned 3 done
operations a) If next symbol is a terminal
8. Which of these does not belong to CFG? b) Only If the next input symbol is a
a) Terminal Symbol c) Only If the next input symbol is A
b) Non terminal Symbol d) Only if the next input symbol is a
c) Start symbol
d) End Symbol Answer: d
Explanation: the next token is considered in this case it’s
Answer: d a
Explanation: CFG consist of terminal non terminal start
116
5. The construction of the canonical collection of the sets Answer: c
of LR (1) items are similar to the construction of the Explanation: Lexical analysis and code generation is a
canonical collection of the sets of LR (0) items. Which is phase of compilation process
an exception? 9. System program such a s compiler are designed so that
a) Closure and goto operations work a little bit different they are
b) Closure and goto operations work similarly a) Re-enterable
c) Closure and additive operations work a little bit b) Non reusable
different c) Serially usable
d) Closure and associatively operations work a little bit d) None of the mentioned
different.
Answer: a
Answer: a Explanation: Re-enterable is the keyword for compiler
Explanation: closure and goto do work differently in case being designed
of LR (0) and LR (1) 10. A series of statements explaining how the data is to
6. Terminal table be processed is called
a) Contains all constants in the program a) Assembly
b) Is a permanent table of decision rules in the form of b) Machine
patterns for matching with the uniform symbol table to c) COBOL
discover syntactic structure d) Program
c) Consist of a full or partial list of the token is as they
appear in the program created by lexical analysis and Answer: d
used for syntax analysis and interpretation Explanation: A program is a sequence of instructions,
d) Is a permanent table which lists all keywords and written to perform a task by computer. It requires
special symbols of the language in symbolic form programs to function, typically executing the program’s
instructions in a central processor.
Answer: d 11. A loader is a program that
Explanation: A permanent database that has entry for a) Program that places functions into memory and
each terminal symbols such as arithmetic operators, prepares them for execution.
keywords, punctuation characters such as ‘;’, ‘,’etc b) Program that automates the translation of assembly
Fields: Name of the symbol. language into machine language.
7. Advantage of incorporating the macro-processor into c) Program accepting another program written in a high
pass 1 is that level language and produces as object program
a) Many functions have to be implemented twice d) None of the mentioned
b) Functions are combined not necessarily creating
intermediate files as output from the macro-processor and Answer: a
input to the assembler Explanation: A loader is the part of an operating system
c) More flexibility is provided to the programmer in that that is responsible for loading programs and libraries. It
he may use all the features of the assembler in is important in the process of placing the programs into
conjunction with macros memory and executing them.
d) All of the mentioned 12. A system program that setup an executable program
in main memory ready for execution is
Answer: d a) Assembler
Explanation: A general-purpose macro processor or b) Linker
general purpose pre-processor is a macro …designed c) Loader
primarily for string manipulation, macro definition d) Load and go
8. Which of the following is a phase of a compilation
process? Answer: c
a) Lexical Analysis Explanation: a loader is the part of an operating system
b) Code Generation that is responsible for loading programs and libraries. It
c) Both of the mentioned is one of the essential stages in the process of starting a
d) None of the mentioned program, as it places programs into memory and prepares
them for execution
117
a) Assembler
. b) Linker
c) Loader
Machine Model-2 - d) Load and go
“Machine Model”.
1. Which of the following is a phase of a compilation Answer: c
process? Explanation: a loader is the part of an operating system
a) Lexical Analysis that is responsible for loading programs and libraries. It
b) Code Generation is one of the essential stages in the process of starting a
c) Both of the mentioned program, as it places programs into memory and prepares
d) None of the mentioned them for execution
6. Which of the following system program forgoes the
Answer: c production of object code to generate absolute machine
Explanation: Lexical analysis and code generation is a code and load it into the physical main storage location
phase of compilation process from which it will be executed immediately upon
2. System program such a s compiler are designed so that completion of the assembly?
they are a) Two pass assembler
a) Re-enterable b) Load and go assembler
b) Non reusable c) Macro processor
c) Serially usable d) Linker
d) None of the mentioned
Answer: b
Answer: a Explanation: Each pass scans the program, the first pass
Explanation: Re-enterable is the keyword for compiler generates the symbol table and the second pass generates
being designed the machine code
3. A series of statements explaining how the data is to be 7. Uniform symbol table
processed is called a) Has all constants in the program
a) Assembly b) Permanent table of rules in the form of patterns for
b) Machine matching with the uniform symbol table to discover
c) COBOL syntactic structure
d) Program c) Consists of full or partial list of the tokens as they
appear in the program created by Lexical analysis and
Answer: d used for syntax analysis and interpretation
Explanation: A program is a sequence of instructions, d) A permanent table which has all key words and special
written to perform a task by computer. It requires symbols of the language in symbolic form
programs to function, typically executing the program’s
instructions in a central processor. Answer: c
4. A loader is a program that Explanation: Each pass scans the program, the first pass
a) Program that places functions into memory and generates the symbol table and the second pass generates
prepares them for execution. the machine code.
b) Program that automates the translation of assembly 8. Assembler is a program that
language into machine language. a) Puts programs into memory and executes them
c) Program accepting another program written in a high b) Translates the assembly language into machine
level language and produces as object program language
d) None of the mentioned c) Writes in high level language and produces an object
program
Answer: a d) None of the mentioned
Explanation: A loader is the part of an operating system
that is responsible for loading programs and libraries. It Answer: b
is important in the process of placing the programs into Explanation: An assembler is a program that takes basic
memory and executing them. computer instructions and converts them into a pattern of
5. A system program that setup an executable program in bits that the computer’s processor can use to perform its
main memory ready for execution is basic operations.
118
program
. b) Assign storage to all temporary locations that are
necessary for intermediate results
Using DAG for Code Generation-1 - c) Assign storage to literals, and to ensure that the storage
“Using DAG for Code Generation”. is allocated and appropriate locations are initialized
1. The graph that shows basic blocks and their successor d) All of the mentioned
relationship is called
a) Dag Answer: d
b) Flow Graph Explanation: the storage assignment performs the above
c) Control Graph mentioned tasks
d) Hamilton Graph 6. A non relocatable program is the one which
a) Cannot execute in any area of storage other than the
Answer: B one designated
Explanation: Flow graph shows the basic blocks b) Consists of a program and information for its
2. The specific task storage manager performs relocation
a) Allocation/ deal location of programs c) None of the mentioned
b) Protection of storage area assigned to the program d) All of the mentioned
c) Both of the mentioned
d) None of the mentioned Answer: a
Explanation: A non relocatable program is one which
Answer: C cannot be made to execute in any area of storage other
Explanation: its basic function is that of the task storage than the one designated for it at the time of its coding or
manager translation.
3. When a computer is rebooted, a special type of loader 7. A relocatable program form is one which
is executed called a) Cannot execute in any area of storage other than the
a) Compile and GO ” loader one designated
b) Boot loader b) Consists of a program and information for its
c) Bootstrap Loader relocation
d) Relating Loader c) None of the mentioned
d) All of the mentioned
Answer: C
Explanation: A boot loader, is a small program that Answer: c
places the operating system (OS) of a computer into Explanation: A relocatable program form is one which
memory consists of a program and relevant information for its
4. Disadvantage of ” Compile and GO ” loading scheme relocation. Using this information it is possible to
is that relocate the program to execute from a storage area then
a) Memory is wasted because the case occupied by the the one designated for it at the time of its coding or
assembler is unavailable to the object program translation.
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 Advanced
d) All of the mentioned This set of Advanced Compilers focuses on “Using Dag
for Code Generation – 2”.
Answer: D 1. A self-relocating program is one which
Explanation: In computer programming, a compile and a) Cannot execute in any area of storage other than the
go system, compile, load, and go system, assemble and one designated
go system, or load and go system[1][2][3] is a b) Consists of a program and information for its
programming language processor in which the relocation
compilation, assembly, or link steps are not separated c) None of the mentioned
from program execution. d) All of the mentioned
5. Function of the storage assignment is
a) Assign storage to all variables referenced in the source
119
Answer: C b) Serially reusable module
Explanation: A self-relocating program is a program c) Re-enterable module
which can perform the relocation itself d) All of the mentioned
•A table of information about address sensitive
instruction in the program. Answer: a
•Relocating logic that can perform the relocation of the Explanation: Non reusable models can be used once for a
address sensitive instructions purpose they can’t be modified and used again
2. Scissoring enables 7. An intermediate code form is
a) A part of data to be displayed a) Postfix Notation
b) Entire data to be displayed b) Syntax Trees
c) Full data display on full screen c) Three address
d) No data to be displayed d) All of the mentioned
Answer: a Answer: d
Explanation: It displays a part of the data Explanation: all the specified options are type of
3. Which of the following can be accessed by transfer intermediate code form
vector approach of linking? 8. The best way to compare the different implementations
a) External data segments of symbol table is to compare the time required to
b) External sub-routines a) Add a new name
c) Data located in other procedure b) Make an enquiry
d) All of the mentioned c) Add a new name and make an enquiry
d) All of the mentioned
Answer: b
Explanation: External subroutines are routines that are Answer: d
created and maintained separately from the program that Explanation: These are the different implementations of
will be calling them the symbol table as mentioned above.
4. Relocation bits used by relocating loader are specified
by To practice Advanced on all areas of Compilers, .
a) Relocating loader itself Compilers – PeepHole Optimization-1
b) Linker “PeepHole Optimization”.
c) Assembler 1. Relocating bits used by relocating loader are specified
d) Macro processor by
a) Relocating loader itself
Answer: b b) Linker
Explanation: A linker or link editor is a computer c) Assembler
program that takes one or more object files generated by d) Macro Processor
a compiler and combines them into a single executable
file, library file, or another object file. Answer: b
5. Generation of intermediate code based on a abstract Explanation: Takes an object files and combines them
machine model is useful in compilers because into a single executable file, library file, or another object
a) Implementation of lexical analysis and syntax analysis file.
is made easier 2. What is the binary equivalent of the decimal number
b) Writing for intermediate code generation 368
c) Portability of the front end of the compiler a) 10111000
d) None of the mentioned b) 110110000
c) 111010000
Answer: A d) 111100000
Explanation: Intermediate code generator receives input
from its predecessor phase, semantic analyzer, in the Answer: b
form of an annotated syntax tree. Explanation: 368 binary equivalents is
6. Which of the following module does not incorporate 8=1000
initialization of values changed by the module? 6=0110
a) Non reusable module
120
3=0011 a) Ambiguous
So 1101101000 b) Unambiguous
3. AB+(A+B)’ is equivalent to c) Regular
a) A?B d) None of the mentioned
b) A+B
c) (A+B)A Answer: a
d) (A+B)B Explanation: ambiguous grammar has more than one
parse tree.
Answer: a 2. An optimizer Compiler
Explanation: It is equivalent to A? B a) Is optimized to occupy less space
4. A top down parser generates b) Both of the mentioned
a) Rightmost Derivation c) Optimize the code
b) Right most derivation in reverse d) None of the mentioned
c) Left most derivation
d) Left most derivation in reverse Answer: d
Explanation: In computing, an optimizing compiler is a
Answer: c compiler that tries to minimize or maximize some
Explanation: Top-down parsing is a parsing strategy attributes of an executable computer program
where one first looks at the highest level of the parse tree 3. The linker
and works down the parse tree by using the rewriting a) Is similar to interpreter
rules of a formal grammar. b) Uses source code as its input
5. Running time of a program depends on c) Is required to create a load module
a) Addressing mode d) None of the mentioned
b) Order of computations
c) The usage of machine idioms Answer: c
d) All of the mentioned Explanation: It is a program that takes one or more object
files generated by a compiler and combines them into a
Answer: d single executable file, library file, or another object file.
Explanation: Run time, runtime or execution time is the 4. A latch is constructed using two cross coupled
time during which a program is running (executing) a) AND OR gates
6. Which of the following is the fastest logic b) AND gates
a) TTL c) NAND and NOR gates
b) ECL d) NAND gates
c) CMOS
d) LSI Answer: d
Explanation: It has two inputs and one output
Answer: b 5. Pee Hole optimization
Explanation: In electronics, emitter-coupled logic (ECL) a) Loop Optimization
is a high-speed integrated circuit. b) Local Optimization
7. A bottom up parser generates c) Constant folding
a) Right most derivation d) Data Flow analysis
b) Rightmost derivation in reverse
c) Leftmost derivation Answer: c
d) Leftmost derivation in reverse Explanation: More loops are added
6. The optimization which avoids test at every iteration is
Answer: b a) Loop unrolling
Explanation: This corresponds to starting at the leaves of b) Loop jamming
the parse tree also known as shift-reduce parsing. c) Constant folding
d) None of the mentioned
PeepHole Optimization-2 -
“PeepHole Optimization”. Answer: a
1. A grammar that produces more than one parse tree for Explanation: Execution speed is enhanced by sacrificing
some sentence is called bits
121
7. 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
8. 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
122