Package org.antlr.runtime
Class Parser
- java.lang.Object
-
- org.antlr.runtime.BaseRecognizer
-
- org.antlr.runtime.Parser
-
- Direct Known Subclasses:
DebugParser
public class Parser extends BaseRecognizer
A parser for TokenStreams. "parser grammars" result in a subclass of this.
-
-
Field Summary
Fields Modifier and Type Field Description TokenStream
input
-
Fields inherited from class org.antlr.runtime.BaseRecognizer
DEFAULT_TOKEN_CHANNEL, HIDDEN, INITIAL_FOLLOW_STACK_SIZE, MEMO_RULE_FAILED, MEMO_RULE_UNKNOWN, NEXT_TOKEN_RULE_NAME, state
-
-
Constructor Summary
Constructors Constructor Description Parser(TokenStream input)
Parser(TokenStream input, RecognizerSharedState state)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
getCurrentInputSymbol(IntStream input)
Match needs to return the current input symbol, which gets put into the label for the associated token ref; e.g., x=ID.protected Object
getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow)
Conjure up a missing token during error recovery.String
getSourceName()
TokenStream
getTokenStream()
void
reset()
reset the parser's state; subclasses must rewinds the input streamvoid
setTokenStream(TokenStream input)
Set the token stream and reset the parservoid
traceIn(String ruleName, int ruleIndex)
void
traceOut(String ruleName, int ruleIndex)
-
Methods inherited from class org.antlr.runtime.BaseRecognizer
alreadyParsedRule, beginResync, combineFollows, computeContextSensitiveRuleFOLLOW, computeErrorRecoverySet, consumeUntil, consumeUntil, displayRecognitionError, emitErrorMessage, endResync, failed, getBacktrackingLevel, getErrorHeader, getErrorMessage, getGrammarFileName, getNumberOfSyntaxErrors, getRuleInvocationStack, getRuleInvocationStack, getRuleMemoization, getRuleMemoizationCacheSize, getTokenErrorDisplay, getTokenNames, match, matchAny, memoize, mismatchIsMissingToken, mismatchIsUnwantedToken, pushFollow, recover, recoverFromMismatchedSet, recoverFromMismatchedToken, reportError, setBacktrackingLevel, toStrings, traceIn, traceOut
-
-
-
-
Field Detail
-
input
public TokenStream input
-
-
Constructor Detail
-
Parser
public Parser(TokenStream input)
-
Parser
public Parser(TokenStream input, RecognizerSharedState state)
-
-
Method Detail
-
reset
public void reset()
Description copied from class:BaseRecognizer
reset the parser's state; subclasses must rewinds the input stream- Overrides:
reset
in classBaseRecognizer
-
getCurrentInputSymbol
protected Object getCurrentInputSymbol(IntStream input)
Description copied from class:BaseRecognizer
Match needs to return the current input symbol, which gets put into the label for the associated token ref; e.g., x=ID. Token and tree parsers need to return different objects. Rather than test for input stream type or change the IntStream interface, I use a simple method to ask the recognizer to tell me what the current input symbol is. This is ignored for lexers.- Overrides:
getCurrentInputSymbol
in classBaseRecognizer
-
getMissingSymbol
protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow)
Description copied from class:BaseRecognizer
Conjure up a missing token during error recovery. The recognizer attempts to recover from single missing symbols. But, actions might refer to that missing symbol. For example, x=ID {f($x);}. The action clearly assumes that there has been an identifier matched previously and that $x points at that token. If that token is missing, but the next token in the stream is what we want we assume that this token is missing and we keep going. Because we have to return some token to replace the missing token, we have to conjure one up. This method gives the user control over the tokens returned for missing tokens. Mostly, you will want to create something special for identifier tokens. For literals such as '{' and ',', the default action in the parser or tree parser works. It simply creates a CommonToken of the appropriate type. The text will be the token. If you change what tokens must be created by the lexer, override this method to create the appropriate tokens.- Overrides:
getMissingSymbol
in classBaseRecognizer
-
setTokenStream
public void setTokenStream(TokenStream input)
Set the token stream and reset the parser
-
getTokenStream
public TokenStream getTokenStream()
-
getSourceName
public String getSourceName()
- Specified by:
getSourceName
in classBaseRecognizer
-
traceIn
public void traceIn(String ruleName, int ruleIndex)
-
traceOut
public void traceOut(String ruleName, int ruleIndex)
-
-