0
$\begingroup$

I am failing to understand the "visits sequence evaluator in attribute grammar". Is it an order on instantiated tree nodes where on each visit to a node we evaluate a particular node and we may end up visiting a node more than once. Is it correct?

There are two paper that describe the visit sequence evaluator:

$\endgroup$

1 Answer 1

1
+50
$\begingroup$

You don't evaluate nodes in an attribute grammar. You evaluate attributes. At a given node there may be zero or more attributes to evaluate, and they don't necessarily get evaluated on the same visit to the node. So the evaluator may indeed need to visit nodes multiple times.

This theoretical structure corresponds to compilers which do multiple passes over the parse tree. But it also could also apply to an attribute evaluation sequence in which nodes are visited twice: once before their children (in order to compute inherited attributes) and again after their children (in order to compute synthesized attributes). Or multiple times, if some attribute needs to be synthesized from one child before being inherited by a different one. (Whether you count that as multiple visits or not is somewhat dependent on what you think a "visit" is. But it certainly affects how the evaluation code is ordered in the visitor function.)

There is a whole chapter devoted to syntax-directed translation in the dragon book, for what it's worth.

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.