public abstract class ParseTreeTraverser
extends java.lang.Object
Visitor for
each subtree of a ParseTree<Node>.
Each subtree can be visited in ‘pre-order’ as well asO in ‘post-order’. ‘Pre-order’ visits each subtree before any of its child subtrees, and ‘post-order’ visits each subtree after visiting its child subtrees.
traverse(ParseTree, Visitor) visits each subtree twice: combining ‘pre-order’ and ‘post-order’ traversal in one pass.
The Visitor contract returns a boolean flag from its visit methods which these
traversal algorithms interpret as immediate abort: no further visits will be made after the first returns false.
Each traversal method returns true if all the tree is visited, and false if any visit aborted.
| Modifier and Type | Method and Description |
|---|---|
static <Node> boolean |
traverse(ParseTree<Node> tree,
Visitor<Node> visitor)
Visits each subtree in both ‘pre-order’ and ‘post-order’, in one pass.
|
public static <Node> boolean traverse(ParseTree<Node> tree, Visitor<Node> visitor)
Visitor.visitBefore(Object, Object[])) and after (by calling Visitor.visitAfter(Object, Object[]))
all of its child subtrees are visited.tree - the tree all of whose subtrees are to be visitedvisitor - the Visitor whose Visitor.visitBefore(Object, Object[]) and Visitor.visitAfter(Object, Object[])
methods are passed each subtree’s node and child nodes.true if the traversal completed, false if it was aborted prematurelyCopyright © 2022. All rights reserved.