sjm.parse.tokens
Class SymbolNode
java.lang.Object
|
+--sjm.parse.tokens.SymbolNode
- Direct Known Subclasses:
- SymbolRootNode
- public class SymbolNode
- extends java.lang.Object
A SymbolNode
object is a member of a tree that
contains all possible prefixes of allowable symbols. Multi-
character symbols appear in a SymbolNode
tree
with one node for each character.
For example, the symbol =:~
will appear in a
tree as three nodes. The first node contains an equals sign,
and has a child; that child contains a colon and has a
child; this third child contains a tilde, and has no
children of its own. If the colon node had another child
for a dollar sign character, then the tree would contain
the symbol =:$
.
A tree of SymbolNode
objects collaborate to
read a (potentially multi-character) symbol from an input
stream. A root node with no character of its own finds an
initial node that represents the first character in the
input. This node looks to see if the next character in the
stream matches one of its children. If so, the node
delegates its reading task to its child. This approach
walks down the tree, pulling symbols from the input that
match the path down the tree.
When a node does not have a child that matches the next
character, we will have read the longest possible symbol
prefix. This prefix may or may not be a valid symbol.
Consider a tree that has had =:~
added and has
not had =:
added. In this tree, of the three
nodes that contain =:~
, only the first and
third contain complete symbols. If, say, the input contains
=:a
, the colon node will not have a child that
matches the 'a' and so it will stop reading. The colon node
has to "unread": it must push back its character, and ask
its parent to unread. Unreading continues until it reaches
an ancestor that represents a valid symbol.
- Version:
- 1.0
- Author:
- Steven J. Metsker
Constructor Summary |
SymbolNode(SymbolNode parent,
char myChar)
Constructs a SymbolNode with the given parent, representing
the given character. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
myChar
protected char myChar
children
protected java.util.Vector children
valid
protected boolean valid
parent
protected SymbolNode parent
SymbolNode
public SymbolNode(SymbolNode parent,
char myChar)
- Constructs a SymbolNode with the given parent, representing
the given character.
- Parameters:
SymbolNode
- this node's parentchar
- this node's character
addDescendantLine
protected void addDescendantLine(java.lang.String s)
ancestry
public java.lang.String ancestry()
- Show the symbol this node represents.
- Returns:
- the symbol this node represents
deepestRead
protected SymbolNode deepestRead(java.io.PushbackReader r)
throws java.io.IOException
ensureChildWithChar
protected SymbolNode ensureChildWithChar(char c)
findChildWithChar
protected SymbolNode findChildWithChar(char c)
findDescendant
protected SymbolNode findDescendant(java.lang.String s)
setValid
protected void setValid(boolean b)
toString
public java.lang.String toString()
- Give a string representation of this node.
- Overrides:
toString
in class java.lang.Object
- Returns:
- a string representation of this node
unreadToValid
protected SymbolNode unreadToValid(java.io.PushbackReader r)
throws java.io.IOException