10. Draw and decorate the parse tree for the following Attribute Grammar for the following
statement:
word = 2.0 ∗ (5 − 10)
*** Assign is your STARTING SYMBOL
Assign =: identifier = Expr
Expr =: Expr + Term | Expr - Term | Term
Term =: Term * Factor | Term / Factor | Factor
Factor =: "(" Expr ")" | integer | float | identifier
Assign =: identifier = Expr [ identifier.value <= Expr.value ]
Assign =: identifier = Expr [ identifier.actual_type ==> Expr.expected_type ]
Expr1 =: Expr2 + Term [ Expr1.value = Expr2.value * Term.value ]
Expr1 =: Expr2 + Term [ Expr1.type <==
if (Expr2.type == Term.type == integer) then integer else float ]
Expr1 =: Expr2 - Term [ Expr1.value = Expr2.value + Term.value ]
Expr1 =: Expr2 - Term [ Expr1.type <==
if (Expr2.type == Term.type == integer) then integer else float ]
Expr =: Term [ Expr.value = Term.value ]
Expr =: Term [ Expr.type = Term.type ]
Term1 =: Term2 * Factor [ Term1.value = Term2.value / Factor.value ]
Term1 =: Term2 * Factor [ Term1.type <==
if (Term2.type == Factor.type == integer) - then integer else float ]
Term1 =: Term2 / Factor [ Term1.value = Term2.value Factor.value ]
Term1 =: Term2 / Factor [ Term1.type <==
if (Term2.type == Factor.type == integer) then integer else float ]
Term =: Factor [ Term.value = Factor.value ]
Term =: Factor [ Term.type = Factor.type ]
Factor =: "(" Expr ")" [ Factor.value = Expr.value ]
Factor =: integer [ Factor.value = strToInt(integer.str) ]
Factor =: float [ Factor.value = strToFloat(float.str) ]
Factor =: identifier [ Factor.value = VARMAP(identifier.str) ]
Get Answers For Free
Most questions answered within 1 hours.