net.percederberg.grammatica.parser
Class Node

java.lang.Object
  |
  +--net.percederberg.grammatica.parser.Node
Direct Known Subclasses:
Production, Token

public abstract class Node
extends java.lang.Object

An abstract parse tree node. This class is inherited by all nodes in the parse tree, i.e. by the token and production classes.

Version:
1.0
Author:
Per Cederberg,

Constructor Summary
Node()
           
 
Method Summary
 void addValue(java.lang.Object value)
          Adds a computed value to this node.
 void addValues(java.util.Vector values)
          Adds a set of computed values to this node.
 java.util.Vector getAllValues()
          Returns the vector with all the computed values for this node.
 Node getChildAt(int index)
          Returns the child node with the specified index.
 int getChildCount()
          Returns the number of child nodes.
 int getEndColumn()
          The column number of the last character in this node.
 int getEndLine()
          The line number of the last character in this node.
abstract  int getId()
          Returns the node type id.
 Node getParent()
          Returns the parent node.
 int getStartColumn()
          The column number of the first character in this node.
 int getStartLine()
          The line number of the first character in this node.
 java.lang.Object getValue(int pos)
          Returns a computed value of this node, if previously set.
 int getValueCount()
          Returns the number of computed values associated with this node.
 void printTo(java.io.PrintStream out)
          Prints this node and all subnodes to the specified output stream.
 void printTo(java.io.PrintWriter out)
          Prints this node and all subnodes to the specified output stream.
 void removeAllValues()
          Removes all computed values stored in this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Node

public Node()
Method Detail

getId

public abstract int getId()
Returns the node type id. This value is set as a unique identifier for each type of node, in order to simplify later identification.

Returns:
the node type id

getStartLine

public int getStartLine()
The line number of the first character in this node. If the node has child elements, this value will be fetched from the first child.

Returns:
the line number of the first character, or -1 if not applicable

getStartColumn

public int getStartColumn()
The column number of the first character in this node. If the node has child elements, this value will be fetched from the first child.

Returns:
the column number of the first token character, or -1 if not applicable

getEndLine

public int getEndLine()
The line number of the last character in this node. If the node has child elements, this value will be fetched from the last child.

Returns:
the line number of the last token character, or -1 if not applicable

getEndColumn

public int getEndColumn()
The column number of the last character in this node. If the node has child elements, this value will be fetched from the last child.

Returns:
the column number of the last token character, or -1 if not applicable

getParent

public Node getParent()
Returns the parent node.

Returns:
the parent parse tree node

getChildCount

public int getChildCount()
Returns the number of child nodes.

Returns:
the number of child nodes

getChildAt

public Node getChildAt(int index)
Returns the child node with the specified index.

Parameters:
index - the child index, 0 <= index < count
Returns:
the child node found, or null if index out of bounds

getValueCount

public int getValueCount()
Returns the number of computed values associated with this node. Any number of values can be associated with a node through calls to addValue().

Returns:
the number of values associated with this node

getValue

public java.lang.Object getValue(int pos)
Returns a computed value of this node, if previously set. A value may be used for storing intermediate results in the parse tree during analysis.

Parameters:
pos - the value position, 0 <= pos < count
Returns:
the computed node value, or null if not set

getAllValues

public java.util.Vector getAllValues()
Returns the vector with all the computed values for this node. Note that the vector is not a copy, so changes will affect the values in this node (as it is the same object).

Returns:
a vector with all values, or null if no values have been set

addValue

public void addValue(java.lang.Object value)
Adds a computed value to this node. The computed value may be used for storing intermediate results in the parse tree during analysis.

Parameters:
value - the node value

addValues

public void addValues(java.util.Vector values)
Adds a set of computed values to this node.

Parameters:
values - the vector with node values

removeAllValues

public void removeAllValues()
Removes all computed values stored in this node.


printTo

public void printTo(java.io.PrintStream out)
Prints this node and all subnodes to the specified output stream.

Parameters:
out - the output stream to use

printTo

public void printTo(java.io.PrintWriter out)
Prints this node and all subnodes to the specified output stream.

Parameters:
out - the output stream to use