Attribute Grammar - Example

Example

The following is a simple Context-free grammar which can describe a language made up of multiplication and addition of integers.

ExprExpr + Term ExprTerm TermTerm * Factor TermFactor Factor → "(" Expr ")" Factorinteger

The following attribute grammar can be used to calculate the result of an expression written in the grammar. Note that this grammar only uses synthesized values, and is therefore an S-attributed grammar.

Expr1Expr2 + Term ExprTerm Term1Term2 * Factor TermFactor Factor → "(" Expr ")" Factorinteger

Read more about this topic:  Attribute Grammar

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)