openlist.reader
Class SExpressionReader

java.lang.Object
  extended by java.io.StreamTokenizer
      extended by openlist.reader.SExpressionReader

public class SExpressionReader
extends java.io.StreamTokenizer

SExpressionReader provides a reader for OpenLists and atoms. In addition to tokenizing for atoms of specific types: Doubles, Longs, and Strings (which are interned as Symbols), an entire OpenList can be read by a single method call, assuming the input is in the form of an S expression. In an S expression, the elements of a OpenLists are shown in parentheses with a space between each element. (The elements can themselves be S expressions representing OpenLists.)


Field Summary
private  int buff
           
private static char FORM_FEED
           
private static char LEFT_PAREN
           
private  long lval
           
private static char NEWLINE
           
private static char RETURN
           
private static char RIGHT_PAREN
           
private static char SPACE
           
private static char TAB
           
private static int TT_LONG
           
private  boolean valid
           
 
Fields inherited from class java.io.StreamTokenizer
nval, sval, TT_EOF, TT_EOL, TT_NUMBER, TT_WORD, ttype
 
Constructor Summary
SExpressionReader(java.io.InputStream I)
          Construct an SExpressionReader from an InputStream
SExpressionReader(java.io.Reader R)
          Construct an SExpressionReader from a Reader.
 
Method Summary
 void exceptionHandler(java.lang.Exception e)
          exceptionHandler can be over-ridden to handle IO exceptions
private  void get()
          Get the next token from the input.
(package private)  OpenList<java.lang.Object> getRestSexp()
          Get the rest of a started S expression from input stream.
private  void getSkippingWhiteSpace()
          Skip any whitespace, then get the next token from the input.
private  boolean isWhiteSpace(int c)
          Determine whether a character is white space
 java.lang.Object nextSexp()
          Get next S expression from input stream.
 int nextToken()
          Get token and return TT_LONG, TT_NUMBER, TT_WORD, or TT_EOF
private  void putBack(int c)
          Put a character back into the input.
 
Methods inherited from class java.io.StreamTokenizer
commentChar, eolIsSignificant, lineno, lowerCaseMode, ordinaryChar, ordinaryChars, parseNumbers, pushBack, quoteChar, resetSyntax, slashSlashComments, slashStarComments, toString, whitespaceChars, wordChars
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TT_LONG

private static final int TT_LONG
See Also:
Constant Field Values

lval

private long lval

buff

private int buff

valid

private boolean valid

LEFT_PAREN

private static final char LEFT_PAREN
See Also:
Constant Field Values

RIGHT_PAREN

private static final char RIGHT_PAREN
See Also:
Constant Field Values

SPACE

private static final char SPACE
See Also:
Constant Field Values

TAB

private static final char TAB
See Also:
Constant Field Values

NEWLINE

private static final char NEWLINE
See Also:
Constant Field Values

RETURN

private static final char RETURN
See Also:
Constant Field Values

FORM_FEED

private static final char FORM_FEED
See Also:
Constant Field Values
Constructor Detail

SExpressionReader

public SExpressionReader(java.io.InputStream I)
Construct an SExpressionReader from an InputStream


SExpressionReader

public SExpressionReader(java.io.Reader R)
Construct an SExpressionReader from a Reader.

Method Detail

exceptionHandler

public void exceptionHandler(java.lang.Exception e)
exceptionHandler can be over-ridden to handle IO exceptions


isWhiteSpace

private boolean isWhiteSpace(int c)
Determine whether a character is white space


get

private void get()
Get the next token from the input. This is a hand-implemented get/putBack system, since the one in StreamOpenListReader didn't work well at one time.


getSkippingWhiteSpace

private void getSkippingWhiteSpace()
Skip any whitespace, then get the next token from the input.


putBack

private void putBack(int c)
Put a character back into the input.

Parameters:
c - the character to be put back

nextToken

public int nextToken()
Get token and return TT_LONG, TT_NUMBER, TT_WORD, or TT_EOF

Overrides:
nextToken in class java.io.StreamTokenizer

nextSexp

public java.lang.Object nextSexp()
Get next S expression from input stream. Returns an object of class EndOfFile on end-of-file.


getRestSexp

OpenList<java.lang.Object> getRestSexp()
Get the rest of a started S expression from input stream. Returns the empty list on end-of-file.