Compiler Design

Compiler Design Questions Answers GATE 2023

Compiler Design GATE Question Answers with Explanation.

Q1 – Consider the following statements regarding the front-end and back-end of a compiler.
S1: The front-end includes phases that are independent of the target hardware.
S2: The back-end includes phases that are specific to the target hardware.
S3: The back-end includes phases that are specific to the programming language used in the source code.
Identify the CORRECT option. (GATE 2023)
1. Only S1 is TRUE.
2. Only S1 and S2 are TRUE.
3. S1, S2, and S3 are all TRUE.
4. Only S1 and S3 are TRUE.

Ans – (2)

Explanation – 

Q2 – Consider the following program:
Q26 GATE 2023
Which one of the following options represents the activation tree corresponding to the main function? (GATE 2023)
Q26 GATE 2023 (1)

Ans – (1)

Explanation

Q3 – Consider the control flow graph shown.
Control flow graph
Which one of the following choices correctly lists the set of live variables at the exit point of each basic block? (GATE 2023)
1. B1: {}, B2: {a}, B3: {a}, B4: {a}
2. B1: {i, j}, B2: {a}, B3: {a}, B4: {i}
3. B1: {a, i, j}, B2: {a, i, j}, B3: {a, i}, B4: {a}
4. B1: {a, i, j}, B2: {a, j}, B3: {a, j}, B4: {a, i, j}

Ans – (4)

Explanation

Q4 – Consider the context-free grammar G below
S → aSb | X
X → aX | Xb | a | b,
where S and X are non-terminals, and a and b are terminal symbols. The starting non-terminal is S.
Which one of the following statements is CORRECT? (GATE 2023)
1. The language generated by G is (a + b)∗
2. The language generated by G is a∗(a + b)b∗
3. The language generated by G is a∗b∗(a + b)
4. The language generated by G is not a regular language

Ans – (2)

Explanation

Q5 – Consider the syntax directed translation given by the following grammar and semantic rules. Here N, I, F and B are non-terminals. N is the starting non-terminal, and #, 0 and 1 are lexical tokens corresponding to input letters “#”, “0” and “1”, respectively. X.val denotes the synthesized attribute (a numeric value) associated with a non-terminal X.
I1 and F1 denote occurrences of I and F on the right-hand side of a production, respectively. For the tokens 0 and 1, 0.val = 0 and 1.val = 1.
N → I #F     N.val = I.val + F.val
I → I1B       I.val = (2 I1.val) + B.val
I → B          I.val = B.val
F → BF1      F.val = 1/2 (B.val + F1.val )
F → B         F.val = 1/2B.val
B → 0         B.val = 0.val
B → 1         B.val = 1.val
The value computed by the translation scheme for the input string
                                 10#011
is ________. (Rounded off to three decimal places) (GATE 2023)

Ans – (2.374 to 2.376)

Explanation