sjm.parse
Class Terminal
java.lang.Object
|
+--sjm.parse.Parser
|
+--sjm.parse.Terminal
- Direct Known Subclasses:
- Char, Digit, Letter, Literal, Num, QuotedString, SpecificChar, SpecificTerminal, Symbol, Word
- public class Terminal
- extends Parser
A Terminal
is a parser that is not a
composition of other parsers. Terminals are "terminal"
because they do not pass matching work on to other
parsers. The criterion that terminals use to check a
match is something other than another parser. Terminals
are also the only parsers that advance an assembly.
- Version:
- 1.0
- Author:
- Steven J. Metsker
Field Summary |
protected boolean |
discard
|
Constructor Summary |
Terminal()
Constructs an unnamed terminal. |
Terminal(java.lang.String name)
Constructs a terminal with the given name. |
Method Summary |
void |
accept(ParserVisitor pv,
java.util.Vector visited)
Accept a "visitor" and a collection of previously visited
parsers. |
Terminal |
discard()
A convenience method that sets discarding to be true. |
java.util.Vector |
match(java.util.Vector in)
Given a collection of assemblies, this method matches
this terminal against all of them, and returns a new
collection of the assemblies that result from the
matches. |
protected Assembly |
matchOneAssembly(Assembly in)
Returns an assembly equivalent to the supplied assembly,
except that this terminal will have been removed from the
front of the assembly. |
protected boolean |
qualifies(java.lang.Object o)
The mechanics of matching are the same for many terminals,
except for the check that the next element on the assembly
qualifies as the type of terminal this terminal looks for.
|
java.util.Vector |
randomExpansion(int maxDepth,
int depth)
|
Terminal |
setDiscard(boolean discard)
By default, terminals push themselves upon a assembly's
stack, after a successful match. |
protected java.lang.String |
unvisitedString(java.util.Vector visited)
|
Methods inherited from class sjm.parse.Parser |
accept, add, best, bestMatch, completeMatch, elementClone, getName, matchAndAssemble, randomInput, setAssembler, toString, toString |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
discard
protected boolean discard
Terminal
public Terminal()
- Constructs an unnamed terminal.
Terminal
public Terminal(java.lang.String name)
- Constructs a terminal with the given name.
- Parameters:
String
- A name to be known by.
accept
public void accept(ParserVisitor pv,
java.util.Vector visited)
- Accept a "visitor" and a collection of previously visited
parsers.
- Overrides:
accept
in class Parser
- Parameters:
ParserVisitor
- the visitor to acceptVector
- a collection of previously visited parsers
discard
public Terminal discard()
- A convenience method that sets discarding to be true.
- Returns:
- this
match
public java.util.Vector match(java.util.Vector in)
- Given a collection of assemblies, this method matches
this terminal against all of them, and returns a new
collection of the assemblies that result from the
matches.
- Overrides:
match
in class Parser
- Parameters:
Vector
- a vector of assemblies to match against- Returns:
- a Vector of assemblies that result from
matching against a beginning set of assemblies
matchOneAssembly
protected Assembly matchOneAssembly(Assembly in)
- Returns an assembly equivalent to the supplied assembly,
except that this terminal will have been removed from the
front of the assembly. As with any parser, if the
match succeeds, this terminal's assembler will work on
the assembly. If the match fails, this method returns
null.
- Parameters:
Assembly
- the assembly to match against- Returns:
- a copy of the incoming assembly, advanced by this
terminal
qualifies
protected boolean qualifies(java.lang.Object o)
- The mechanics of matching are the same for many terminals,
except for the check that the next element on the assembly
qualifies as the type of terminal this terminal looks for.
This method performs that check.
- Parameters:
Object
- an element from a assembly- Returns:
- true, if the object is the kind of terminal this
parser seeks
randomExpansion
public java.util.Vector randomExpansion(int maxDepth,
int depth)
- Overrides:
randomExpansion
in class Parser
setDiscard
public Terminal setDiscard(boolean discard)
- By default, terminals push themselves upon a assembly's
stack, after a successful match. This routine will turn
off (or turn back on) that behavior.
- Parameters:
boolean
- true, if this terminal should push
itself on a assembly's stack- Returns:
- this
unvisitedString
protected java.lang.String unvisitedString(java.util.Vector visited)
- Overrides:
unvisitedString
in class Parser