All Question paper with solution mean Bachelorexam.com

(Aktu Btech) Compiler Design Important Unit-3 Syntax-Directed Translations

B.Tech AKTU Quantum Book can help you understand the complexities of compiler design. Access important notes, frequently asked questions, and valuable insights to help you learn this key area. Unit-3 Syntax-Directed Translations

Dudes 🤔.. You want more useful details regarding this subject. Please keep in mind this as well.

Important Questions For Compiler Design:
*Quantum               *B.tech-Syllabus
*Circulars                *B.tech AKTU RESULT
* Btech 3rd Year     * Aktu Solved Question Paper

Q1. Define syntax directed translation. Construct an annotated parse tree for the expression (4 * 7 + 1) * 2, using the simple desk calculator grammar.

Ans.

  • 1. Syntax directed definition/translation is a generalization of context free grammar in which each grammar production X ⍺ is associated with a set of semantic rules of the form a: = f(b1,b2…….bk), where a is an attribute obtained from the function f. 
  • 2. Syntax directed translation is a kind of abstract specification. 
  • 3. It is done for static analysis of the language. 
  • 4. It allows subroutines or semantic actions to be attached to the productions of a context free grammar. These subroutines generate intermediate code when called at appropriate time by a parser for that grammar. 
  • 5. The syntax directed translation is partitioned into two subsets called the synthesized and inherited attributes of grammar.    
Define syntax directed translation. Construct an annotated parse tree for the expression (4 * 7 + 1) * 2, using the simple desk calculator grammar. Compiler Design

Annotated tree for the expression (4*7 + 1)*2:

Define syntax directed translation. Construct an annotated parse tree for the expression (4 * 7 + 1) * 2, using the simple desk calculator grammar. Btech Compiler Design

Q2. Explain attributes. What are synthesized and inherited attribute?

Ans. Attributes: 

  • 1. By tying attributes to the grammar symbols that correspond to a language construct, information is connected with that construct.
  • 2. Grammar symbols that serve as the labels of the nodes in the parse tree are associated with attributes.
  • 3. An attribute can (reasonably) represent anything, including a string, a number, a type, a location in memory, a section of code, etc.
  • 4. A semantic rule connected to the production used at a parse tree node determines the value of an attribute at that node.

Synthesized attribute: 

  • 1. An attribute at a node is said to be synthesized if its value is computed from the attributed values of the children of that node in the parse tree.
  • 2. A syntax directed definition that uses the synthesized attributes is exclusively said to be S-attributed definition. 
  • 3. Thus, a parse tree for S-attributed definition can always be annotated by evaluating the semantic rules for the attributes at each node from leaves to root. 
  • 4. If the translations are specified using S-attributed definitions, then the semantic rules can be conveniently evaluated by the parser itself during the parsing.

For example: A parse tree along with the values of the attributes at nodes (called an “annotated parse tree”) for an expression 2 + 3*5 with synthesized attributes is shown in the Fig.

Explain attributes. Compiler Design

Inherited attribute: 

  • 1. An inherited attribute is one whose value at a node in a parse tree is defined in terms of attributes at the parent and/or sibling of that node. 
  • 2. Inherited attributes are convenient for expressing the dependence of a programming language construct.

For example: Syntax directed definitions that uses inherited attribute are given as:

What are synthesized and inherited attribute? Aktu Btech

The parse tree, along with the attribute values at the parse tree nodes, for an input string int id1, id2, and id3, is shown in the Fig.

What are synthesized and inherited attribute? Compiler Design

Q3. What is intermediate code generation and discuss benefits of intermediate code ?

Ans. Intermediate code generation is the fourth phase of compiler which takes parse tree as an input from semantic phase and generates an intermediate code as output. 

The benefits of intermediate code are: 

  • 1. Intermediate code is machine independent, which makes it easy to retarget the compiler to generate code for newer and different processors. 
  • 2. Intermediate code is nearer to the target machine as compared to the source language so it is easier to generate the object code. 
  • 3. The intermediate code allows the machine independent optimization of the code by using specialized techniques. 
  • 4. Syntax directed translation implements the intermediate code generation, thus by augmenting the parser, it can be folded into the parsing.

Q4. Write the quadruples, triple and indirect triple for the following expression:

                                             (x + y) * (y + z)+ (x + y + z) 

Ans. The three address code for given expression:

Write the quadruples, triple and indirect triple for the following expression: Compiler Design

i. The quadruple representation:

Write the quadruples, triple and indirect triple for the following expression: Btech Aktu

ii. The triple representation:

Write the quadruples, triple and indirect triple for the following expression: Compiler Design

iii. The indirect triple representation: 

Write the quadruples, triple and indirect triple for the following expression: Btech Aktu Compiler Design

Q5. Explain procedure call with example. 

Ans. Procedures call: 

  • 1. Procedure is an important and frequently used programming construct for a compiler. 
  • 2. It is used to generate code for procedure calls and returns. 
  • 3. Queue is used to store the list of parameters in the procedure call. 
  • 4. The translation for a call includes a sequence of actions taken on entry and exit from each procedure. Following actions take place ina calling sequence:
    • a. When a procedure call occurs then space is allocated for activation record. 
    • b. Evaluate the argument of the called procedure.
    • c. Establish the environment pointers to enable the called procedure to access data in enclosing blocks. 
    • d. Save the state of the calling procedure so that it can resume execution after the call. 
    • e. Also save the return address. It is the address of the location to which the called routine must transfer after it is finished. 
    • f. Finally generate a jump to the beginning of the code for the called procedure.

For example: Let us consider a grammar for a simple procedure call statement:

Explain procedure call with example. Aktu Btech

A suitable transition scheme for procedure call would be: 

Explain procedure call with example. Compiler Design

Q6. Explain declarative statements with example.

Ans. In the declarative statements the data items along with their data types are declared. 

For example: 

Explain declarative statements with example. Compiler Design
  • 1. Initially, the value of offset is set to zero. The computation of offset can be done by using the formula offset = offset + width. 
  • 2. In the above translation scheme, T.type, T.width are the synthesized attributes. The type indicates the data type of corresponding identifier and width is used to indicate the memory units associated with an identifier of corresponding type. For instance integer has width 4 and real has 8.       
  • 3. The rule D → id: T is a declarative statements for id declaration. The enter_tab is a function used for creating the symbol table entry for identifier along with its type and offset. 
  • 4. The width of array is obtained by multiplying the width of each element by number of elements in the array. 
  • 5. The width of pointer types of supposed to be 4. 
bachelor exam preparation all question paper with solution important questions with solution

Compiler Design Btech Quantum PDF, Syllabus, Important Questions

LabelLink
Subject SyllabusSyllabus
Short QuestionsShort-question
Question paper – 2021-222021-22

Compiler Design Quantum PDF | AKTU Quantum PDF:

Quantum SeriesLinks
Quantum -2022-232022-23

AKTU Important Links | Btech Syllabus

Link NameLinks
Btech AKTU CircularsLinks
Btech AKTU SyllabusLinks
Btech AKTU Student DashboardStudent Dashboard
AKTU RESULT (One VIew)Student Result

Important Links-Btech (AKTU)

LabelLinks
Btech InformationInfo Link
Btech BranchLINK
Quantum-PageLink

Leave a Comment