Syntax Directed Translation MCQ Quiz in मल्याळम - Objective Question with Answer for Syntax Directed Translation - സൗജന്യ PDF ഡൗൺലോഡ് ചെയ്യുക

Last updated on Apr 12, 2025

നേടുക Syntax Directed Translation ഉത്തരങ്ങളും വിശദമായ പരിഹാരങ്ങളുമുള്ള മൾട്ടിപ്പിൾ ചോയ്സ് ചോദ്യങ്ങൾ (MCQ ക്വിസ്). ഇവ സൗജന്യമായി ഡൗൺലോഡ് ചെയ്യുക Syntax Directed Translation MCQ ക്വിസ് പിഡിഎഫ്, ബാങ്കിംഗ്, എസ്എസ്‌സി, റെയിൽവേ, യുപിഎസ്‌സി, സ്റ്റേറ്റ് പിഎസ്‌സി തുടങ്ങിയ നിങ്ങളുടെ വരാനിരിക്കുന്ന പരീക്ഷകൾക്കായി തയ്യാറെടുക്കുക

Latest Syntax Directed Translation MCQ Objective Questions

Top Syntax Directed Translation MCQ Objective Questions

Syntax Directed Translation Question 1:

Consider the grammar G:

(assume Bottom up parsing)

S → 0{ printf(“a”) }A

A → 1{ printf(“b”) }B

A → 2{ printf(“c”) }

A → ϵ { printf(“-“) }

B → 3 { printf(“b”) }A

B → ϵ { printf(“a”) }

What will be the input for the output “cbbbba”?

  1. 013132
  2. 031312
  3. 033112
  4. 011332

Answer (Detailed Solution Below)

Option 1 : 013132

Syntax Directed Translation Question 1 Detailed Solution

Answer: Option 1

Explanation

for Bottom-up parsing the Rules associated with a production executed at the time of reduction.

Option 4: 011332

This Option is not correct, since the 011332 can not be generated from the given Grammar.

Option 3: 033112

This option is also not correct, since the 033112 can not be generated from the given Grammar.

Option 2: 031312

This option is also not correct, since the 031312 can not be generated from the given Grammar.

Option 1:  013132

This Option is the correct answer Since 013132 can generate the output "cbbbba": 

 

Syntax Directed Translation Question 2:

Consider the following Syntax directed translation (SDT)

S → TR { printf(+) }

R → +T { printf(*) } R { printf(+) } | ε  { printf(*) }

T → num { printf(+) }

The input to this SDT is 2 + 3 + 4 + 5.

What will be the length of the longest Consecutive Repeating sequence in output?

Answer (Detailed Solution Below) 4

Syntax Directed Translation Question 2 Detailed Solution

Concept: To analyze the output from the SDT, first we need to draw the parse tree or annotated parse tree for the given input string. Then, we can traverse through that parse tree and find the output in an efficient way by traversing the tree from left to right.

First draw the parse tree for the given string from the given SDT i.e, 

we got the output + + * + * + * * + + + +.

Hence,  the length of the longest Consecutive Repeating sequence will be 4, and the longest Consecutive Repeating character is '+'.

Syntax Directed Translation Question 3:

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

  1. The actions will lead to infinite loop.
  2.  The actions can be used to correctly type-check any syntactically correct program.
  3. The actions can be used to type-check syntactically correct integer variable declarations and integer expressions.
  4. The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions.

Answer (Detailed Solution Below)

Option :

Syntax Directed Translation Question 3 Detailed Solution

Explanation

Option 1The actions will lead to an infinite loop.

This statement is not correct.

Option 2The actions can be used to correctly type-check any syntactically correct program.

This statement is not correct. Because These SDT actions can not type-check boolean expressions or float expressions.

for example :

float a = 3.46;

bool b = 0,c;

c = a + b; 

Option 3: The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions.

This statement is not correct. Because the SDT actions can not be used to correctly type check boolean expressions.

for example : 

bool a = 0;

bool b = 1;

bool c = a + b;

Option 4: The actions can be used to type-check syntactically correct integer variable declarations and integer expressions.

This statement is Correct. Because These SDT actions can be used to correctly type check both integer variables and integer expressions as well.

Syntax Directed Translation Question 4:

Convert the pre-fix expression to in-fix

