Top Description Fields Constructors Methods
org.antlr.runtime

public Class Parser

extends BaseRecognizer
Class Inheritance
Known Direct Subclasses
org.antlr.runtime.debug.DebugParser

A parser for TokenStreams. "parser grammars" result in a subclass of this.

Field Summary

Modifier and TypeField and Description
public TokenStream
Inherited from org.antlr.runtime.BaseRecognizer:
DEFAULT_TOKEN_CHANNELHIDDENINITIAL_FOLLOW_STACK_SIZEMEMO_RULE_FAILEDMEMO_RULE_UNKNOWNNEXT_TOKEN_RULE_NAMEstate

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected Object
getCurrentInputSymbol(IntStream input)

Overrides org.antlr.runtime.BaseRecognizer.getCurrentInputSymbol.

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.
protected Object
getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow)

Overrides org.antlr.runtime.BaseRecognizer.getMissingSymbol.

Conjure up a missing token during error recovery.
public String
public TokenStream
public void
reset()

Overrides org.antlr.runtime.BaseRecognizer.reset.

reset the parser's state; subclasses must rewinds the input stream
public void
setTokenStream(TokenStream input)

Set the token stream and reset the parser

public void
traceIn(String ruleName, int ruleIndex)

public void
traceOut(String ruleName, int ruleIndex)

Inherited from org.antlr.runtime.BaseRecognizer:
alreadyParsedRulebeginResynccombineFollowscomputeContextSensitiveRuleFOLLOWcomputeErrorRecoverySetconsumeUntilconsumeUntildisplayRecognitionErroremitErrorMessageendResyncfailedgetBacktrackingLevelgetErrorHeadergetErrorMessagegetGrammarFileNamegetNumberOfSyntaxErrorsgetRuleInvocationStackgetRuleInvocationStackgetRuleMemoizationgetRuleMemoizationCacheSizegetTokenErrorDisplaygetTokenNamesmatchmatchAnymemoizemismatchIsMissingTokenmismatchIsUnwantedTokenpushFollowrecoverrecoverFromMismatchedSetrecoverFromMismatchedTokenreportErrorsetBacktrackingLeveltoStringstraceIntraceOut

Field Detail

inputback to summary
public TokenStream input

Constructor Detail

Parserback to summary
public Parser(TokenStream input)
Parserback to summary
public Parser(TokenStream input, RecognizerSharedState state)

Method Detail

getCurrentInputSymbolback to summary
protected Object getCurrentInputSymbol(IntStream input)

Overrides org.antlr.runtime.BaseRecognizer.getCurrentInputSymbol.

Doc from org.antlr.runtime.BaseRecognizer.getCurrentInputSymbol.

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.

Annotations
@Override
getMissingSymbolback to summary
protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow)

Overrides org.antlr.runtime.BaseRecognizer.getMissingSymbol.

Doc from org.antlr.runtime.BaseRecognizer.getMissingSymbol.

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.

Annotations
@Override
getSourceNameback to summary
public String getSourceName()

Implements abstract org.antlr.runtime.BaseRecognizer.getSourceName.

Annotations
@Override
getTokenStreamback to summary
public TokenStream getTokenStream()
resetback to summary
public void reset()

Overrides org.antlr.runtime.BaseRecognizer.reset.

Doc from org.antlr.runtime.BaseRecognizer.reset.

reset the parser's state; subclasses must rewinds the input stream

Annotations
@Override
setTokenStreamback to summary
public void setTokenStream(TokenStream input)

Set the token stream and reset the parser

traceInback to summary
public void traceIn(String ruleName, int ruleIndex)
traceOutback to summary
public void traceOut(String ruleName, int ruleIndex)