unsw.cse.framescript
Class Atomiser

java.lang.Object
  extended by unsw.cse.framescript.Atomiser

public class Atomiser
extends java.lang.Object

This class takes a reader and tokenises its stream of characters into terms. Term produced are generally of types: atom, integer, double, string.

Author:
Matthew McGill

Constructor Summary
Atomiser()
          Creates an atomiser that reads from System.in.
Atomiser(java.io.InputStream is)
          Creates an atomiser that reads from a specified input stream.
Atomiser(java.io.Reader r)
          Creates an atomiser that reads from a specified reader.
Atomiser(java.lang.String s)
          Creates an atomiser that tokenises a given string.
 
Method Summary
static void addCompoundTerm(Atom a)
          Tells all atomisers that a specific configuration of characters is special.
static void addCompoundTerm(java.lang.String str)
          Tells all atomisers that a specific configuration of characters is special.
 void allowSlashSlashComments(boolean flag)
          Switches on/off C style line comments.
 void allowSlashStarComments(boolean flag)
          Switches on/off C style block comments.
 java.lang.String comment(Term t)
          Gets a comment associated with a term.
 void commentChar(int c)
          Designates a character as a line comment indicator.
static void debug(int i, java.lang.String msg)
          Method for displaying debugging information.
 void eolIsImportant(boolean flag)
          Designates whether the end of a line is to be treated a a special character.
 int lineno()
          Gets the current line number.
static void loadAtoms()
          Tells all atomisers to load all atoms from symbol table to get special atoms.
static void main(java.lang.String[] args)
          For use in testing of Atomiser.
 Term nextToken()
          Gets the next term from the input stream.
 boolean nextToken(Term expect)
          Checks if the next term matches another, if so it is consumed.
 void ordinaryChar(int c)
          Designates a character ordiary.
 void ordinaryChars(int low, int high)
          Designates a range of characters ordinary.
 void parseNumbers(boolean flag)
          Switches on/off number parsing.
 void pushBack(Term t)
          Returns a term to the input stream.
 void quoteChar(int c)
          Designates a character to be a quotation character.
 void skip(Term expect)
          Skips to the designated term.
 void whitespaceChars(int low, int high)
          Designates which characters are considered whitespace.
 void wordChars(int low, int high)
          Disignates a range of characters to be word characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Atomiser

public Atomiser()
Creates an atomiser that reads from System.in.


Atomiser

public Atomiser(java.io.Reader r)
Creates an atomiser that reads from a specified reader.

Parameters:
r - a reader

Atomiser

public Atomiser(java.io.InputStream is)
Creates an atomiser that reads from a specified input stream.

Parameters:
is - an input stream

Atomiser

public Atomiser(java.lang.String s)
Creates an atomiser that tokenises a given string.

Parameters:
s - a string to be tokenised
Method Detail

comment

public java.lang.String comment(Term t)
Gets a comment associated with a term.

Parameters:
t - the term to get the comment for
Returns:
the comment for the term, null if no comment is associated with the term

ordinaryChar

public void ordinaryChar(int c)
Designates a character ordiary.

Parameters:
c - a character

ordinaryChars

public void ordinaryChars(int low,
                          int high)
Designates a range of characters ordinary.

Parameters:
low - lowest character to be made ordinary
high - highest character to be made ordinary

wordChars

public void wordChars(int low,
                      int high)
Disignates a range of characters to be word characters.

Parameters:
low - lowest characte to be a word character
high - highest character to be a word character

whitespaceChars

public void whitespaceChars(int low,
                            int high)
Designates which characters are considered whitespace.

Parameters:
low - lowest character being made whitespace
high - highest character being made whitespace

quoteChar

public void quoteChar(int c)
Designates a character to be a quotation character.

Parameters:
c - a character

commentChar

public void commentChar(int c)
Designates a character as a line comment indicator.

Parameters:
c - a character

parseNumbers

public void parseNumbers(boolean flag)
Switches on/off number parsing.

Parameters:
flag - whether or not to parse numbers

allowSlashSlashComments

public void allowSlashSlashComments(boolean flag)
Switches on/off C style line comments.

Parameters:
flag - whether or not C style line comments are to be ignored.

allowSlashStarComments

public void allowSlashStarComments(boolean flag)
Switches on/off C style block comments.

Parameters:
flag - whether or not C style line comments are to be ignored.

addCompoundTerm

public static void addCompoundTerm(Atom a)
Tells all atomisers that a specific configuration of characters is special.

Parameters:
a - atom that represents a special configuration of characters

addCompoundTerm

public static void addCompoundTerm(java.lang.String str)
Tells all atomisers that a specific configuration of characters is special.

Parameters:
str - a string which shows a special configuration of characters

eolIsImportant

public void eolIsImportant(boolean flag)
Designates whether the end of a line is to be treated a a special character. (NOTE new lines in C style block comments are still ignored)

Parameters:
flag - whether or not ends of line are important

lineno

public int lineno()
Gets the current line number.

Returns:
the current line number

loadAtoms

public static void loadAtoms()
Tells all atomisers to load all atoms from symbol table to get special atoms.


nextToken

public Term nextToken()
               throws SyntaxError,
                      java.io.IOException
Gets the next term from the input stream. First checks if a term has been pushed back, if not reads next term.

Returns:
the next term in the input, null if no more terms
Throws:
java.io.IOException - if the is a problem reading from the input stream
SyntaxError - if a string literal is incorrectly finished

pushBack

public void pushBack(Term t)
Returns a term to the input stream. Stores the term in a stack.

Parameters:
t - term being returned to the stream

nextToken

public boolean nextToken(Term expect)
                  throws SyntaxError,
                         java.io.IOException
Checks if the next term matches another, if so it is consumed.

Parameters:
expect - a term that is exxpected at this point in the stream
Returns:
true if the term is next in the stream, false otherwise
Throws:
SyntaxError - if there is a problem reading from the input stream
java.io.IOException - if there is a problem reading from the input stream

skip

public void skip(Term expect)
          throws java.io.IOException
Skips to the designated term. Ignores SyntaxErrors.

Parameters:
expect - the term to skip to
Throws:
java.io.IOException - if there is a problem reading from the input stream

debug

public static void debug(int i,
                         java.lang.String msg)
Method for displaying debugging information.

Parameters:
i - level of the debugging information
msg - string with debugging information

main

public static void main(java.lang.String[] args)
For use in testing of Atomiser.

Parameters:
args - arguments
Throws:
FSException