|
Generic Interpreter 0.9 Protected API |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gi.Lexicon | +--gi.Grammar
This class implements a Grammar
.
Inner Class Summary | |
protected static class |
Grammar.ParseTree
This class implements a constructed by interpreting a source stream. |
protected static class |
Grammar.Semantics
This class implements embedded in productions and evaluated when interpreting. |
Inner classes inherited from class gi.Lexicon |
Lexicon.Concatenation, Lexicon.Exception, Lexicon.Match, Lexicon.NonMatch, Lexicon.PosixClass, Lexicon.Range, Lexicon.Repetition, Lexicon.Singleton, Lexicon.UnicodeCategory, Lexicon.Union |
Fields inherited from class gi.Lexicon |
END_OF_SOURCE |
Constructor Summary | |
protected |
Grammar()
Constructs an empty Grammar . |
Method Summary | |
Object |
grab(BufferedReader source)
Grabs terminals from a source character stream using this Grammar . |
Grammar.ParseTree |
interpret()
Interprets the standard input stream using this Grammar . |
Grammar.ParseTree |
interpret(File source)
Interprets a source file using this Grammar . |
Grammar.ParseTree |
interpret(InputStream source)
Interprets a source byte stream using this Grammar . |
Grammar.ParseTree |
interpret(PipedWriter source)
Interprets a source pipe using this Grammar . |
Grammar.ParseTree |
interpret(Reader source)
Interprets a source character stream using this Grammar . |
Grammar.ParseTree |
interpret(String source)
Interprets a source string using this Grammar . |
Grammar.ParseTree |
interpret(String[] argv)
Interprets by command-line arguments using this Grammar . |
protected void |
put(Object nonterminal,
Object[] phrase)
Puts a production into this Grammar . |
protected void |
put(Object nonterminal,
Object[][] phrases)
Puts productions into this Grammar . |
Methods inherited from class gi.Lexicon |
expression, put, word |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected Grammar()
Constructs an empty Grammar
.
Method Detail |
public Object grab(BufferedReader source) throws Lexicon.Exception
Grabs terminals from a source character stream using this Grammar
. Invokes
until it returns a terminal occurring in a phrase of this Lexicon.grab(source)
Grammar
or end of source. Blocks until a character is available, an I/O error occurs, or the end of the source stream is reached.
grab
in class Lexicon
source
- the source character stream.Grammar
.Lexicon.Exception
- if an I/O or lexical error occurs.public Grammar.ParseTree interpret() throws Lexicon.Exception
Interprets the standard input stream using this Grammar
.
ParseTree
constructed by interpreting the standard input stream.Lexicon.Exception
- if an I/O, lexical, syntax or semantic error occurs.public Grammar.ParseTree interpret(File source) throws FileNotFoundException, Lexicon.Exception
Interprets a source file using this Grammar
.
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 Grammar.ParseTree interpret(InputStream source) throws Lexicon.Exception
Interprets a source byte stream using this Grammar
.
source
- the source byte stream.ParseTree
constructed by interpreting source
.Lexicon.Exception
- if an I/O, lexical, syntax or semantic error occurs.public Grammar.ParseTree interpret(PipedWriter source) throws IOException, Lexicon.Exception
Interprets a source pipe using this Grammar
.
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 Grammar.ParseTree interpret(Reader source) throws Lexicon.Exception
Interprets a source character stream using this Grammar
.
source
- the source character stream.ParseTree
constructed by interpreting source
.Lexicon.Exception
- if an I/O, lexical, syntax or semantic error occurs.public Grammar.ParseTree interpret(String source) throws Lexicon.Exception
Interprets a source string using this Grammar
.
source
- the source string.ParseTree
constructed by interpreting source
.Lexicon.Exception
- if an I/O, lexical, syntax or semantic error occurs.public Grammar.ParseTree interpret(String[] argv)
Interprets by command-line arguments using this Grammar
. When interpreting, the parser used will be (in order):
The first I/O, lexical, syntax or semantic error that occurs when interpreting is printed to the standard error stream. If requested, each
- The parser most recently constructed by preceding command-line arguments.
- The parser originally around this
Grammar
.- An LR(1) parser.
ParseTree
is printed to the standard error stream after interpreting.argv
- 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
-tree
- Print each
ParseTree
subsequently constructed by interpreting a source stream.-ll1
- Construct an
LL(1) parser
around thisGrammar
.-lr0
- Construct an
LR(0) parser
around thisGrammar
.-slr1
- Construct an
SLR(1) parser
around thisGrammar
.-lr1
- Construct an
LR(1) parser
around thisGrammar
.-
- Interpret the standard input stream using this
Grammar
.filename
- Interpret source file
filename
using thisGrammar
.filename
arguments are given, the standard input stream is interpreted.
ParseTree
constructed by interpreting a source stream.protected void put(Object nonterminal, Object[] phrase)
Puts a production into this Grammar
. The start symbol is the first nonterminal put in this Grammar
.
nonterminal
- the nonterminal to be added to this Grammar
.phrase
- the phrase produced by nonterminal
. phrase
may contain nonterminals, terminals, and Semantics
.protected void put(Object nonterminal, Object[][] phrases)
Puts productions into this Grammar
. The productions are successively added using
.put(nonterminal, phrase)
nonterminal
- the nonterminal on the left-hand side of the production.phrases
- the phrases produced by nonterminal
. Each phrase in phrases
may contain nonterminals, terminals, and Semantics
.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |