public abstract class Parser extends Recognizer<Token,ParserATNSimulator>
| Modifier and Type | Class and Description | 
|---|---|
class  | 
Parser.TraceListener  | 
static class  | 
Parser.TrimToSizeListener  | 
| Modifier and Type | Field and Description | 
|---|---|
protected boolean | 
_buildParseTrees
Specifies whether or not the parser should construct a parse tree during
 the parsing process. 
 | 
protected ParserRuleContext | 
_ctx
The  
ParserRuleContext object for the currently executing rule. | 
protected ANTLRErrorStrategy | 
_errHandler
The error handling strategy for the parser. 
 | 
protected TokenStream | 
_input
The input stream. 
 | 
protected List<ParseTreeListener> | 
_parseListeners
The list of  
ParseTreeListener listeners registered to receive
 events during the parse. | 
protected int | 
_syntaxErrors
The number of syntax errors reported during parsing. 
 | 
_interp, EOF| Constructor and Description | 
|---|
Parser(TokenStream input)  | 
| Modifier and Type | Method and Description | 
|---|---|
protected void | 
addContextToParseTree()  | 
void | 
addParseListener(ParseTreeListener listener)
Registers  
listener to receive events during the parsing process. | 
Token | 
consume()
Consume and return the current symbol. 
 | 
void | 
dumpDFA()
For debugging and other purposes. 
 | 
void | 
enterOuterAlt(ParserRuleContext localctx,
             int altNum)  | 
void | 
enterRecursionRule(ParserRuleContext localctx,
                  int ruleIndex)  | 
void | 
enterRule(ParserRuleContext localctx,
         int state,
         int ruleIndex)
Always called by generated parsers upon entry to a rule. 
 | 
void | 
exitRule()  | 
boolean | 
getBuildParseTree()
Gets whether or not a complete parse tree will be constructed while
 parsing. 
 | 
ParserRuleContext | 
getContext()  | 
Token | 
getCurrentToken()
Match needs to return the current input symbol, which gets put
  into the label for the associated token ref; e.g., x=ID. 
 | 
List<String> | 
getDFAStrings()
For debugging and other purposes. 
 | 
ANTLRErrorStrategy | 
getErrorHandler()  | 
IntervalSet | 
getExpectedTokens()
Computes the set of input symbols which could follow the current parser
 state and context, as given by  
Recognizer.getState() and getContext(),
 respectively. | 
IntervalSet | 
getExpectedTokensWithinCurrentRule()  | 
TokenStream | 
getInputStream()  | 
ParserRuleContext | 
getInvokingContext(int ruleIndex)  | 
int | 
getNumberOfSyntaxErrors()
Gets the number of syntax errors reported during parsing. 
 | 
List<ParseTreeListener> | 
getParseListeners()  | 
ParserRuleContext | 
getRuleContext()  | 
List<String> | 
getRuleInvocationStack()
Return List<String> of the rule names in your parser instance
  leading up to a call to the current rule. 
 | 
List<String> | 
getRuleInvocationStack(RuleContext p)  | 
String | 
getSourceName()  | 
TokenFactory<?> | 
getTokenFactory()  | 
TokenStream | 
getTokenStream()  | 
boolean | 
getTrimParseTree()  | 
boolean | 
inContext(String context)  | 
boolean | 
isExpectedToken(int symbol)
Checks whether or not  
symbol can follow the current state in the
 ATN. | 
Token | 
match(int ttype)
Match current input symbol against  
ttype. | 
Token | 
matchWildcard()
Match current input symbol as a wildcard. 
 | 
void | 
notifyErrorListeners(String msg)  | 
void | 
notifyErrorListeners(Token offendingToken,
                    String msg,
                    RecognitionException e)  | 
void | 
pushNewRecursionContext(ParserRuleContext localctx,
                       int state,
                       int ruleIndex)
Like  
enterRule(org.antlr.v4.runtime.ParserRuleContext, int, int) but for recursive rules. | 
void | 
removeParseListener(ParseTreeListener listener)
Remove  
listener from the list of parse listeners. | 
void | 
removeParseListeners()
Remove all parse listeners. 
 | 
void | 
reset()
reset the parser's state 
 | 
void | 
setBuildParseTree(boolean buildParseTrees)
Track the  
ParserRuleContext objects during the parse and hook
 them up using the ParserRuleContext.children list so that it
 forms a parse tree. | 
