Parsing Engine

danbikel.lisp
Class Sexp

java.lang.Object
  extended by danbikel.lisp.Sexp
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
SexpList, Symbol

public abstract class Sexp
extends Object
implements Externalizable

This class provides the abstract base type for S-epxressions, which are either symbols or lists.

See Also:
Symbol, SexpList, Serialized Form

Method Summary
abstract  Sexp deepCopy()
          Returns a deep copy of this S-expression.
 Sexp getCanonical(Map map)
          Returns a canonical version of this S-expression.
abstract  boolean isList()
          Returns true if this is an instance of a SexpList, false otherwise.
abstract  boolean isSymbol()
          Returns true if this is an instance of a Symbol, false otherwise.
 SexpList list()
          Returns this object cast to a SexpList.
static void main(String[] args)
          A (very simple) test driver for this class.
static Sexp read(SexpTokenizer tok)
          Returns the S-expression contained in the stream held by tok.
static Sexp read(SexpTokenizer tok, char open, char close)
           
static Sexp read(String in)
          Returns the S-expression contained in the specified string.
abstract  void readExternal(ObjectInput oi)
          Reads this Sexp object from the specified object stream (to be implemented by all concrete subclasses).
 Symbol symbol()
          Returns this object cast to a Symbol.
abstract  void writeExternal(ObjectOutput oo)
          Writes this Sexp object from the specified object stream (to be implemented by all concrete subclasses).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

symbol

public final Symbol symbol()
Returns this object cast to a Symbol.

Returns:
this object cast to a Symbol.
Throws:
ClassCastException - if this object is not type-compatible with Symbol

list

public final SexpList list()
Returns this object cast to a SexpList.

Returns:
this object case to a SexpList.
Throws:
ClassCastException - if this object is not type-compatible with SexpList

isList

public abstract boolean isList()
Returns true if this is an instance of a SexpList, false otherwise.

Returns:
true if this is an instance of a SexpList, false otherwise.

isSymbol

public abstract boolean isSymbol()
Returns true if this is an instance of a Symbol, false otherwise.

Returns:
true if this is an instance of a Symbol, false otherwise.

deepCopy

public abstract Sexp deepCopy()
Returns a deep copy of this S-expression.

Returns:
a deep copy of this S-expression.

getCanonical

public final Sexp getCanonical(Map map)
Returns a canonical version of this S-expression. If this S-expression is a symbol, this object is returned; otherwise, if it is a zero-element list, SexpList.emptyList is returned; otherwise, if it is a key in map, the map's value for this list is returned; otherwise, this list is added as a reflexive key-value pair in map, after its trimToSize method has been invoked. Note that this method has a superset of the functionality of SexpList.getCanonical(SexpList).

Parameters:
map - the reflexive map of SexpList objects with which to canonicalize this Sexp object
Returns:
a canonical version of this S-expression, using the specified map to perform canonicalization
See Also:
SexpList.getCanonical(SexpList), SexpList.trimToSize()

read

public static Sexp read(SexpTokenizer tok)
                 throws IOException
Returns the S-expression contained in the stream held by tok. If there are no tokens remaining in tok, this method returns null.

Parameters:
tok - the tokenizer from which to read an S-expression
Returns:
the next S-expression that can be read from the specified S-expression tokenizer
Throws:
IOException - if there is an unexpected end of stream, mismatched parentheses or an unexpected character

read

public static Sexp read(SexpTokenizer tok,
                        char open,
                        char close)
                 throws IOException
Throws:
IOException

read

public static Sexp read(String in)
                 throws IOException
Returns the S-expression contained in the specified string. If the string contains no tokens, this method returns null.

Parameters:
in - the string from which to read an S-expression
Returns:
the first S-expression contained in the specified string
Throws:
IOException - if there was an underlying problem reading from the specified string

readExternal

public abstract void readExternal(ObjectInput oi)
                           throws IOException,
                                  ClassNotFoundException
Reads this Sexp object from the specified object stream (to be implemented by all concrete subclasses).

Specified by:
readExternal in interface Externalizable
Parameters:
oi - the object input stream
Throws:
IOException - if the underlying stream has an exception
ClassNotFoundException - if the class of the object that is read cannot be found

writeExternal

public abstract void writeExternal(ObjectOutput oo)
                            throws IOException
Writes this Sexp object from the specified object stream (to be implemented by all concrete subclasses).

Specified by:
writeExternal in interface Externalizable
Parameters:
oo - the object output stream to which this object will be written
Throws:
IOException - if the underlying stream thrown an exception

main

public static void main(String[] args)
A (very simple) test driver for this class.

Parameters:
args - arguments (all currently ignored)

Parsing Engine

Author: Dan Bikel.