Question 1
Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation (SDT) actions, given as pseudo-code:
P 𔪠D* E*
D 𔪠int ID {record that ID.lexeme is of type int}
D 𔪠bool ID {record that ID. lexeme is of type bool}
E 𔪠E1 + E2 {check that E1.type = E2.type = int; set E.type := int}
E 𔪠!E1 {check that E1 type = bool; set E.type = bool}
E 𔪠ID {set E.Type := int}
With respect to the above grammar, which one of the following choices is correct? [GATE 2021|| SET-1 MCQ|| 1-mark]
The actions can be used to type-check syntactically correct integer variable declarations and integer expressions.
The actions can be used to correctly type-check any syntactically correct program.
The actions can be used to type-check syntactically correct Boolean variable declarations and Boolean expressions
The actions will lead to an infinite loop.
Question 2
Consider the following ANSI C program:
int main() {
Integer x;
return 0;
}
Which one of the following phases in a seven-phase C compiler will throw an error? [GATE 2021|| SET-2 MCQ|| 1-mark]
Lexical analyzer
Machine dependent optimizer
Semantic analyzer
Syntax analyzer
Question 3
Consider the following statements.
I. Symbol table is accessed only during lexical analysis and syntax analysis.
II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
III. Errors violating the condition āany variable must be declared before its useā are detected during syntax analysis.
Which of the above statements is/are TRUE? [GATE 2020|| MCQ|| 1-mark]
II only
I only
I and III only
None of I, II and III
Question 4
Consider the production A ->PQ and A -> XY. Each of the five non-terminals A, P, Q, X and Y has two attributes:
s is a synthesized attribute, and i is an inherited attribute. Consider the following rules:-
Rule 1 : P, i = A.i + 2, Q.i = P.i + A.i and A.s = P.s + Q.s
Rule 2 : X.i = A.i + Y.s and Y.i = X.s + A.i
Which one of the following is TRUE? [GATE 2020|| MCQ|| 2-mark]
Only Rule 2 is L-attributed.
Neither Rule 1 nor Rule 2 is L-attributed.
Both Rule 1 and Rule 2 are L-attributed.
Only Rule 1 is L-attributed.
Question 5
Consider the following grammar and the semantic actions to support the inheriteated type declaration attributes. Let X1, X2, X3, X4, X5 and X6 be the placeholders for the non-terminals D, T, L or L1 in the following table :
Production rule | Semantic action |
D | X1.type = X2.type |
T | T.type = int |
T | T.type = float |
L | X3.type = X4.type addType(id.entry, X5.type) |
L | addType(id.entry, X6.type) |
Which one of the following are the appropriate choices for X1, X2, X3 and X4? [GATE 2019 || MCQ|| 2-mark]
X1 = L, X2 = L, X3 = L1, X4 = T
X1 = L, X2 = T, X3 = L1, X4 = L
X1 = T, X2 = L, X3 = L1, X4 = T
X1 = T, X2 = L, X3 = T X4 = L1
Question 6
Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a,b}.
S ā aA { print 1 }
S ā a { print 2 }
A ā Sb { print 3 }
Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:
[GATE 2016|| SET-1 MCQ|| 2-mark]
1 3 2
2 2 3
2 3 1
syntax error
Question 7
Given the following syntax-directed translation rules: [GATE 2025|| SET-2 MCQ|| 1-mark ]

Which ONE is the CORRECT option among the following?
Rule 1 : is S-attributed and L-attributed; Rule 2 is S-attributed and not L-attributed; Rule 3 is neither S-attributed nor L-attributed
Rule 1 : is neither S-attributed nor L-attributed; Rule 2 is S-attributed and L-attributed; Rule 3 is S-attributed and L-attributed.
Rule 1 : is neither S-attributed nor L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed.
Rule 1 : is S-attributed and not L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed.
Question 8
Consider the following grammar along with translation rules.

Here # and % are operators and id is a token that represents an integer and id.val represents the corresponding integer value.
The set of non-terminals is {S, T, R, P} and a subscripted non-terminal indicates an instance of the non-terminal.
Using this translation scheme, the computed value of S.val for root of the parse tree for the expression
20#10%5#8%2%2 is ______. [GATE 2022|| NAT || 2-mark]
80
Question 9
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

The value computed by the translation scheme for the input string: 10#011
is ____________. (Rounded off to three decimal places) [GATE 2023|| NAT || 2-mark]
2.375
Question 10
Consider the following syntax-directed definition (SDD)

Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute S.val)?
[GATE 2024|| SET-1 MCQ|| 1-mark]
45
50
55
60
There are 11 questions to complete.