Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

Multiple choice question for engineering

Set 1

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

View Answer

Answer: d [Reason:] Both in terms of semantics is not true.

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

View Answer

Answer: c [Reason:] LR >LALR>SLR In terms of parser

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

View Answer

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

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

View Answer

Answer: d [Reason:] The entire binary symbol gives the information

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

View Answer

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

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

View Answer

Answer: b [Reason:] Flow graph shows the basic blocks

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

View Answer

Answer: c [Reason:] its basic function is that of the task storage manager

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

View Answer

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

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

View Answer

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

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

View Answer

Answer: d [Reason:] the storage assignment performs the above mentioned tasks

Set 2

1.

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

The above 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?
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

View Answer

Answer: c [Reason:] 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.

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

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

View Answer

Answer: b [Reason:] 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 these

View Answer

Answer: C [Reason:] 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 ” ε}

View Answer

Answer: a [Reason:] 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 + *

View Answer

Answer: b [Reason:] 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

View Answer

Answer: d [Reason:] All the statements are true except option (D) 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)

 S ->AC | CB

b)

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

c)

 S -> ACCB

d)

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

View Answer

Answer: d [Reason:] 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

View Answer

Answer: a [Reason:] 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

View Answer

Answer: a [Reason:] 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

View Answer

Answer: a [Reason:] 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.

Set 3

1. Dynamic linking can cause security concerns because
a) Security is dynamic
b) None of the mentioned
c) Both of the mentioned
d) Cryptographic procedures are not available for dynamic linking

View Answer

Answer: d [Reason:] required by the program are linked during run time.

2. Which of the following statements is FALSE?
a) Both of the mentioned
b) In up-typed languages, values do not have any types
c) Dynamic languages have no variables types
d) None of the mentioned

View Answer

Answer: c [Reason:] they have dynamically changing types.

3. S -> C C
C -> eC | d
The grammar is
a) LL (1)
b) SLR (1) but not LL (1)
c) LALR (1) but not SLR (1)
d) LR (1) but not LALR (1)

View Answer

Answer: c [Reason:] The grammar is CLR and can be reduced to LALR

4. S -> id: = E ”
newtemp ();
gen(t . place . place;); .place t} ”
.place .place;}
For the statement ‘X: = Y + Z ’,
the 3-address code sequence generated by this definition is
a) X = Y + Z
b) t1 = Y + Z; X t1
c) t1 = Y; t2 = t1 + Z; X = t2
d) t1 = Y; t2 = Z; t3 + t2; X = t3

View Answer

Answer: d [Reason:] In 3-address code we use temporary variables

5. If the programming language uses static scoping and call by need parameter passing mechanism, the values printed by the above program are
a) 115, 220
b) 25, 220
c) 25, 15
d) 115, 105

View Answer

Answer: d [Reason:] So i = 100 & j = 5 P (i + j) = P (100 + 5) = P(105) So x = 105 x + 10 = 105 + 10 = 115 So 115 & 105 will be printed.

6. If dynamic scoping is used and call by name mechanism is used, the values printed will be
a) 115, 220
b) 25, 220
c) 25, 15
d) 115, 105

View Answer

Answer: b [Reason:] Since x = i + j & in P (x) i = 200 & j = 20 x = 200 + 20 = 220 & printing (x + 10) 9. = i + j + 10 = 10 + 5 + 10 = 25

7.

P x =new Q();
 Q y =new Q();
 P z =new Q(); 
x. f (1);((P) y). f (1);
z.f(1);

The output is
a) 1 2 1
b) 2 1 1
c) 2 1 2
d) 2 2 2

View Answer

Answer:d [Reason:] 1. Px = newQ(); 2. Qy = newQ(); 3. Pz = newQ(); 4. x : f(1); print 2 # i = 2 5. ((P) y) :f(1); 6. z : f(1) print 2 # i = 2 but line 5. will print 2 because typecast to parent class can’t prevent over ridding.

8. Which of the following is NOT an advantage of using shared, dynamically linked libraries as compared to statically linked libraries?
a) Smaller sizes of executable
b) Lesser overall page fault rate in the system
c) Faster program start-up
d) Existing programs need not be re-linked to take advantage of newer versions of libraries

View Answer

Answer: c [Reason:] No need for re-linking if newer versions of libraries are there.

9. Which grammar violate rules of an operator grammar?
(i) P-> QR
(ii) P -> Q s R
(iii) P -> ε
(iv) P ->Q t
a) (i) only
b) (i) and (iii) only
c) (ii) and (iii) only
d) (iii) and (iv) only

View Answer

Answer: b [Reason:] (I) P ” QR is not possible since two NT should include one operator as Terminal.

10. Consider the grammar rule
E -> E1 − E2 for arithmetic expressions.
If E1 and E2 do not have any common sub expression, in order to get the shortest possible code
a) E1 should be evaluated first
b) E2 should be evaluated first
c) Evaluation of E1 and E2 should necessarily be interleaved
d) Order of evaluation of E1 and E2 is of no consequence

View Answer

Answer: b [Reason:] E1 is to be kept in accumulator & accumulator is required for operations to evaluate E2.

