|
Generic Interpreter 1.2 Protected API |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgi.Lexicon
This class implements a Lexicon.
| Nested Class Summary | |
protected static class |
Lexicon.Alphabet
This class implements an of character symbols. |
protected static class |
Lexicon.Concatenation
This class implements an expressing the concatenation of two regular languages. |
protected class |
Lexicon.Exception
This class implements an . |
protected static class |
Lexicon.Expression
This class implements an expressing a regular language. |
protected static class |
Lexicon.Match
This class implements an containing some characters. |
protected static class |
Lexicon.NonMatch
This class implements an containing all except some characters. |
protected static class |
Lexicon.PosixClass
This class implements an containing the characters in a POSIX character class. |
protected static class |
Lexicon.Range
This class implements an containing the characters in a range. |
protected static class |
Lexicon.Repetition
This class implements an expressing the repetition of a regular language. |
protected static class |
Lexicon.Singleton
This class implements an expressing a singleton language. |
protected static class |
Lexicon.UnicodeCategory
This class implements an containing the characters in a Unicode general category. |
protected static class |
Lexicon.Union
This class implements an expressing the union of two regular languages. |
| Field Summary | |
protected static Object |
$
The terminal matched by the character at the end of a source stream. |
protected int |
debug
The debug switches, initially zero. |
protected static int |
LEXICAL
switch constant enabling printing terminals and associated words grabbed during lexical analysis. |
protected static int |
TERMINALS
switch constant enabling printing the set of terminals before lexical analysis. |
protected static int |
VERBOSE
switch constant enabling all debugging. |
| Constructor Summary | |
protected |
Lexicon()
Constructs an empty Lexicon. |
| Method Summary | |
protected static Lexicon.Expression |
expression(String ere)
Creates an Expression by interpreting a POSIX extended regular expression (ERE), as used in egrep. |
protected Object |
grab(LineNumberReader source)
Grabs a terminal from a source character stream using this Lexicon. |
Object |
interpret()
Interprets the standard input stream using this Lexicon. |
Object |
interpret(File source)
Interprets a source file using this Lexicon. |
Object |
interpret(InputStream source)
Interprets a source byte stream using this Lexicon. |
Object |
interpret(PipedWriter source)
Interprets a source pipe using this Lexicon. |
Object |
interpret(Reader source)
Interprets a source character stream using this Lexicon. |
Object |
interpret(String source)
Interprets a source string using this Lexicon. |
void |
interpret(String[] arguments)
Lexical analysis by command-line arguments using this Lexicon. |
protected void |
put(Object a,
Lexicon.Expression e)
Puts a terminal and associated Expression into this Lexicon. |
protected 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 |
protected static final Object $
The terminal matched by the character at the end of a source stream.
END_OF_SOURCE in version 1.0.protected int debug
The debug switches, initially zero. The following bits enable debugging to standard output:
0x01=TERMINALS- Print the set of terminals before lexical analysis
0x02=LEXICAL- Print terminals and associated words grabbed during lexical analysis
0x04=FIRST_FOLLOW- Print first and follow sets precomputed during syntax analysis
0x08=SYNTAX- Print parsing decisions made during syntax analysis
0x10=CONFLICT- Print parsing conflicts encountered during syntax analysis
0x20=PARSE_TREE- Print each
ParseTreeproduced by syntax analysis
protected static final int LEXICAL
switch constant enabling printing terminals and associated words grabbed during lexical analysis.debug
protected static final int TERMINALS
switch constant enabling printing the set of terminals before lexical analysis.debug
protected static final int VERBOSE
switch constant enabling all debugging.debug
| Constructor Detail |
protected Lexicon()
Constructs an empty Lexicon.
| Method Detail |
protected static Lexicon.Expression expression(String ere)
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
expression("[^0]|foo")
ere - the POSIX extended regular expression (ERE) to interpret.
Expression constructed by interpreting string.
Lexicon.Exception - if an ERE syntax error occurs.
protected Object grab(LineNumberReader 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.
source - the source character stream.
source.
Lexicon.Exception - if an I/O or lexical error occurs.
public Object interpret()
throws Lexicon.Exception
Interprets the standard input stream using this Lexicon.
ParseTree constructed by interpreting the standard input stream.
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.
public Object interpret(File source)
throws FileNotFoundException,
Lexicon.Exception
Interprets a source file using this Lexicon.
source - the source file.
ParseTree constructed by interpreting source.
FileNotFoundException - if the source file cannot be found.
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.
public Object interpret(InputStream source)
throws Lexicon.Exception
Interprets a source byte stream using this Lexicon.
source - the source byte stream.
ParseTree constructed by interpreting source.
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.
public Object interpret(PipedWriter source)
throws IOException,
Lexicon.Exception
Interprets a source pipe using this Lexicon.
source - the source pipe.
ParseTree constructed by interpreting source.
IOException - if the source pipe cannot be connected.
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.
public Object interpret(Reader source)
throws Lexicon.Exception
Interprets a source character stream using this Lexicon.
source - the source character stream.
ParseTree constructed by interpreting source.
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.
public Object interpret(String source)
throws Lexicon.Exception
Interprets a source string using this Lexicon.
source - the source string.
ParseTree constructed by interpreting source.
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.public void interpret(String[] arguments)
Lexical analysis by command-line arguments using this Lexicon. The first I/O or lexical error that occurs during lexical analysis is printed to the standard error stream.
arguments - the command-line arguments controlling the interpreter.
The following arguments may appear zero or more times, are processed in order, and have the following effects:If no
-t,--terminals- Print the set of terminals in this
Lexiconbefore subsequent lexical analyses.-l,--lexical- Print terminals in this
Lexicongrabbed during subsequent lexical analyses.-v,--verbose- Print maximum debugging. Equivalent to
-tl.-- Lexically analyze the standard input stream using this
Lexicon.filename- Lexically analyze source file
filenameusing thisLexicon.filenamearguments are given, the standard input stream is lexically analyzed.
protected void put(Object a,
Lexicon.Expression e)
Puts a terminal and associated Expression into this Lexicon. The Expression supersedes any previously associated with the terminal.
a - the terminal to add to this Lexicon.e - the Expression associated with terminal a. When grabbing, the language expressed by e matches a.protected String word()
Returns the word most recently grabbed using this Lexicon.
grab(source).
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||