Only $35.99/year

Terms in this set (60)

allows clean implementation in a non-functional language
Provides an iterator over a usually recursive structure
don't mix data and actions
separates the representation of an object structure from the definition of operations on that structure
keeps data class definitions cleaner
Allows the creation of new operations without modifying all data classes. All you need todo is create a new abstractvisitor subclass (concrete visitor)
Adding new data classes is hard because all concrete visitors will need to be modified to now handle the new data.

general form:
data:
abstract element
concrete element subclasses
all elements define accept method that recursively calls accept on any child nodes
Actions:
abstractVisitor
Concrete visitors
ex: build symbol tables, calculateNodeDepths
*we made visitors for p4 (MyDecafAnalysis)
All visitors must have visit methods for each element type

*ex traverse from pa: previsit on the visitor's specific implementation of previsit, then call traverse on all element subnodes, then postvisit on the visitor's specific implementation of postvisit
**the previsit invisit and postvisit allow preorder, inorder, and postorder operations

Each element has its own implementation of accept because they have to manage how to pass on the tree traversal. Some have different structures of storing subnodes so they need call accept slightly differently to reach each one. Like different iterations over data structures. But they leave the state changes up to the visit functions on the visitors because that's where the don't mix data and actions comes in