Set 4

1. The grammar A ->AA |( A)| ε
is not suitable for predictive-parsing because the grammar is
a) Ambiguous
b) Left-recursive
c) Right-recursive
d) An operator-grammar

View Answer

Answer: a [Reason:] The grammar is ambiguous.

2. Consider the grammar
E ->E + n | E # n | n
For a sentence n + n, form of the reduction are
a) n, E + n and E + n # n
b) n , E + n and E + E # n
c) n , n + n and n + n # n
d) n , E + n and E # n

View Answer

Answer: d [Reason:] during reduction the order is reverse. So {E ” n , E ” E + n, E ” E # n}

3. S -> (S)| a
Let the number of states in SLR(1), LR(1) and LALR(1) parsers for the grammar n1 n2 and n3 respectively.
a) n1 < n2 < n3
b) n1 = n3 < n2
c) n1 = n2 = n3
d) n1 $ n3 $ n2

View Answer

Answer: b [Reason:] The no. of states for SLR(1) & LALR(1) are equal so n 1 = n3, but CLR(1) or LR(1) will have no. of states greater than LALR & LR(0) both.

4. Consider line 3

Int main()
{ int 1,N;
Fro (I,1 N,1);
}

Identify the compiler’s response about this line while creating the object-module
a) No compilation error
b) Only a lexical error
c) Only syntactic errors
d) Both lexical and syntactic errors

View Answer

Answer: c [Reason:] 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?
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

View Answer

Answer: c [Reason:] Yacc tool is used to create a LALR(1) parser.

6. What precedence and associativity properties does the generated parser realize?
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

View Answer

Answer: b [Reason:] The grammar has equal precedence and it is also ambiguous.

7. 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) (i) and (ii)
b) (ii) and (iii)
c) (i) and (iii)
d) None of these

View Answer

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

8. 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 ” ε}

View Answer

Answer: a [Reason:] 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 “!}

9. 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 + *

View Answer

Answer: b [Reason:] 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

10. Consider the following C code segment.
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

View Answer

Answer: d [Reason:] All the statements are true except option last since there is no dead code to get eliminated.

Set 5

1. Which of these is also known as look-head LR parser?
a) SLR
b) LR
c) LLR
d) None of the mentioned

View Answer

Answer: c [Reason:] LLR is the look ahead parser.

2. What is the similarity between LR, LALR and SLR?
a) Use same algorithm, but different parsing table.
b) Same parsing table, but different algorithm.
c) Their Parsing tables and algorithm are similar but uses top down approach.
d) Both Parsing tables and algorithm are different.

View Answer

Answer: a [Reason:] The common grounds of these 3 parser is the algorithm but parsing table is different

3. An LR-parser can detect a syntactic error as soon as
a) The parsing starts
b) It is possible to do so a left-to-right scan of the input.
c) It is possible to do so a right-to-left scan of the input.
d) Parsing ends

View Answer

Answer: b [Reason:] Error is found when it the input string is scanned

4. Which of these is true about LR parsing?
a) Is most general non-backtracking shift-reduce parsing
b) It is still efficient
c) Both a and b
d) None of the mentioned

View Answer

Answer: c [Reason:] LR parsers are a type of bottom-up parsers that efficiently handle deterministic context-free languages in guaranteed linear time.

5. Which of the following is incorrect for the actions of A LR-Parser I) shift s ii) reduce A->ß iii) Accept iv) reject?
a) Only I)
b) I) and ii)
c) I), ii) and iii)
d) I), ii) , iii) and iv)

View Answer

Answer: c [Reason:] Only reject out of the following is a correct LR parser action

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
c) Shift conflict
d) Reduce conflict

View Answer

Answer: a [Reason:] As the name suggests that the conflict is between shift and reduce hence it is called shift reduce conflict

7. When there is a reduce/reduce conflict?
a) If a state does not know whether it will make a shift operation using the production rule i or j for a terminal.
b) If a state does not know whether it will make a shift or reduction operation using the production rule i or j for a terminal.
c) If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal.
d) None of the mentioned

View Answer

Answer: c [Reason:] It occurs when If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal.

8. When ß ( in the LR(1) item A -> ß.a,a ) is not empty, the look-head
a) Will be affecting.
b) Does not have any affect.
c) Shift will take place.
d) Reduction will take place.

View Answer

Answer: b [Reason:] There is no terminal before the non terminal beta

9. When ß is empty (A -> ß.,a ), the reduction by A-> a is done
a) If next symbol is a terminal
b) Only If the next input symbol is a
c) Only If the next input symbol is A
d) Only if the next input symbol is a

View Answer

Answer: d [Reason:] The next token is considered in this case it’s a

10. The construction of the canonical collection of the sets of LR (1) items are similar to the construction of the canonical collection of the sets of LR (0) items. Which is an exception?
a) Closure and goto operations work a little bit different
b) Closure and goto operations work similarly
c) Closure and additive operations work a little bit different
d) Closure and associatively operations work a little bit different

View Answer

Answer: a [Reason:] Closure and goto do work differently in case of LR (0) and LR (1)