Generic Interpreter 0.9
Protected API

gi
Class Lexicon

java.lang.Object
  |
  +--gi.Lexicon
Direct Known Subclasses:
Grammar

public class Lexicon
extends Object

This class implements a Lexicon.

Version:
0.9
Author:
© 1999-2000 Craig A. Rich <carich@acm.org>
See Also:
Source code

Inner Class Summary
protected static class Lexicon.Concatenation
          This class implements an Expression denoting the concatenation of two regular languages.
protected  class Lexicon.Exception
          This class implements an Exception.
protected static class Lexicon.Match
          This class implements an Expression denoting the set of characters in a string.
protected static class Lexicon.NonMatch
          This class implements an Expression denoting the set of characters not in a string.
protected static class Lexicon.PosixClass
          This class implements an Expression denoting the set of characters in a POSIX class.
protected static class Lexicon.Range
          This class implements an Expression denoting the set of characters in a range.
protected static class Lexicon.Repetition
          This class implements an Expression denoting the repetition of a regular language.
protected static class Lexicon.Singleton
          This class implements an Expression denoting the set containing a string.
protected static class Lexicon.UnicodeCategory
          This class implements an Expression denoting the set of characters in a Unicode category.
protected static class Lexicon.Union
          This class implements an Expression denoting the union of two regular languages.
 
Field Summary
protected static String END_OF_SOURCE
          The terminal matching the character at the end of a source stream.
 
Constructor Summary
protected Lexicon()
          Constructs an empty Lexicon.
 
Method Summary
protected static gi.Lexicon.Expression expression(String string)
          Creates an Expression by interpreting a POSIX extended regular expression (ERE), as used in egrep.
 Object grab(BufferedReader source)
          Grabs a terminal from a source character stream using this Lexicon.
protected  void put(Object terminal, gi.Lexicon.Expression expression)
          Puts a terminal and associated Expression into this Lexicon.
 String word()
          Returns the word most recently grabbed using this Lexicon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

END_OF_SOURCE

protected static final String END_OF_SOURCE

The terminal matching the character at the end of a source stream.

Constructor Detail

Lexicon

protected Lexicon()

Constructs an empty Lexicon.

Method Detail

expression

protected static gi.Lexicon.Expression expression(String string)
                                           throws Lexicon.Exception

Creates an Expression by interpreting a POSIX extended regular expression (ERE), as used in egrep. The syntax and semantics for EREs is formally specified by the ERE Grammar. Provides a convenient method for constructing an Expression, at the cost of an LR(1) parse. Implementations seeking maximum speed should avoid this method and use explicit Expression subclass constructors; for example,

new Union(new NonMatch("0"), new Singleton("foo"))
instead of
Lexicon.expression("[^0]|foo")
Parameters:
string - the POSIX extended regular expression (ERE) to be interpreted.
Returns:
the Expression constructed by interpreting string.
Throws:
Lexicon.Exception - if a syntax error occurs.

grab

public Object grab(BufferedReader source)
            throws Lexicon.Exception

Grabs a terminal from a source character stream using this Lexicon. The variable returned by word() is set to the longest nonempty prefix of the remaining source characters matching an Expression in this Lexicon. If no nonempty prefix matches an Expression, a Lexicon.Exception is thrown. If the longest matching prefix matches more than one Expression, the terminal associated with the Expression most recently constructed is returned. Blocks until a character is available, an I/O error occurs, or the end of the source stream is reached.

Parameters:
source - the source character stream.
Returns:
the terminal grabbed from source.
Throws:
Lexicon.Exception - if an I/O or lexical error occurs.

put

protected void put(Object terminal,
                   gi.Lexicon.Expression expression)

Puts a terminal and associated Expression into this Lexicon. The Expression supersedes any previously associated with the terminal.

Parameters:
terminal - the terminal to be added.
expression - the Expression associated with terminal. When grabbing, the language denoted by expression matches terminal.

word

public String word()

Returns the word most recently grabbed using this Lexicon.

Returns:
the word most recently grabbed by grab(source).

 

© 1999-2000 Craig A. Rich <carich@acm.org>