250+ TOP MCQs on Symbol Table Organization and Answers

Compilers Assessment Questions and Answers on “Symbol Table Organization”.

1. Generally Dynamic RAM is used as main memory in a computer system as it ____________
a) Consumes less power
b) Has higher speed
c) Has lower cell density
d) Needs refreshing circuitry

Answer: b
Clarification: Because of higher speed it is Dynamic.

2. Write Through technique is used in which memory for updating the data ___________
a) Virtual memory
b) Main memory
c) Auxiliary memory
d) Cache memory

Answer: d
Clarification: The answer is cache memory.

3. Cache memory acts between __________
a) CPU and RAM
b) RAM and ROM
c) CPU and Hard Disk
d) None of the mentioned

Answer: a
Clarification: It acts between CPU and RAM.

4. The circuit used to store one bit of data is known as __________
a) Encoder
b) OR gate
c) Flip Flop
d) Decoder

Answer: c
Clarification: Flip flop is 1 bit circuit.

5. Von Neumann architecture is __________
a) SISD
b) SIMD
c) MIMD
d) MISD

Answer: a
Clarification: It is single instruction single data.

6. In a vectored interrupt ____________
a) The branch address is assigned to a fixed location in memory
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
d) None of the mentioned

Answer: b
Clarification: It branches to process the interrupt.

7. In a memory-mapped I/O system, which of the following will not be there?
a) LDA
b) IN
c) ADD
d) OUT

Answer: a
Clarification: There is no LDA.

8. If memory access takes 20 ns with cache and 110 ns without it, then the ratio (cache uses a 10 ns memory) is __________
a) 93%
b) 90%
c) 88%
d) 87%

Answer: b
Clarification: The answer is 90%.

9. The addressing mode used in an instruction of the form ADD X Y is ________
a) Absolute
b) Indirect
c) Index
d) None of the mentioned

Answer: c
Clarification: This addressing mode is indexed.

10. _________ register keeps track of the instructions stored in program stored in memory.
a) AR (Address Register)
b) XR (Index Register)
c) PC (Program Counter)
d) AC (Accumulator)

Answer: c
Clarification: Program Counter keeps track of the next instruction.

250+ TOP MCQs on Cross Compiler and Answers

Compilers Multiple Choice Questions on “Cross Compiler”.

1. If we compile the sam.c file with the command “gcc -o sam sam.c”, then the executable file will be?
a) a.out
b) sam
c) sam.out
d) None of the mentioned

Answer: b
Clarification: This is how the GCC is designed to take names of executable files.

2. What will be output of the following code?

#include
int main()
{
    printf("%dt",sizeof(6.5));
    printf("%dt",sizeof(90000));
    printf("%d",sizeof('A'));
    return 0;
}

a) 8 4 2
b) 8 4 2
c) 8 4 4
d) 8 4 3

Answer: c
Clarification: GCC compilers (32 bit compilers) size of:
double is 8 byte
long int is 8 byte
Character constant is 2 byte.

3. What will be output of the following c code? ( according to GCC compiler)

#include
int main()
{
    signed x;
    unsigned y;
    x = 10 +- 10u + 10u +- 10;
    y = x;
    if(x==y)
         printf("%d %d",x,y);
    else if(x!=y)
         printf("%u  %u",x,y);
    return 0;
}

a) 0 0
b) 65536 -10
c) 0 65536
d) Compilation error

Answer: a
Clarification: Consider on the expression:
x = 10 +- 10u + 10u +- 10;
10: It is signed integer constant.
10u: It is unsigned integer constant.
X: It is signed integer variable.
As we know operators enjoy higher precedence than binary operators. So
x = 10 + (-10u) + 10u + (-10);
= 10 + -10 + 10 + (-10);
= 0
So, Corresponding signed value of unsigned 10u is +10.

4. What will be output of the following c code?

#include
int main()
{
    const int *p;
    int a=10;
    p=&a;
    printf("%d",*p);
    return 0;
}

a) 0
b) 10
c) Garbage Value
d) Any Memory address

Answer: b
Clarification: In the following declaration
const int *p;
p can keep address of constant integer.

