public abstract class Parser
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected ASTFactory |
astFactory
AST support code; parser delegates to this object.
|
protected ParserSharedInputState |
inputState |
protected AST |
returnAST
AST return value for a rule is squirreled away here
|
protected java.lang.String[] |
tokenNames
Table of token type to token names
|
protected java.util.Hashtable |
tokenTypeToASTClassMap
Constructed if any AST types specified in tokens{..}.
|
protected int |
traceDepth
Used to keep track of indentdepth for traceIn/Out
|
Constructor and Description |
---|
Parser() |
Parser(ParserSharedInputState state) |
Modifier and Type | Method and Description |
---|---|
void |
addMessageListener(MessageListener l) |
void |
addParserListener(ParserListener l) |
void |
addParserMatchListener(ParserMatchListener l) |
void |
addParserTokenListener(ParserTokenListener l) |
void |
addSemanticPredicateListener(SemanticPredicateListener l) |
void |
addSyntacticPredicateListener(SyntacticPredicateListener l) |
void |
addTraceListener(TraceListener l) |
abstract void |
consume()
Get another token object from the token stream
|
void |
consumeUntil(BitSet set)
Consume tokens until one matches the given token set
|
void |
consumeUntil(int tokenType)
Consume tokens until one matches the given token
|
protected void |
defaultDebuggingSetup(TokenStream lexer,
TokenBuffer tokBuf) |
AST |
getAST()
Get the AST return value squirreled away in the parser
|
ASTFactory |
getASTFactory() |
java.lang.String |
getFilename() |
ParserSharedInputState |
getInputState() |
java.lang.String |
getTokenName(int num) |
java.lang.String[] |
getTokenNames() |
java.util.Hashtable |
getTokenTypeToASTClassMap()
If the user specifies a tokens{} section with heterogeneous
AST node types, then ANTLR generates code to fill
this mapping.
|
boolean |
isDebugMode() |
abstract int |
LA(int i)
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).
|
abstract Token |
LT(int i)
Return the ith token of lookahead
|
int |
mark() |
void |
match(BitSet b)
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.
|
void |
match(int t)
Make sure current lookahead symbol matches token type t.
|
void |
matchNot(int t) |
static void |
panic()
Deprecated.
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. |
void |
recover(RecognitionException ex,
BitSet tokenSet) |
void |
removeMessageListener(MessageListener l) |
void |
removeParserListener(ParserListener l) |
void |
removeParserMatchListener(ParserMatchListener l) |
void |
removeParserTokenListener(ParserTokenListener l) |
void |
removeSemanticPredicateListener(SemanticPredicateListener l) |
void |
removeSyntacticPredicateListener(SyntacticPredicateListener l) |
void |
removeTraceListener(TraceListener l) |
void |
reportError(RecognitionException ex)
Parser error-reporting function can be overridden in subclass
|
void |
reportError(java.lang.String s)
Parser error-reporting function can be overridden in subclass
|
void |
reportWarning(java.lang.String s)
Parser warning-reporting function can be overridden in subclass
|
void |
rewind(int pos) |
void |
setASTFactory(ASTFactory f)
Specify an object with support code (shared by
Parser and TreeParser.
|
void |
setASTNodeClass(java.lang.String cl) |
void |
setASTNodeType(java.lang.String nodeType)
Deprecated.
since 2.7.1
|
void |
setDebugMode(boolean debugMode) |
void |
setFilename(java.lang.String f) |
void |
setIgnoreInvalidDebugCalls(boolean value) |
void |
setInputState(ParserSharedInputState state) |
void |
setTokenBuffer(TokenBuffer t)
Set or change the input token buffer
|
void |
traceIn(java.lang.String rname) |
void |
traceIndent() |
void |
traceOut(java.lang.String rname) |
protected ParserSharedInputState inputState
protected java.lang.String[] tokenNames
protected AST returnAST
protected ASTFactory astFactory
protected java.util.Hashtable tokenTypeToASTClassMap
protected int traceDepth
public Parser()
public Parser(ParserSharedInputState state)
public java.util.Hashtable getTokenTypeToASTClassMap()
public void addMessageListener(MessageListener l)
public void addParserListener(ParserListener l)
public void addParserMatchListener(ParserMatchListener l)
public void addParserTokenListener(ParserTokenListener l)
public void addSemanticPredicateListener(SemanticPredicateListener l)
public void addSyntacticPredicateListener(SyntacticPredicateListener l)
public void addTraceListener(TraceListener l)
public abstract void consume() throws TokenStreamException
TokenStreamException
public void consumeUntil(int tokenType) throws TokenStreamException
TokenStreamException
public void consumeUntil(BitSet set) throws TokenStreamException
TokenStreamException
protected void defaultDebuggingSetup(TokenStream lexer, TokenBuffer tokBuf)
public AST getAST()
public ASTFactory getASTFactory()
public java.lang.String getFilename()
public ParserSharedInputState getInputState()
public void setInputState(ParserSharedInputState state)
public java.lang.String getTokenName(int num)
public java.lang.String[] getTokenNames()
public boolean isDebugMode()
public abstract int LA(int i) throws TokenStreamException
TokenStreamException
public abstract Token LT(int i) throws TokenStreamException
TokenStreamException
public int mark()
public void match(int t) throws MismatchedTokenException, TokenStreamException
public void match(BitSet b) throws MismatchedTokenException, TokenStreamException
public void matchNot(int t) throws MismatchedTokenException, TokenStreamException
public static void panic()
static
, it cannot be overridden to avoid these problems.
ANTLR no longer uses this method internally or in generated code.public void removeMessageListener(MessageListener l)
public void removeParserListener(ParserListener l)
public void removeParserMatchListener(ParserMatchListener l)
public void removeParserTokenListener(ParserTokenListener l)
public void removeSemanticPredicateListener(SemanticPredicateListener l)
public void removeSyntacticPredicateListener(SyntacticPredicateListener l)
public void removeTraceListener(TraceListener l)
public void reportError(RecognitionException ex)
public void reportError(java.lang.String s)
public void reportWarning(java.lang.String s)
public void recover(RecognitionException ex, BitSet tokenSet) throws TokenStreamException
TokenStreamException
public void rewind(int pos)
public void setASTFactory(ASTFactory f)
public void setASTNodeClass(java.lang.String cl)
public void setASTNodeType(java.lang.String nodeType)
public void setDebugMode(boolean debugMode)
public void setFilename(java.lang.String f)
public void setIgnoreInvalidDebugCalls(boolean value)
public void setTokenBuffer(TokenBuffer t)
public void traceIndent()
public void traceIn(java.lang.String rname) throws TokenStreamException
TokenStreamException
public void traceOut(java.lang.String rname) throws TokenStreamException
TokenStreamException