Class TreeNode

java.lang.Object
  extended byTreeNode
Direct Known Subclasses:
LeafNode, TreeNode1, TreeNode2, TreeNode3, TreeNode4, TreeNodeList

public abstract class TreeNode
extends java.lang.Object

TreeNode is the abstract parent class for a parse tree node. It contains an integer ID data field that is common to all types of node. The ID defines what type of tree node this is, e.g., an IF node, a PLUS, etc. The ID values are those defined for symbols in sym.java.

Extensions of TreeNode add additional data fields to hold information necessary for a particular node type. The TreeNode extensions are the following:

See the documentation for each of these extending classes for further detail.


Field Summary
 int id
          The ID of this node.
 
Constructor Summary
TreeNode()
          Construct a tree node with id = 0.
TreeNode(int id)
          Construct a tree node with the given id.
 
Method Summary
static java.lang.String symPrint(int id)
          Print a readable string value for a numeric-valued tree ID.
 java.lang.String toString()
          Output the String representation of a pre-order tree traversal.
abstract  java.lang.String toString(int level)
          This is the recursive work-doer for toString.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

public int id
The ID of this node. Yea, it's public. Take that, you pain-in-the-xxx software engineers.

Constructor Detail

TreeNode

public TreeNode()
Construct a tree node with id = 0. This is used, e.g., for nodes in a list, that don't need individual id's.


TreeNode

public TreeNode(int id)
Construct a tree node with the given id.

Method Detail

toString

public java.lang.String toString()
Output the String representation of a pre-order tree traversal. The value of each node is written on a separate line, with subtree nodes indented two spaces per each level of depth, starting at depth 0 for the root.

For example, the following tree

looks like this from TreeNode.toString

 +
   a
   *
     b
     c
                                                                  
The implementation of toString() uses an int-valued overload to perform recursive traversal, passing an incrementing level value to successive recursive invocations. See the definitions of toString(int) in each TreeNode extension for further details.


toString

public abstract java.lang.String toString(int level)
This is the recursive work-doer for toString. See its definition in extending classes for details.


symPrint

public static java.lang.String symPrint(int id)
Print a readable string value for a numeric-valued tree ID. This method uses the mapping defined in the symNames class.