Compiler Design questions

Q15

GATE CS 2015 CS-3ParsingMCQ1 mark−1/3 if wrong
Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the most powerful, in that order?
Show answer without attempting

Answer: C

Q58

GATE CS 2015 CS-3Optimization and Data FlowMCQ2 marks−2/3 if wrong
Consider three software items: Program-X, Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown below

Program-X:
sumcal(int maxint, int value)
{
    int result=0, i=0;
    if (value < 0)
    {
        value = -value;
    }
    while((i<value) AND (result <= maxint))
    {
        i=i+1;
        result = result + 1;
    }
    if (result <= maxint)
    {
        printf(result);
    }
    else
    {
        printf("large");
    }
    printf("end of program");
}
Control Flow Diagram of Program-Y: shown in the figure.

Control Flow Diagram of Program-Z: the Control Flow Diagram of Program-X followed by (with an arrow into) the Control Flow Diagram of Program-Y.

The values of McCabe's Cyclomatic complexity of Program-X, Program-Y, and Program-Z respectively are
Question figure
Show answer without attempting

Answer: A

Q65

GATE CS 2015 CS-3ParsingMCQ2 marks−2/3 if wrong
Consider the following grammar GG

S→F∣HF→p∣cH→d∣c \begin{array}{rcl} S & \to & F \mid H \\ F & \to & p \mid c \\ H & \to & d \mid c \end{array}

where S,FS, F, and HH are non-terminal symbols, p,dp, d, and cc are terminal symbols. Which of the following statement(s) is/are correct?

S1. LL(1) can parse all strings that are generated using grammar GG
S2. LR(1) can parse all strings that are generated using grammar GG
Show answer without attempting

Answer: D

Q18

GATE CS 2015 CS-1ParsingMCQ1 mark−1/3 if wrong
Which one of the following is TRUE at any valid state in shift-reduce parsing?
Show answer without attempting

Answer: C

Q38

GATE CS 2015 CS-1Optimization and Data FlowNAT2 marks
Consider the following C program segment.
while (first <= last)
{
    if (array[middle] < search)
        first = middle + 1;
    else if (array[middle] == search)
        found = TRUE;
    else last = middle - 1;
    middle = (first + last)/2;
}
if (first > last) notPresent = TRUE;
The cyclomatic complexity of the program segment is ________.
Show answer without attempting

Answer: 5

Q46

GATE CS 2015 CS-1Optimization and Data FlowMCQ2 marks−2/3 if wrong
A variable xx is said to be live at a statement SiS_i in a program if the following three conditions hold simultaneously:

i. There exists a statement SjS_j that uses xx
ii. There is a path from SiS_i to SjS_j in the flow graph corresponding to the program
iii. The path has no intervening assignment to xx including at SiS_i and SjS_j

(Control flow graph: block 1: p=q+rp = q + r, s=p+qs = p + q, u=s∗vu = s * v; block 2: v=r+uv = r + u; block 3: q=s∗uq = s * u; block 4: q=v+rq = v + r; edges 1→2, 1→3, 2→4, 3→4, 4→1.)

The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are
Question figure
Show answer without attempting

Answer: C

Q47

GATE CS 2015 CS-1Intermediate CodeNAT2 marks
The least number of temporary variables required to create a three-address code in static single assignment form for the expression q+r/3+s−t∗5+u∗v/wq + r/3 + s - t * 5 + u * v/w is ________.
Show answer without attempting

Answer: 8

Q27

GATE CS 2015 CS-2Lexical AnalysisMCQ1 mark−1/3 if wrong
Match the following:

P. Lexical analysis
Q. Parsing
R. Register allocation
S. Expression evaluation

1. Graph coloring
2. DFA minimization
3. Post-order traversal
4. Production tree
Show answer without attempting

Answer: C

Q28

GATE CS 2015 CS-2Intermediate CodeMCQ1 mark−1/3 if wrong
In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is TRUE?
Show answer without attempting

Answer: C

Q44

GATE CS 2015 CS-2Intermediate CodeMCQ2 marks−2/3 if wrong
Consider the intermediate code given below.
(1)  i = 1
(2)  j = 1
(3)  t1 = 5 * i
(4)  t2 = t1 + j
(5)  t3 = 4 * t2
(6)  t4 = t3
(7)  a[t4] = -1
(8)  j = j + 1
(9)  if j<=5 goto (3)
(10) i=i+1
(11) if i<5 goto (2)
The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are
Show answer without attempting

Answer: B

0/100 correct0 marks

Related topics in GATE CS