0% found this document useful (0 votes)
27 views73 pages

Syntax Directed Translation

The document summarizes topics related to syntax directed translation that will be covered in a compiler design course, including syntax directed definitions, intermediate code generation using postfix translation and three address codes, translation of expressions and arrays, backpatching for control flow statements, and run time environments. The instructor is Mrs. A. Sireesha and the course is Compiler Design (ECS 304) at GITAM Institute of Technology in Visakhapatnam, India.

Uploaded by

Sk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views73 pages

Syntax Directed Translation

The document summarizes topics related to syntax directed translation that will be covered in a compiler design course, including syntax directed definitions, intermediate code generation using postfix translation and three address codes, translation of expressions and arrays, backpatching for control flow statements, and run time environments. The instructor is Mrs. A. Sireesha and the course is Compiler Design (ECS 304) at GITAM Institute of Technology in Visakhapatnam, India.

Uploaded by

Sk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 73

Course Code and Course Title :ECS 304 &Compiler Design

Unit 4: Syntax Directed Translation

Course Instructor: Mrs.A.Sireesha

Department of Computer Science and Engineering


GITAM Institute of Technology (GIT)
Visakhapatnam – 530045
Email: [email protected]

Department of Computer Science and Engineering Course Code and Course Title: ECS 30 &Compiler Design
Thursday, November 3, 2022 2
Topics:

Syntax Directed Translation:


• Syntax directed definitions,
• evaluation orders for SDD’s.

Intermediate Code Generation:


• SDD for syntax tree construction,
• postfix translation,
• three address codes,
• translation of arithmetic expressions,
• translation of array references;

Back patching:
• Boolean expressions,
• flowof control statements.

Run Time Environments: Storage organization, stack allocation of Space

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
 Syntax-Directed Definitions:

A syntax-directed definition (SDD) is a context-free grammar together with,


attributes and rules. Attributes are associated with grammar symbols and rules are associated with productions.

-----If X is a symbol and a is one of its attributes, then we write X.a to denote the value of a at a particular parse-tree
node labeled X.

A syntax-directed definition specifies the values of attributes by


associating semantic rules with the grammar productions.

For example, an infix-to-postfix translator might have a production and rule

This production has two nonterminals, E and T; the subscript in E1 distin-


guishes the occurrence of E in the production body from the occurrence of E as the head.

Both E and T have a string-valued attribute code. The semantic rule specifies that the string E. code is formed by
concatenating E1. code, T. code, and the character '+I.

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
a syntax-directed translation scheme embeds program
fragments called semantic actions within production bodies, as in

E -> E1+T { print ‘+’}

The most general approach to syntax-directed translation is to construct a


parse tree or a syntax tree, and then to compute the values of attributes at the
nodes of the tree by visiting the nodes of the tree.

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
 Inherited and Synthesized Attributes:

We shall deal with two kinds of attributes for nonterminals:


1. A synthesized attribute for a nonterminal A at a parse-tree node N is
defined by a semantic rule associated with the production at N. Note
that the production must have A as its head.

A synthesized attribute atnode N is defined only in terms of attribute values at the


children of Nand at N itself.

2. An inherited attribute for a nonterminal B at a parse-tree node N is


defined by a semantic rule associated with the production at the parent
of N. Note that the production must have B as a symbol in its body.

An inherited attribute at node N is defined only in terms of attribute values


at N's parent, N itself, and N's siblings.

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
7 gives F.val the value of a digit, that is,
the numerical value of the token digit that the lexical analyzer
returned.

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
An SDD that involves only synthesized attributes is called S-
attributed;
In an S-attributed SDD, each rule computes
an attribute for the nonterminal at the head of a production from attributes
taken from the body of the production.

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Translation of arithmetic expressions

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Addressing array elements ;

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Translation of array references;

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Translation of array references;

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Translation of array references;

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Translation of array references;

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Translation of array references;

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Backpatching

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Backpatching of flow of control statements

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Run Time Environments:

Thursday, November 3, 2022


Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design
Thursday, November 3, 2022
Department of Computer Science and Engineering Course Code and Course Title: ECS 304 &Compiler Design

You might also like