void | 
setErrorHandler(ANTLRErrorStrategy handler)  | 
void | 
setInputStream(IntStream input)  | 
void | 
setTokenFactory(TokenFactory<?> factory)
Tell our token source and error strategy about a new way to create tokens. 
 | 
void | 
setTokenStream(TokenStream input)
Set the token stream and reset the parser. 
 | 
void | 
setTrace(boolean trace)
During a parse is sometimes useful to listen in on the rule entry and exit
  events as well as token matches. 
 | 
void | 
setTrimParseTree(boolean trimParseTrees)
Trim the internal lists of the parse tree during parsing to conserve memory. 
 | 
protected void | 
triggerEnterRuleEvent()
Notify any parse listeners of an enter rule event. 
 | 
protected void | 
triggerExitRuleEvent()
Notify any parse listeners of an exit rule event. 
 | 
void | 
unrollRecursionContexts(ParserRuleContext _parentctx)  | 
action, addErrorListener, getATN, getErrorHeader, getErrorListenerDispatch, getErrorListeners, getGrammarFileName, getInterpreter, getRuleNames, getState, getTokenErrorDisplay, getTokenNames, removeErrorListener, removeErrorListeners, sempred, setInterpreter, setState@NotNull protected ANTLRErrorStrategy _errHandler
DefaultErrorStrategy.protected TokenStream _input
protected ParserRuleContext _ctx
ParserRuleContext object for the currently executing rule.
 This is always non-null during the parsing process.protected boolean _buildParseTrees
true.@Nullable protected List<ParseTreeListener> _parseListeners
ParseTreeListener listeners registered to receive
 events during the parse.protected int _syntaxErrors
notifyErrorListeners(java.lang.String) is called.public Parser(TokenStream input)
public void reset()
@NotNull public Token match(int ttype) throws RecognitionException
ttype. If the symbol type
 matches, ANTLRErrorStrategy.reportMatch(org.antlr.v4.runtime.Parser) and consume() are
 called to complete the match process.
 
 If the symbol type does not match,
 ANTLRErrorStrategy.recoverInline(org.antlr.v4.runtime.Parser) is called on the current error
 strategy to attempt recovery. If getBuildParseTree() is
 true and the token index of the symbol returned by
 ANTLRErrorStrategy.recoverInline(org.antlr.v4.runtime.Parser) is -1, the symbol is added to
 the parse tree by calling ParserRuleContext.addErrorNode(org.antlr.v4.runtime.Token).ttype - the token type to matchRecognitionException - if the current input symbol did not match
 ttype and the error strategy could not recover from the
 mismatched symbol@NotNull public Token matchWildcard() throws RecognitionException
ANTLRErrorStrategy.reportMatch(org.antlr.v4.runtime.Parser)
 and consume() are called to complete the match process.
 
 If the symbol type does not match,
 ANTLRErrorStrategy.recoverInline(org.antlr.v4.runtime.Parser) is called on the current error
 strategy to attempt recovery. If getBuildParseTree() is
 true and the token index of the symbol returned by
 ANTLRErrorStrategy.recoverInline(org.antlr.v4.runtime.Parser) is -1, the symbol is added to
 the parse tree by calling ParserRuleContext.addErrorNode(org.antlr.v4.runtime.Token).RecognitionException - if the current input symbol did not match
 a wildcard and the error strategy could not recover from the mismatched
 symbolpublic void setBuildParseTree(boolean buildParseTrees)
ParserRuleContext objects during the parse and hook
 them up using the ParserRuleContext.children list so that it
 forms a parse tree. The ParserRuleContext returned from the start
 rule represents the root of the parse tree.
 
 Note that if we are not building parse trees, rule contexts only point
 upwards. When a rule exits, it returns the context but that gets garbage
 collected if nobody holds a reference. It points upwards but nobody
 points at it.
 
 When we build parse trees, we are adding all of these contexts to
 ParserRuleContext.children list. Contexts are then not candidates
 for garbage collection.public boolean getBuildParseTree()
true for a newly constructed parser.true if a complete parse tree will be constructed while
 parsing, otherwise falsepublic void setTrimParseTree(boolean trimParseTrees)
false by default for a newly constructed parser.trimParseTrees - true to trim the capacity of the ParserRuleContext.children
 list to its size after a rule is parsed.public boolean getTrimParseTree()
