Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Tests  >  Compiler Design  >  Test: Syntax Directed Translation - Computer Science Engineering (CSE) MCQ

Test: Syntax Directed Translation - Computer Science Engineering (CSE) MCQ


Test Description

10 Questions MCQ Test Compiler Design - Test: Syntax Directed Translation

Test: Syntax Directed Translation for Computer Science Engineering (CSE) 2024 is part of Compiler Design preparation. The Test: Syntax Directed Translation questions and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus.The Test: Syntax Directed Translation MCQs are made for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Syntax Directed Translation below.
Solutions of Test: Syntax Directed Translation questions in English are available as part of our Compiler Design for Computer Science Engineering (CSE) & Test: Syntax Directed Translation solutions in Hindi for Compiler Design course. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free. Attempt Test: Syntax Directed Translation | 10 questions in 30 minutes | Mock test for Computer Science Engineering (CSE) preparation | Free important questions MCQ to study Compiler Design for Computer Science Engineering (CSE) Exam | Download free PDF with solutions
Test: Syntax Directed Translation - Question 1

Which of the following phase of the compiler is Syntax Analysis?

Detailed Solution for Test: Syntax Directed Translation - Question 1

It is the Second Phase of the Compiler after Lexical Analyzer. It is also called Hierarchical Analysis or Parsing.

*Answer can only contain numeric values
Test: Syntax Directed Translation - Question 2

A translation scheme is shown as-

Output for 3 * 2 + 4 is ______.


Detailed Solution for Test: Syntax Directed Translation - Question 2

Given grammar, is
 is an ambiguous grammar.
Therefore two outputs are possible for single input i.e. 3 * 2 + 4.
Like: output 1 = 10
output 2 = 18
This problem is resolved by YACC Tool. So, according to rule of YACC Tool:
(1)  S-R conflict is resolved by ‘S’
(2) Ri – Rj conflict is resolved by Ri where i < j.
So, scanning input from left to right 

1 Crore+ students have signed up on EduRev. Have you? Download the App
*Answer can only contain numeric values
Test: Syntax Directed Translation - Question 3

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


Detailed Solution for Test: Syntax Directed Translation - Question 3

Concept:
The given grammar along with translation rules is,

The given string is=  20#10%5#8%2%2
Rule 1:
In the given SDT, % has more precedence than # and % because it is away from starting symbol.
Rule 2:
Both % and * are left-associative because the left non-terminal is present left most on the right side grammar.
The given string is=  20#10%5#8%2%2
The given string is=  20x10÷5 x 8÷2÷2
The given string is= 20 x2x4÷2
The given string is= 20 x2x2
The given string is= 40 x2
The given string is= 80
Hence the correct answer is 80.

Test: Syntax Directed Translation - Question 4

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?

Detailed Solution for Test: Syntax Directed Translation - Question 4

Option 1: The actions will lead to an infinite loop.
This statement is not correct.

Option 2: The 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.

Test: Syntax Directed Translation - Question 5

The below mentioned picture shows the:­

Detailed Solution for Test: Syntax Directed Translation - Question 5

Concept:
Basic idea of syntax directed translation:
Syntax-Directed Constructing a parse tree or syntax tree and computing the values of attributes at the nodes of the tree by visiting them in some order is the definition of translation. In many circumstances, translation can be done without creating an explicit tree during parsing.

Evaluation Orders for syntax directed translation:

  • Dependency Graphs.
  • Ordering the Evaluation of Attributes.
  • S-Attributed Definitions.
  • L-Attributed Definitions.
  • Semantic Rules

Note:

  • Evaluation of the semantic rules may generate code, save information in a symbol table, issue error messages, or perform any other activities.
  • Special cases of syntax-directed definitions can be implemented in a single pass by evaluating semantic rules during parsing, without explicitly constructing a parse tree or a graph showing dependencies between attributes.

Hence the correct answer is the Conceptual view of syntax-directed translation.

Test: Syntax Directed Translation - Question 6

Convert the pre-fix expression to in-fix
--*+ABC*DE+FG

Detailed Solution for Test: Syntax Directed Translation - Question 6

(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

Test: Syntax Directed Translation - Question 7

COMPILER is used to?

Detailed Solution for Test: Syntax Directed Translation - Question 7

Compiler is a translator which converts high level language (source program) into low level language (machine program).

Test: Syntax Directed Translation - Question 8

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:

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

Detailed Solution for Test: Syntax Directed Translation - Question 8

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.

*Answer can only contain numeric values
Test: Syntax Directed Translation - Question 9

Consider the syntax-directed transition scheme given below with non-terminals {A, B, C} and terminals {a, b, c}
S → AC {print*} | aB{print ***}
A → Sb {print **}
B → c {print *}
C → S {print *}
Using the above SDT, calculate the total number of * that are going to be printed in the output for the input acbac.


Detailed Solution for Test: Syntax Directed Translation - Question 9

Input: a c b a c
(1) Construct the syntax tree for the given input.

Test: Syntax Directed Translation - Question 10

_____ is done by attaching rules or algorithms or program fragments to productions in a grammar.

Detailed Solution for Test: Syntax Directed Translation - Question 10

Syntax Directed Translation is done by attaching augmented rules to the grammar that facilitate semantic analysis. It involves passing information top bottom and/or bottom up the parse tree in form of attributes attached to the nodes. Syntax directed translation rules use the following

  1. lexical values of nodes
  2. constants
  3. attributes associated to the non-terminals in their definitions.
26 videos|66 docs|30 tests
Information about Test: Syntax Directed Translation Page
In this test you can find the Exam questions for Test: Syntax Directed Translation solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Syntax Directed Translation, EduRev gives you an ample number of Online tests for practice

Top Courses for Computer Science Engineering (CSE)

26 videos|66 docs|30 tests
Download as PDF

Top Courses for Computer Science Engineering (CSE)