18
CS269: HW/SW Engineering of Embedded Systems, Winter02
Visitors
•Traversals of the AST use the Visitor design pattern:
•
•“A solution to the problem of adding operations
•to the elements of an object structure without
•changing the classes on which it operates”
•
–1 traversal = 1 Visitor class
–AST classes not modified when adding new Visitors
–
•The code of the traversal is divided in visit() methods: Object visitNameNode(NameNode node,
–                        LinkedList args)
–
•There is one _defaultVisit() method used if visit() method is not defined for a class of nodes
•
•Back-end tool may need several traversals of the AST
• ฎ Back-end  tool = set of visitors + additional classes