What is the attribute grammar and how it works for solving p

What is the attribute grammar and how it works for solving problems in computer programming concepts? How can we compute value using attribute grammar, please explain with example.

Solution

Attribute Grammar : It is a kind of context-free grammar in which additional attributes (having well-defined domain of values, such as float,integer,character,string, and expressions.)
are appended to its non-terminals and are associated with the values so as to provide some context-sensitive information.
With the help of Attribute Grammar , we define the attributes for production of formal grammar and to specify the syntax and semantics of a programming language.
It is also a medium to provide sematics to context free grammar.

Uses :
1) Attribute grammars is used in solving some combinatorics problems.
2) It is used to translate the syntax tree directly into code for specific machines.

eg.
ExpressionA ExpressionB + Term [ ExpressionA.value = ExpressionB.value + Term.value ]
Expression Term [ Expression.value = Term.value ]
TermA TermB * Factor [ TermA.value = TermB.value * Factor.value ]

FactorA integer [ FactorA.value = strToInt(integer.str) ]

What is the attribute grammar and how it works for solving problems in computer programming concepts? How can we compute value using attribute grammar, please e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site