Parser
v2.1

Parser
Class RETree

java.lang.Object
  |
  +--Parser.RETree

public class RETree
extends java.lang.Object

The RETree class represents a tree structure used to store strings as parsed useing a regular expression system.


Field Summary
 java.util.LinkedList branches
          The branching structure, linked list of Strings and RETrees.
 java.lang.reflect.Method codeGen
          A method that can be used to generate code.
 java.lang.String type
          A string describing the tree in terms of a grammar.
 
Constructor Summary
RETree()
          Empty constructor.
RETree(java.util.LinkedList branches, java.lang.String type)
          Constructs a regular expression tree with specified branches and type.
 
Method Summary
 java.lang.String collapse()
          Returns a string including all sub-strings using in-order traversal.
 java.lang.Object generateCode(java.lang.Object object, java.lang.Object args)
          A function used to accommodate automatic code generation.
 java.lang.Object get(int offset)
          Gets an item from the branches of the RETree.
 java.lang.Object get(int[] offsets)
          Gets an item from the branches of the RETree.
 int size()
          Returns the string length of the collapsed tree.
 java.lang.String toString()
          Returns a formatted string including all sub-strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

branches

public java.util.LinkedList branches
The branching structure, linked list of Strings and RETrees.

type

public java.lang.String type
A string describing the tree in terms of a grammar.

codeGen

public java.lang.reflect.Method codeGen
A method that can be used to generate code.
Constructor Detail

RETree

public RETree()
Empty constructor.

RETree

public RETree(java.util.LinkedList branches,
              java.lang.String type)
Constructs a regular expression tree with specified branches and type.
Parameters:
branches - the branches of the tree (either String or LinkedList).
type - a description of the tree (i.e. the rule name).
Method Detail

generateCode

public java.lang.Object generateCode(java.lang.Object object,
                                     java.lang.Object args)
                              throws java.lang.Exception
A function used to accommodate automatic code generation.
Returns:
a generic object, depends on implementation.

get

public java.lang.Object get(int offset)
Gets an item from the branches of the RETree.
Parameters:
offset - the position in the tree.
Returns:
the item at the specified position in the tree.

get

public java.lang.Object get(int[] offsets)
Gets an item from the branches of the RETree. This function can traverse multiple tree levels.
Parameters:
offsets - an array of offsets.
Returns:
the item at the specified position in the tree.

collapse

public java.lang.String collapse()
Returns a string including all sub-strings using in-order traversal. This function is more useful than toString because it returns the exact "value" of the tree without formatting.
Returns:
a string representation of the tree after in-order traversal.

size

public int size()
Returns the string length of the collapsed tree.
Returns:
the string length of the collapsed tree.

toString

public java.lang.String toString()
Returns a formatted string including all sub-strings. Example: English: [Noun: Person, Verb: plays]
Overrides:
toString in class java.lang.Object
Returns:
a formatted string representation of the tree after in-order traversal.

Parser
v2.1