--*+ABC*DE+FG

  1. (A - B)*C+(D*E)-(F+G)
  2. (A+B)*C-(D-E)*(F-G)
  3. (A+B-C)*(D-E)*(F+G)
  4. (A+B)*C - (D*E)-(F+G)

Answer (Detailed Solution Below)

Option 4 : (A+B)*C - (D*E)-(F+G)

Syntax Directed Translation Question 4 Detailed Solution

Option 4:

(A+B)*C - (D*E)-(F+G)

+AB*C - (D*E)-(F+G)

+AB*C - *DE - (F+G)

+AB*C - *DE - +FG

*+ABC*DE - +FG

-*+ABC*DE +FG

--*+ABC*DE+FG

Syntax Directed Translation Question 5:

Consider the following attributed grammar

S → A + B { S.val = A.val + B.val }

A → id { A.val = id.val }

B → id { B.val = id.val }

  1. SDT is L-attributed only
  2. SDT is S-attributed only
  3. SDT is L-attributed and S-attributed
  4. None of these

Answer (Detailed Solution Below)

Option 3 : SDT is L-attributed and S-attributed

Syntax Directed Translation Question 5 Detailed Solution

Synthesized attributes:

A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production. Synthesized attributes represent information that is being passed up the parse tree. The attribute can take value only from its children.

S-attributed SDT

If an SDT uses only synthesized attributes, it is called as S-attributed SDT.

Example:

S → A + B { S.val = A.val + B.val }

A → id { A.val = id.val }

B → id { B.val = id.val }

Inherited attributes:

An attribute of a nonterminal on the right-hand side of a production is called an inherited attribute. The attribute can take value either from its parent or from its siblings.

L-attributed SDT

If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT.

Therefore, every S-attributed definition is L-attributed but vice versa is not true.

Hence SDT is L-attribute and S-attributed

Syntax Directed Translation Question 6:

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:

Production rule

Semantic action

D → T L

X1.type = X2.type

T → int

T.type = int

T → float

T.type = float

L → L1, id

X3.type = X4.type

addType(id.entry, X5.type)

L → id

addType(id.entry, X6.type)

 

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

  1. X1 = L, X2 = T, X3 = L1, X4 = L
  2. X1 = T, X2 = L, X3 = L1, X4 = T
  3. X1 = L, X2 = L, X3 = L1, X4 = T
  4. X1 = T, X2 = L, X3 = T, X4 = L1

Answer (Detailed Solution Below)

Option 1 : X1 = L, X2 = T, X3 = L1, X4 = L

Syntax Directed Translation Question 6 Detailed Solution

Concepts:

Synthesized attributes:

A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production. Synthesized attributes represent information that is being passed up the parse tree. The attribute can take value only from its children.

S-attributed SDT

If an SDT uses only synthesized attributes, it is called as S-attributed SDT.

Inherited attributes:

An attribute of a nonterminal on the right-hand side of a production is called an inherited attribute. The attribute can take value either from its parent or from its siblings.

L-attributed SDT

If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT.

In SDT:

D → T L {X1.type = X2.type}

L.type = T.type (Inherited attributed )

∴ X1 = L and X2 = T

T can be int or float

In SDT:

L → L1, id {X3.type = X4.type}

L1.type = L.type (Inherited attributed)

∴ X3 = L1 and X4 = L

Hence option 1 is correct.

Syntax Directed Translation Question 7:

Let SDT be

S → BC {B.val = C.val}

The above SDT is

  1. S-attributed
  2. L-attribute
  3. S-attributed and L-attributed
  4. Neither S-attributed and nor L-attributed

Answer (Detailed Solution Below)

Option 4 : Neither S-attributed and nor L-attributed

Syntax Directed Translation Question 7 Detailed Solution

Synthesized attributes:

A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production. Synthesized attributes represent information that is being passed up the parse tree. The attribute can take value only from its children.

S-attributed SDT

If an SDT uses only synthesized attributes, it is called as S-attributed SDT.

Example: S → BC

S.val = B.val

S.val = C.val

But B.val = C.val is not a S-attributed SDT

Inherited attributes:

An attribute of a nonterminal on the right-hand side of a production is called an inherited attribute. The attribute can take value either from its parent or from its siblings.

L-attributed SDT