true if the ParserRuleContext.children list is trimmed
 using the default Parser.TrimToSizeListener during the parse process.@NotNull public List<ParseTreeListener> getParseListeners()
public void addParseListener(@NotNull ParseTreeListener listener)
listener to receive events during the parsing process.
 
 To support output-preserving grammar transformations (including but not
 limited to left-recursion removal, automated left-factoring, and
 optimized code generation), calls to listener methods during the parse
 may differ substantially from calls made by
 ParseTreeWalker.DEFAULT used after the parse is complete. In
 particular, rule entry and exit events may occur in a different order
 during the parse than after the parser. In addition, calls to certain
 rule entry methods may be omitted.
 
 With the following specific exceptions, calls to listener events are
 deterministic, i.e. for identical input the calls to listener
 methods will be the same.
 listener - the listener to addNullPointerException - if  listener is nullpublic void removeParseListener(ParseTreeListener listener)
listener from the list of parse listeners.
 
 If listener is null or has not been added as a parse
 listener, this method does nothing.listener - the listener to removeaddParseListener(org.antlr.v4.runtime.tree.ParseTreeListener)public void removeParseListeners()
protected void triggerEnterRuleEvent()
protected void triggerExitRuleEvent()
public int getNumberOfSyntaxErrors()
notifyErrorListeners(java.lang.String) is called.public TokenFactory<?> getTokenFactory()
getTokenFactory in class Recognizer<Token,ParserATNSimulator>public void setTokenFactory(TokenFactory<?> factory)
setTokenFactory in class Recognizer<Token,ParserATNSimulator>@NotNull public ANTLRErrorStrategy getErrorHandler()
public void setErrorHandler(@NotNull ANTLRErrorStrategy handler)
public TokenStream getInputStream()
getInputStream in class Recognizer<Token,ParserATNSimulator>public final void setInputStream(IntStream input)
setInputStream in class Recognizer<Token,ParserATNSimulator>public TokenStream getTokenStream()
public void setTokenStream(TokenStream input)
public Token getCurrentToken()
public final void notifyErrorListeners(String msg)
public void notifyErrorListeners(Token offendingToken, String msg, @Nullable RecognitionException e)
public Token consume()
A being the current
 lookahead symbol, this function moves the cursor to B and returns
 A.
 A B ^If the parser is not in error recovery mode, the consumed symbol is added to the parse tree using
ParserRuleContext.addChild(Token), and
 ParseTreeListener.visitTerminal(org.antlr.v4.runtime.tree.TerminalNode) is called on any parse listeners.
 If the parser is in error recovery mode, the consumed symbol is
 added to the parse tree using
 ParserRuleContext.addErrorNode(Token), and
 ParseTreeListener.visitErrorNode(org.antlr.v4.runtime.tree.ErrorNode) is called on any parse
 listeners.protected void addContextToParseTree()
public void enterRule(@NotNull ParserRuleContext localctx, int state, int ruleIndex)
_ctx get the current context.public void exitRule()
public void enterOuterAlt(ParserRuleContext localctx, int altNum)
public void enterRecursionRule(ParserRuleContext localctx, int ruleIndex)
public void pushNewRecursionContext(ParserRuleContext localctx, int state, int ruleIndex)
enterRule(org.antlr.v4.runtime.ParserRuleContext, int, int) but for recursive rules.public void unrollRecursionContexts(ParserRuleContext _parentctx)
public ParserRuleContext getInvokingContext(int ruleIndex)
public ParserRuleContext getContext()
public boolean inContext(String context)
public boolean isExpectedToken(int symbol)
symbol can follow the current state in the
 ATN. The behavior of this method is equivalent to the following, but is
 implemented such that the complete context-sensitive follow set does not
 need to be explicitly constructed.
 return getExpectedTokens().contains(symbol);
symbol - the symbol type to checktrue if symbol can follow the current state in
 the ATN, otherwise false.@NotNull public IntervalSet getExpectedTokens()
Recognizer.getState() and getContext(),
 respectively.@NotNull public IntervalSet getExpectedTokensWithinCurrentRule()
public ParserRuleContext getRuleContext()
public List<String> getRuleInvocationStack()
public List<String> getRuleInvocationStack(RuleContext p)
public void dumpDFA()
public String getSourceName()
public void setTrace(boolean trace)
Copyright © 1992-2013 ANTLR. All Rights Reserved.