Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views4 pages

Unit-3 Part A

Uploaded by

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

Unit-3 Part A

Uploaded by

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

Unit-3 part 2

Syntax-Directed Definitions/translations:

In syntax directed translation, along with the grammar we associate some informal notations
and these notations are called as semantic rules.

So we can say that

1. Grammar + semantic rule = SDT (syntax directed translation)

 In syntax directed translation, every non-terminal can get one or more than one
attribute or sometimes 0 attribute depending on the type of the attribute. The value of
these attributes is evaluated by the semantic rules associated with the production rule.
 In the semantic rule, attribute is VAL and an attribute may hold anything like a string,
a number, a memory location and a complex record

What is a Parse Tree?


A parse tree in compiler design is a graphical representation of a symbol which can be
terminal or non-terminal. Here, the string is taken using the start symbol, and the parse tree's
root is that start symbol.

Rules to follow while drawing a Parse Tree:

1. All leaf nodes need to be terminals.

2. All interior nodes need to be non-terminals.

3. In-order traversal gives the original input string.

In A -> xyz, the parse tree will have A as the interior node whose children are x, y and z from
left to right

E -> E+T | T
T -> T*F | F
F -> INTLIT

E -> E+T { E.val = E.val + T.val } PR#1


E -> T { E.val = T.val } PR#2
T -> T*F { T.val = T.val * F.val } PR#3
T -> F { T.val = F.val } PR#4
F -> INTLIT { F.val = INTLIT.lexval } PR#5

Advantages of Syntax Directed Translation in Compiler


Design
 SDT in compiler design provides an easy way to specific transitions and grammar
rules. It makes an easy method to translate= programming languages.

 SDT maintains the compiler and is easy to modify as it separates the translation
process from the parsing method.

 It optimises the translation process making it code-effective.

Disadvantages of Syntax Directed Translation in Compiler


Design
 Other translation methods, like attribute grammar, have increased expressiveness.
This decreases the performance of SDT.

 Also, SDT does not perform well when the translations are complex.

 In addition to that, the process of error fixing and error location is not easy in SDT.
This happens in the case of complex translations.

Application of Syntax Directed Translation in Compiler


Design
Here are some applications of SDT in Compiler Design:
1. Syntax Directed Translation is used for executing arithmetic expressions

2. Conversion from infix to postfix expression

3. Conversion from infix to prefix expression

4. For Binary to decimal conversion

5. Counting the number of Reductions

6. Creating a Syntax Tree

7. Generating intermediate code

8. Storing information into the symbol table

9. Type checking

Evaluation Orders for SDD’s(refer mobile and notes)

You might also like