5. What will be output of the following c code?

#include
int main()
{
    int a= sizeof(signed) +sizeof(unsigned);
    int b=sizeof(const)+sizeof(volatile);
    printf("%d",a+++b);
    return 0;
}

a) 10
b) 9
c) 8
d) Error

Answer: c
Clarification: Default data type of signed, unsigned, const and volatile is intSo, a = 4 and b =4
Now, a+++b
= a++ + b
= 4 + 4 //due to post increment operator.
=8
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?
a) void
b) char
c) float
d) double

Answer: b
Expanation: In c char is integral data type. It stores the ASCII value.

7. What will be output of the following c code?

#include
int main()
{
    volatile int a=11;
    printf("%d",a);
    return 0;
}

a) 11
b) Garbage
c) -2
d) Cannot Predict

Answer: d
Clarification: Value of volatile variable can’t be predicted because its value can be changed by any microprocessor interrupt.

8. What will be output of the following c code?

#include
const enum Alpha
{
      X,
      Y=5,
      Z
}p=10;
int main()
{
    enum Alpha a,b;
    a= X;
    b= Z;
    printf("%d",a+b-p); 
    return 0; 
}

a) -4
b) -5
c) 10
d) 11

Answer: a
Clarification: Default value X is zero and
Z = Y + 1 = 5 + 1 = 6
So, a + b – p
=0 + 6 -10 = -4.

250+ TOP MCQs on The NFA with epsilon-moves to the DFA and Answers

Compilers Interview Questions and Answers for Experienced people 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
d) P is not closed under union & NP is not closed under intersection

Answer: d
Clarification: Both P and NP are closed under each of these operations.

2. Ndfa and dfa accept same languages.
a) True
b) False

Answer: a
Clarification: They both are equivalent.

3. __________ a part of a compiler that is responsible for recognizing syntax.
a) Parser
b) Bzr
c) Linker
d) Optimizer

Answer: a
Clarification: Parser recognises all the syntax of the language.

4. __________ a part of a compiler that takes as input a stream of characters and produces as output a stream of words along with their associated syntactic categories.
a) Parser
b) Optimizer
c) Scanner
d) None of the mentioned

Answer: c
Clarification: A compiler’s scanner reads an input stream that consists of characters and produces an output stream that contains words, each labelled with its Syntactic category.

5. _________an IR-to-IR transformer that tries to improve the IR program in some way.
a) Optimizer
b) Parser
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: The optimizer is an IR-to-IR transformer that tries to improve the IR program in some way.

6. _________ a phase of a compiler that maps the IR program into the instruction set and the finite resources of the target machine.
a) Optimizer
b) Parser
c) Optimizer & Parser
d) None of the mentioned

Answer: d
Clarification: In a two-phase compiler, ensures that there is 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

Answer: a
Clarification: nfa has n then dfa has at max 2^n.

8. An NFA is nothing more than an ε-NFA with no ε transitions.
a) True
b) False

Answer: a
Clarification: An NFA is nothing more than an ε-NFA with no ε transitions. Thus • δ (q, ε) for all states q = ∅.

9. For every DFA, there is an ε-NFA that accepts the same language.
a) True
b) False

Answer: a
Clarification: For every DFA, there is an ε-NFA that accepts the same language and Vice Versa.

10. DFAs, NFAs, and ε-NFA s are equivalent.
a) True
b) False

Answer: a
Clarification: For every NFA there is an ε-NFA that accepts a similar language and vice versa.

Global Education & Learning Series – Compilers.

To practice all areas of Compilers for Interviews, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

250+ TOP MCQs on Top-Down Parsing and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Predictive Top-Down Parsing”.

1. Find the TRUE statement?

I.  There exist parsing algorithms for some programming languages which has O(3) complexity.
II.  A programming language which allows recursion can be implemented with static storage allocation.
III. No L-attributed definition can be evaluated in The framework of bottom-up parsing.
IV. Code improving transformations can be performed at both intermediate code level and source Language.

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

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

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

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

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

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

4. Which of the following is TRUE?
a) Both P and Q are true
b) P is true and Q is false
c) P is false and Q is true
d) Both P and Q are false

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

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

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

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

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

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

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

