|
Generic Interpreter 1.2 Private API |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgi.Lexicon
gi.Grammar
This class implements a Grammar.
| Nested Class Summary | |
protected static class |
Grammar.ParseTree
This class implements a constructed by interpreting a source stream. |
(package private) static class |
Grammar.Production
This class implements a . |
protected static class |
Grammar.Semantics
This class implements embedded in productions and evaluated when interpreting. |
| Nested classes inherited from class gi.Lexicon |
Lexicon.Alphabet, Lexicon.Concatenation, Lexicon.Exception, Lexicon.Expression, Lexicon.Match, Lexicon.NonMatch, Lexicon.PosixClass, Lexicon.Range, Lexicon.Repetition, Lexicon.Set, Lexicon.Singleton, Lexicon.Stack, Lexicon.UnicodeCategory, Lexicon.Union |
| Field Summary | |
protected static int |
CONFLICT
switch constant enables printing parsing conflicts encountered during syntax analysis. |
private Map |
first
The mapping from a nonterminal to its first set in this Grammar. |
private Lexicon.Set |
first_beta
A first set computed by . |
protected static int |
FIRST_FOLLOW
switch constant enables printing first and follow sets precomputed during syntax analysis. |
private Map |
follow
The mapping from a nonterminal to its follow set in this Grammar. |
(package private) Map |
P
The Productions put into this Grammar. |
protected static int |
PARSE_TREE
switch constant enables printing each ParseTree produced by syntax analysis. |
private static int |
PSize
The number of Productions constructed. |
(package private) Object |
S
The start symbol of this Grammar. |
protected static int |
SYNTAX
switch constant enables printing parsing decisions made during syntax analysis. |
private HashSet |
T
The terminals put into this Grammar. |
| Fields inherited from class gi.Lexicon |
$, debug, LEXICAL, TERMINALS, VERBOSE |
| Constructor Summary | |
protected |
Grammar()
Constructs an empty Grammar. |
(package private) |
Grammar(Grammar G)
Constructs a Grammar that is a shallow copy of G. |
| Method Summary | |
(package private) Lexicon.Set |
first(Object nonterminal)
Returns the first set of a nonterminal. |
(package private) Lexicon.Set |
first(Object[] beta)
Computes the first set of a phrase. |
(package private) Lexicon.Set |
first(Object[] beta,
int start)
Computes the first set of a phrase. |
(package private) Lexicon.Set |
follow(Object nonterminal)
Returns the follow set of a nonterminal. |
protected Object |
grab(LineNumberReader source)
Grabs a terminal from a source character stream using this Grammar. |
(package private) Object |
interpret(LineNumberReader source)
Interprets a source character stream using an LR(1) parser around this Grammar. |
void |
interpret(String[] arguments)
Interprets by command-line arguments using this Grammar. |
(package private) boolean |
nonterminal(Object X)
Indicates whether a symbol is a nonterminal in 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. |
(package private) boolean |
terminal(Object X)
Indicates whether a symbol is a terminal in this Grammar. |
| Methods inherited from class gi.Lexicon |
expression, interpret, interpret, interpret, interpret, interpret, interpret, put, word |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final int CONFLICT
switch constant enables printing parsing conflicts encountered during syntax analysis.debug
private final Map first
The mapping from a nonterminal to its first set in this Grammar. When empty, there is a need to compute current first sets. It is computed only on demand created by .first(nonterminal)
private final Lexicon.Set first_beta
A first set computed by .first(beta, start)
protected static final int FIRST_FOLLOW
switch constant enables printing first and follow sets precomputed during syntax analysis.debug
private final Map follow
The mapping from a nonterminal to its follow set in this Grammar. When empty, there is a need to compute current follow sets. It is computed only on demand created by .follow(nonterminal)
final Map P
The Productions put into this Grammar. It is a mapping from a nonterminal to its Productions.
protected static final int PARSE_TREE
switch constant enables printing each debugParseTree produced by syntax analysis.
private static int PSize
The number of Productions constructed.
Object S
The start symbol of this Grammar. It is the nonterminal on the left side of the Production first put into this Grammar.
protected static final int SYNTAX
switch constant enables printing parsing decisions made during syntax analysis.debug
private final HashSet T
The terminals put into this Grammar. When empty, there is a need to discover terminals. It is computed only on demand created by .terminal(X)
| Constructor Detail |
protected Grammar()
Constructs an empty Grammar.
Grammar(Grammar G)
Constructs a Grammar that is a shallow copy of G. The fields of the new Grammar refer to the same objects as those in G.
G - the Grammar copied.| Method Detail |
Lexicon.Set first(Object nonterminal)
Returns the first set of a nonterminal.
nonterminal - the nonterminal whose first set is requested.
first.get(nonterminal), computing first if there is a need to compute current first sets.Lexicon.Set first(Object[] beta)
Computes the first set of a phrase.
beta - the phrase whose first set is computed.
beta).
Lexicon.Set first(Object[] beta,
int start)
Computes the first set of a phrase.
beta - the phrase whose first set is computed.start - the index at which to start computing the first set.
beta[start..beta.length-1]).Lexicon.Set follow(Object nonterminal)
Returns the follow set of a nonterminal.
nonterminal - the nonterminal whose follow set is requested.
follow.get(nonterminal), computing follow if there is a need to compute current follow sets.
protected Object grab(LineNumberReader source)
throws Lexicon.Exception
Grabs a terminal 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 Lexiconsource - the source character stream.
Grammar.
Lexicon.Exception - if an I/O or lexical error occurs.
Object interpret(LineNumberReader source)
throws Lexicon.Exception
Interprets a source character stream using an LR(1) parser around this Grammar. This method is overridden by all parsers, so it is only invoked when this Grammar has not been extended by a parser.
interpret in class Lexiconsource - the source character stream.
ParseTree constructed by interpreting source.
Lexicon.Exception - if an I/O, lexical, syntax or semantic error occurs.public void interpret(String[] arguments)
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.
- The parser most recently constructed by preceding command-line arguments.
- The parser originally around this
Grammar.- An LR(1) parser.
interpret in class Lexiconarguments - 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
Grammarbefore subsequent syntax analyses.-l,--lexical- Print terminals in this
Grammargrabbed during subsequent syntax analyses.-f,--firstfollow- Print first and follow sets precomputed during subsequent syntax analyses.
-s,--syntax- Print parsing decisions made during subsequent syntax analyses.
-c,--conflict- Print parsing conflicts encountered during subsequent syntax analyses.
-p,--parsetree,--tree- Print each
ParseTreeproduced by subsequent syntax analyses.-v,--verbose- Print maximum debugging. Equivalent to
-tlfscp.--ll1- Construct an
LL(1) parseraround thisGrammar.--lr0- Construct an
LR(0) parseraround thisGrammar.--slr1- Construct an
SLR(1) parseraround thisGrammar.--lr1- Construct an
LR(1) parseraround thisGrammar.-- Interpret the standard input stream using this
Grammar.filename- Interpret source file
filenameusing thisGrammar.filenamearguments are given, the standard input stream is interpreted.
boolean nonterminal(Object X)
Indicates whether a symbol is a nonterminal in this Grammar.
X - the symbol whose status is requested.
true if X is a nonterminal in this Grammar; false otherwise.
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 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 side of the productions.phrases - the phrases produced by nonterminal. Each phrase in phrases may contain nonterminals, terminals, and Semantics.boolean terminal(Object X)
Indicates whether a symbol is a terminal in this Grammar.
terminal in class LexiconX - the symbol whose status is requested.
true if X is a terminal in this Grammar; false otherwise.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||