A generic ANTLR parser (LL(k) for k>=1) containing a bunch of
utility routines useful at any lookahead depth. We distinguish between
the LL(1) and LL(k) parsers because of efficiency. This may not be
necessary in the near future.
Each parser object contains the state of the parse including a lookahead
cache (the form of which is determined by the subclass), whether or
not the parser is in guess mode, where tokens come from, etc...
During
guess mode, the current lookahead token(s) and token type(s)
cache must be saved because the token stream may not have been informed
to save the token (via
mark) before the
try block.
Guessing is started by:
- saving the lookahead cache.
- marking the current position in the TokenBuffer.
- increasing the guessing level.
After guessing, the parser state is restored by:
- restoring the lookahead cache.
- rewinding the TokenBuffer.
- decreasing the guessing level.
LA
public abstract int LA(int i)
throws TokenStreamException
Return the token type of the ith token of lookahead where i=1
is the current token being examined by the parser (i.e., it
has not been matched yet).
consume
public abstract void consume()
throws TokenStreamException
Get another token object from the token stream
consumeUntil
public void consumeUntil(int tokenType)
throws TokenStreamException
Consume tokens until one matches the given token
getAST
public AST getAST()
Get the AST return value squirreled away in the parser
getFilename
public String getFilename()
getTokenName
public String getTokenName(int num)
getTokenNames
public String[] getTokenNames()
getTokenTypeToASTClassMap
public Hashtable getTokenTypeToASTClassMap()
If the user specifies a tokens{} section with heterogeneous
AST node types, then ANTLR generates code to fill
this mapping.
isDebugMode
public boolean isDebugMode()
match
public void match(BitSet b)
throws MismatchedTokenException,
TokenStreamException
Make sure current lookahead symbol matches the given set
Throw an exception upon mismatch, which is catch by either the
error handler or by the syntactic predicate.
match
public void match(int t)
throws MismatchedTokenException,
TokenStreamException
Make sure current lookahead symbol matches token type t.
Throw an exception upon mismatch, which is catch by either the
error handler or by the syntactic predicate.
panic
public static void panic()
as of 2.7.2. This method calls System.exit() and writes
directly to stderr, which is usually not appropriate when
a parser is embedded into a larger application. Since the method is
static
, it cannot be overridden to avoid these problems.
ANTLR no longer uses this method internally or in generated code.
removeParserListener
public void removeParserListener(ParserListener l)
removeTraceListener
public void removeTraceListener(TraceListener l)
reportError
public void reportError(String s)
Parser error-reporting function can be overridden in subclass
reportError
public void reportError(RecognitionException ex)
Parser error-reporting function can be overridden in subclass
reportWarning
public void reportWarning(String s)
Parser warning-reporting function can be overridden in subclass
rewind
public void rewind(int pos)
setASTFactory
public void setASTFactory(ASTFactory f)
Specify an object with support code (shared by
Parser and TreeParser. Normally, the programmer
does not play with this, using setASTNodeType instead.
setASTNodeClass
public void setASTNodeClass(String cl)
setASTNodeType
public void setASTNodeType(String nodeType)
since 2.7.1
Specify the type of node to create during tree building; use setASTNodeClass now
to be consistent with Token Object Type accessor.
setDebugMode
public void setDebugMode(boolean debugMode)
setFilename
public void setFilename(String f)
setIgnoreInvalidDebugCalls
public void setIgnoreInvalidDebugCalls(boolean value)
setTokenBuffer
public void setTokenBuffer(TokenBuffer t)
Set or change the input token buffer
traceIndent
public void traceIndent()