7. Consider the grammar.

E → E + n | E × n | n 

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

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

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

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

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

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

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

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

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

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

250+ TOP MCQs on Intermediate Code-Generation and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Intermediate code-Generation”.

1. The below grammar and the semantic rules are fed to a yacc tool (which is an LALR (1) parser generator) for parsing and evaluating arithmetic expressions. Which one of the following is true about the action of yacc for the given grammar?

 E -> number   Eval           number val 
     E         E .val         E .VAL           E .val 
    E # E      E .val         E .VAL           E .val 
     ;

a) It detects recursion and eliminates recursion
b) It detects reduce-reduce conflict and resolves
c) It detects shift-reduce conflict and resolves the conflict in favor of a shift over a reduce action
d) It detects shift-reduce conflict and resolves the conflict in favor of a reduce over a shift action

Answer: c
Clarification: Yacc tool is used to create a LALR (1) parser. This parser can detect the conflicts but to resolve the conflicts it actually prefers shift over reduce action.

2. Assume the conflicts part (a) of this question are resolved and an LALR (1) parser is generated for parsing arithmetic expressions as per the given grammar. Consider an expression 3 # 2 + 1. What precedence and associativity properties does the generated parser realize?

  E -> number        Eval               number val 
   E                 E .val             E .VAL                  E .val 
  E # E              E .val             E .VAL                  E .val 
   ;

a) Equal precedence and left associativity; expression is evaluated to 7
b) Equal precedence and right associativity, expression is evaluated to 9
c) Precedence of ‘x’ is higher than that of ‘+’, and both operators are left associative; expression is evaluated to 7
d) Precedence of ‘ # ‘ is higher than that of ‘#’, and both operators are left associative; expression is evaluated to 9

Answer: b
Clarification: The grammar has equal precedence and it is also ambiguous. Since LALR (1) parser prefer shift over reduce so + operation will be executed here before). 2 + 1 = 3 & 3 # 3 = 9 also the operators are right associative.

3. Consider the following grammar.

S -> S * E
S -> E 
E -> F + E 
E -> F 
F -> id

Consider the following LR (0) items corresponding to the grammar above.

(i) S -> S * .E 
(ii) E -> F. + E 
(iii) E “F + .E

Given the items above, which two of them will appear in the same set in the canonical sets-of-items for the grammar?
a) (ii)
b) (i) and (iii)
c) (iii)
d) None of the mentioned

Answer: c
Clarification: If S -> S): E is in LR (0) then E -> F +: E will also be there because both of them has ‘: ‘ before E.

4. Consider the following grammar:

S -> FR 
R -> * S | ε 
F -> id

In the predictive parser table, M, of the grammar the entries M [S, id] and M [R, $] respectively.
a) {S ” FR} and {R ” ε}
b) {S ” FR} and {}
c) {S ” FR} and {R ” * S}
d) {F ” id} and {R ” ε}

Answer: a
Clarification: The predictive parser table is given as. Non Terminal) id $ S S “FR F F “id R R “) S R “! R “! So at M [ S, id] = { S ” FR} M [ R,$] = {R “!}.

5. Consider the following translation scheme.

S -> ER 
R -> * E{print{’ * ’);
R | f 
E -> F + E{print(’ + ’); | F 
F -> (S) | id{print(id.value);}

Here id is a taken that represents an integer and id. value represents the corresponding integer value. For an input ‘2 * 3 + 4’, this translation scheme prints?
a) 2 * 3 + 4
b) 2 * + 3 4
c) 2 3 * 4 +
d) 2 3 4 + *

Answer: b
Clarification: Input string 2 ) 3 + 4 S ” ER FR idR {print(2)} id)ER {print())} id) F+ER {print(+)}id) id + ER {print(3)} id) id ) id +id So 2 )+ 3 4 are printed.

6. Consider the following C code segment.

for for if i # i } } }

Which one to the following false?
a) The code contains loop-in variant computation
b) There is scope of common sub-expression elimination in this code
c) There is scope strength reduction in this code
d) There is scope of dead code elimination in this code

