Difference between revisions of "Attribute Grammars/Exercise 6: Expressions with bases percentages"

From Wiki**3

< Attribute Grammars
(Problem (in Portuguese))
Line 1: Line 1:
 
== Problem (in Portuguese) ==
 
== Problem (in Portuguese) ==
 +
 +
== Solution ==
  
 
  E<sub>0</sub> -> E<sub>1</sub> '''+''' T  { <font color="blue">E<sub>0</sub>.val = E<sub>1</sub>.val + T.val;</font> }
 
  E<sub>0</sub> -> E<sub>1</sub> '''+''' T  { <font color="blue">E<sub>0</sub>.val = E<sub>1</sub>.val + T.val;</font> }

Revision as of 17:51, 13 June 2010

Problem (in Portuguese)

Solution

E0 -> E1 + T   { E0.val = E1.val + T.val; }
E -> T         { E.val = T.val; }
T0 -> T1 @ F   { T0.val = T1.val * F.val / 100; }
T -> F         { T.val = F.val; }
F -> ( E )         { F.val = E.val; }
F -> N       { F.val = N.val; }
N0 -> N1 DIG       { N0.val = N1.val * 10 + DIG.val; }
N -> DIG       { N.val = DIG.val; }

The following is the annotated tree.

File:AttrGramEx6.png