If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT.

Example: S → BC

S.val = B.val

S.val = C.val

Also

C.val = B.val

C.val = S.val

B.val = S.val

Therefore B.val = C.val is not a L-attributed SDT

Hence is neither S-attributed SDT nor L-attributed SDT

Syntax Directed Translation Question 8:

Consider a Grammar E → E + n|E x n|n for a sentence n + n x n, the handles in the right-sentential form of the reduction are?

  1. n, E + n and E + n x n
  2. n, E + n and E + E x n
  3. n, n + n and n + n x n
  4. n, E + n and E x n

Answer (Detailed Solution Below)

Option 4 : n, E + n and E x n

Syntax Directed Translation Question 8 Detailed Solution

The correct answer is n, E + n and E x n

EXPLANATION:

In the given grammar E → E + n | E x n | n, let's consider the sentence n + n x n.

  • The right-sentential form during the reduction process will be as follows:
    • n + n x n  (Start with the original sentence)
    • E + n x n   (Apply the reduction E → n)
    • E x n         (Apply the reduction E → E + n)
    • E               (Apply the reduction E → E x n)

 

Therefore, the correct option is: 4) n, E + n, and E x n

Syntax Directed Translation Question 9:

Consider the following SDT

L -> E

E -> { printf("+") } E1 + T | T

T -> { printf("*") } | T1 * F | F

F -> (E)

F -> digit { printf(digit.val)}

Which of the following is true about the above SDT?

  1. Infix to post fix
  2. Infix evaluation
  3. Infix to prefix
  4. None of the above

Answer (Detailed Solution Below)

Option 3 : Infix to prefix

Syntax Directed Translation Question 9 Detailed Solution

The correct answer is option 3

Explanation:

According to the given SDT is used to convert infix to prefix expression

Example:

Infix expression : 5+2*7

So, it gives the prefix expression +5*27

Syntax Directed Translation Question 10:

Consider the following SDT to generate three address code of expression Statement ( E ) by using the following grammar productions where "place" is an attribute that gives the name of the variable that will hold the value of E and code is an attribute that gives 3-address code at every place and newtemp() function generates new temporary variable on every function call. gen() function generates the output intermediate code.

PRODUCTION

SEMANTIC RULES

S → id := E

S.code := E.code || gen(id.place : = E.place)

E → E1 + E2

E.place := newtemp();
E.code := E1.code || E2.code || gen(Y)

E → E1 * E2

E.place := newtemp();
E.code := E1.code || E2.code || gen(X)

E → - E1

E.place := newtemp();
E.code := E1.code || gen(E.place := 'uminus' E1.place)

E →(E1)

E.place := E1.place;
E.code := E1.code;

E → id

E.place := id.place;

E.code := ‘ ’


What will be the appropriate expression in place of X and Y for SDT to generate the three Address of Expression { only involving +, *, -, (, ) }.

(uminus stands for unary minus)

  1. X: E.place := E1.place + E2.place, Y: E.place := E1.place * E2.place
  2. X: E.place := E1.place * E2.place, Y: E.place := E1.place + E2.place
  3. X: E.place * E2.place, Y: E1.place + E2.place
  4. X: E1 := newtemp(), E2 := newtemp() ,E.place := E1.place * E2.place ; Y: E1 := newtemp(), E2 := newtemp() , E.place := E1.place + E2.place

Answer (Detailed Solution Below)

Option 2 : X: E.place := E1.place * E2.place, Y: E.place := E1.place + E2.place

Syntax Directed Translation Question 10 Detailed Solution

Explanation: 

The Given SDT is supposed to generate 3 address code

E → E1 + E2 /the addition must be assigned to a temp variable So is E.place = newtemp()

And the place values of E1 and E2 must be added and assigned to their place attribute so

So Y: = E1.place + E2.place

And for E → E1 * E2 / X := E1.place * E2.place

Hence Only Option correct is Option 2.

Note:

There is no need to generate a temporary variable for E1 and E2 ( in E → E1 + E2 ) because variables E1 and E2 will already exists in the symbol table, we need only to generate temp variable for E and assign the sum of E1 value and E2 value and assign it to E’s place attributes ( where E’s temporary variable is)

Hot Links: online teen patti real money teen patti gold apk teen patti master list teen patti apk