SDT(Syntax-Directed Translation) PYQ QUIZ GATE CS

Last Updated :
Discuss
Comments

Question 1

Consider two binary operators '

[Tex]\uparrow[/Tex]

' and '

[Tex]\downarrow[/Tex]

' with the precedence of operator

[Tex]\downarrow[/Tex]

being lower than that of the

[Tex]\uparrow[/Tex]

operator. Operator

[Tex]\uparrow[/Tex]

is right associative while operator

[Tex]\downarrow[/Tex]

is left associative. Which one of the following represents the parse tree for expression (7

[Tex]\downarrow[/Tex]

3 ­

[Tex]\uparrow[/Tex]

4 ­

[Tex]\uparrow[/Tex]

3

[Tex]\downarrow[/Tex]

2)?

  • A

  • B

  • C

  • D

Question 2

S -> aSa|bSb|a|b; The language generated by the above grammar over the alphabet {a,b} is the set of

  • All palindromes

  • All odd length palindromes.

  • Strings that begin and end with the same symbol

  • All even length palindromes

Question 3

Which of the following statements are TRUE?

I.  There exist parsing algorithms for some programming languages 
whose complexities are less than O(n3).
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 source
language and intermediate code level.
  • I and II

  • I and IV

  • III and IV

  • I, III and IV

Question 4

Consider the CFG with {S,A,B) as the non-terminal alphabet, {a,b) as the terminal alphabet, S as the start symbol and the following set of production rules

S --> aB        S --> bA
B --> b A --> a
B --> bS A --> aS
B --> aBB A --> bAA

Which of the following strings is generated by the grammar?

  • aaaabb

  • aabbbb

  • aabbab

  • abbbba

Question 5

A student wrote two context-free grammars G1 and G2 for generating a single C-like array declaration. The dimension of the array is at least one. For example,

int a[10][3]; 

The grammars use D as the start symbol, and use six terminal symbols int ; id [ ] num.

Grammar G1
D → int L;
L → id [E
E → num]
E → num] [E

Grammar G2
D → int L;
L → id E
E → E[num]
E → [num]

Which of the grammars correctly generate the declaration mentioned above?

  • Both G1 and G2

  • Only G1

  • Only G2

  • Neither G1 nor G2

Question 6

Consider the following expression grammar G.

E -> E - T | T
T -> T + F | F
F -> (E) | id

Which of the following grammars are not left recursive, but equivalent to G.

A)
E -> E - T | T
T -> T + F | F
F -> (E) | id

B)
E -> TE'
E' -> -TE' | ε
T -> T + F | F
F -> (E) | id

C)
E -> TX
X -> -TX | ε
T -> FY
Y -> +FY | ε
F -> (E) | id

D)
E -> TX | (TX)
X -> -TX | +TX | ε
T -> id

  • A

  • B

  • C

  • D

Question 7

Consider the following grammar and the semantic actions to support the inherited 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:

8

Which one of the following are the appropriate choices for X1, X2, X3 and X4?

  • X1 = L, X2 = T, X3 = L1, X4 = L

  • X1 = L, X2 = L, X3 = L1, X4 = T

  • X1 = T, X2 = L, X3 = L1, X4 = T

  • X1 = T, X2 = L, X3 = T, X4 = L1

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 _____________. 

  • 60

  • 55

  • 75

  • 80

Question 9

Consider the translation scheme shown below

S → T R
R → + T {print ('+');} R | ε
T → num {print (num.val);}

Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will print

  • 9 + 5 + 2

  • 9 5 + 2 +

  • 9 5 2 + +

  • + + 9 5 2

Question 10

In a bottom-up evaluation of a syntax directed definition, inherited attributes can

  • always be evaluated

  • be evaluated only if the definition is L-­attributed

  • be evaluated only if the definition has synthesized attributes

  • never be evaluated

There are 30 questions to complete.

Take a part in the ongoing discussion