sjm.parse
Class Assembly

java.lang.Object
  |
  +--sjm.parse.Assembly
All Implemented Interfaces:
java.lang.Cloneable, java.util.Enumeration, PubliclyCloneable
Direct Known Subclasses:
CharacterAssembly, TokenAssembly

public abstract class Assembly
extends java.lang.Object
implements java.util.Enumeration, PubliclyCloneable

An assembly maintains a stream of language elements along with stack and target objects. Parsers use assemblers to record progress at recognizing language elements from assembly's string.

Version:
1.0
Author:
Steven J. Metsker

Field Summary
protected  int index
           
protected  java.util.Stack stack
           
protected  PubliclyCloneable target
           
 
Constructor Summary
Assembly()
           
 
Method Summary
 java.lang.Object clone()
          Return a copy of this object.
abstract  java.lang.String consumed(java.lang.String delimiter)
          Returns the elements of the assembly that have been consumed, separated by the specified delimiter.
abstract  java.lang.String defaultDelimiter()
          Returns the default string to show between elements.
 int elementsConsumed()
          Returns the number of elements that have been consumed.
 int elementsRemaining()
          Returns the number of elements that have not been consumed.
 java.util.Stack getStack()
          Removes this assembly's stack.
 java.lang.Object getTarget()
          Returns the object identified as this assembly's "target".
 boolean hasMoreElements()
          Returns true if this assembly has unconsumed elements.
abstract  int length()
          Returns the number of elements in this assembly.
abstract  java.lang.Object peek()
          Shows the next object in the assembly, without removing it
 java.lang.Object pop()
          Removes the object at the top of this assembly's stack and returns it.
 void push(java.lang.Object o)
          Pushes an object onto the top of this assembly's stack.
abstract  java.lang.String remainder(java.lang.String delimiter)
          Returns the elements of the assembly that remain to be consumed, separated by the specified delimiter.
 void setTarget(PubliclyCloneable target)
          Sets the target for this assembly.
 boolean stackIsEmpty()
          Returns true if this assembly's stack is empty.
 java.lang.String toString()
          Returns a textual description of this assembly.
 void unget(int n)
          Put back n objects
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Enumeration
nextElement
 

Field Detail

stack

protected java.util.Stack stack

target

protected PubliclyCloneable target

index

protected int index
Constructor Detail

Assembly

public Assembly()
Method Detail

clone

public java.lang.Object clone()
Return a copy of this object.
Specified by:
clone in interface PubliclyCloneable
Overrides:
clone in class java.lang.Object
Returns:
a copy of this object

consumed

public abstract java.lang.String consumed(java.lang.String delimiter)
Returns the elements of the assembly that have been consumed, separated by the specified delimiter.
Parameters:
String - the mark to show between consumed elements
Returns:
the elements of the assembly that have been consumed

defaultDelimiter

public abstract java.lang.String defaultDelimiter()
Returns the default string to show between elements.
Returns:
the default string to show between elements

elementsConsumed

public int elementsConsumed()
Returns the number of elements that have been consumed.
Returns:
the number of elements that have been consumed

elementsRemaining

public int elementsRemaining()
Returns the number of elements that have not been consumed.
Returns:
the number of elements that have not been consumed

getStack

public java.util.Stack getStack()
Removes this assembly's stack.
Returns:
this assembly's stack

getTarget

public java.lang.Object getTarget()
Returns the object identified as this assembly's "target". Clients can set and retrieve a target, which can be a convenient supplement as a place to work, in addition to the assembly's stack. For example, a parser for an HTML file might use a web page object as its "target". As the parser recognizes markup commands like , it could apply its findings to the target.
Returns:
the target of this assembly

hasMoreElements

public boolean hasMoreElements()
Returns true if this assembly has unconsumed elements.
Specified by:
hasMoreElements in interface java.util.Enumeration
Returns:
true, if this assembly has unconsumed elements

length

public abstract int length()
Returns the number of elements in this assembly.
Returns:
the number of elements in this assembly

peek

public abstract java.lang.Object peek()
Shows the next object in the assembly, without removing it
Returns:
the next object

pop

public java.lang.Object pop()
Removes the object at the top of this assembly's stack and returns it.
Returns:
the object at the top of this assembly's stack
Throws:
java.util.EmptyStackException - if this stack is empty

push

public void push(java.lang.Object o)
Pushes an object onto the top of this assembly's stack.
Parameters:
object - the object to be pushed

remainder

public abstract java.lang.String remainder(java.lang.String delimiter)
Returns the elements of the assembly that remain to be consumed, separated by the specified delimiter.
Parameters:
String - the mark to show between unconsumed elements
Returns:
the elements of the assembly that remain to be consumed

setTarget

public void setTarget(PubliclyCloneable target)
Sets the target for this assembly. Targets must implement clone() as a public method.
Parameters:
target - a publicly cloneable object

stackIsEmpty

public boolean stackIsEmpty()
Returns true if this assembly's stack is empty.
Returns:
true, if this assembly's stack is empty

toString

public java.lang.String toString()
Returns a textual description of this assembly.
Overrides:
toString in class java.lang.Object
Returns:
a textual description of this assembly

unget

public void unget(int n)
Put back n objects