Answer: d
Clarification: All the statements are true except option (There is scope of dead code elimination in this code ) since there is no dead code to get eliminated.

7. Which one of the following grammars generates the language L = (a i b i | i ! j}?
a)

b)

S -> aS | Sb | a | b 
C -> aCb | a | b 
A -> aA | ε 
B -> Bb | ε

c)

d)

S -> AC | CB 
C -> aCb |!
C -> aCb |! 
A -> aA |! 
A -> aA | a 
B -> Bb |! 
B -> bB | b

View Answer

Answer: d
Clarification: The grammar S -> AC CB
C ->aCb !
A ->aA a
B->” bB b
Consider string aaabb S -> AC AaCb AaaCbb Aaabb aaabb But string aabb S ” AC And ->his string is not derivable.

8. In the correct grammar above, what is the length of the derivation (number of steps starting from S to generate the string a l b m with l ! m?
a) max (l, m) + 2
b) l+m+2
c) l + m + 3
d) max (l, m) + 3

Answer: a
Clarification: It is very clear from the previous solution that the no. of steps required depend upon the no. of a’ s & b ‘ s which ever is higher & exceeds by 2 due to S ” AC CB & C “! So max(l , m) + 2.

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

Answer: a
Clarification: Clearly LR & LALR are not top down they are bottom up passers. Also not operator precedence parser. ut yes recursive descent parser is top down parser. Starts from start symbol & derives the terminal string.

10. Consider the grammar with non-terminals.

N = {S , C , S}, terminals T = {a, b , i , t, e}, with S as the start symbol, and the following of rules 
S -> iCtSS1 | a 
S1 -> eS | ε 
C -> b

The grammar is NOTLL(1) because ________
a) It is left recursive
b) It is right recursive
c) It is ambiguous
d) It is not context-free

Answer: a
Clarification: The grammar has production S ” iCtSS1 here the right hand side of grammar has the same symbol as left side. So the grammar is left recursive. The grammar is not ambiguous.

250+ TOP MCQs on Storage Allocation and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Storage Allocation”.

1. The idea of cache memory is based __________
a) On the property of locality of reference
b) On the heuristic 90-10 rule
c) On the fact that references generally tend to cluster
d) All of the mentioned

Answer: a
Clarification: Cache memory is based on the locality of references.

2. Which of the following is not a weighted code?
a) Decimal Number system
b) Excess 3-cod
c) Binary number System
d) None of the mentioned

Answer: b
Clarification: Excess 3 is not a weighted code.

3. The average time required to reach a storage location in memory and obtain its contents is called the _____
a) Seek time
b) Turnaround time
c) Access time
d) Transfer time

Answer: c
Clarification: Times used to access the contents.

4. (2FAOC) 16 is equivalent to __________
a) (195 084)10
b) (001011111010 0000 1100)2
c) (195 084)10 & (001011111010 0000 1100)2
d) None of the mentioned

Answer: b
Clarification: It is equivalent to (001011111010 0000 1100)2.

5. The circuit used to store one bit of data is known as_______
a) Register
b) Encoder
c) Decoder
d) Flip Flop

Answer: d
Clarification: 1 bit circuit is known as Flip Flop.

6. Computers use addressing mode techniques for ____________
a) Giving programming versatility to the user by providing facilities as pointers to memory counters for loop control
b) To reduce number of bits in the field of instruction
c) Specifying rules for modifying or interpreting address field of the instruction
d) All of the mentioned

Answer: d
Clarification: All of these are addressing mode techniques.

7. What characteristic of RAM memory makes it not suitable for permanent storage?
a) Too slow
b) Unreliable
c) It is volatile
d) Too bulky

Answer: c
Clarification: Ram is volatile.

8. The amount of time required to read a block of data from a disk into memory is composed of seek time, rotational latency, and transfer time. Rotational latency refers to ______
a) The time it takes for the platter to make a full rotation
b) The time it takes for the read-write head to move into position over the appropriate track
c) The time it takes for the platter to rotate the correct sector under the head
d) None of the mentioned

Answer: a
Clarification: Rotational latency is the time taken to make full rotation.