0
4.3kviews
What are different tpyes of attributes in SDD? Explain with Example

Mumbai University > Computer > Sem 6 > System Programming and Compiler Construction

Marks: 5

Year:May 16

1 Answer
1
88views

Syntax directed definition specifies the values of attributes by associating semantic rules with the grammar productions.

t is a context free grammar with attributes and rules together which are associated with grammar symbols and productions respectively.

The process of syntax directed translation is two-fold:

• Construction of syntax tree and

• Computing values of attributes at each node by visiting the nodes of syntax tree.

Semantic actions

Semantic actions are fragments of code which are embedded within production bodies by syntax directed translation. They are usually enclosed within curly braces ({ }).

It can occur anywhere in a production but usually at the end of production.

(eg.) E---> E1 + T {print ‘+’}

Types of translation

• L-attributed translation

o It performs translation during parsing itself.

o No need of explicit tree construction.

o L represents 'left to right'.

• S-attributed translation

o It is performed in connection with bottom up parsing.

o 'S' represents synthesized.

Types of attributes

• Inherited attributes

o It is defined by the semantic rule associated with the production at the parent of node.

o Attributes values are confined to the parent of node, its siblings and by itself.

o The non-terminal concerned must be in the body of the production.

• Synthesized attributes

o It is defined by the semantic rule associated with the production at the node.

o Attributes values are confined to the children of node and by itself.

o The non terminal concerned must be in the head of production.

o Terminals have synthesized attributes which are the lexical values (denoted by lexval) generated by the lexical analyzer.

Please log in to add an answer.