Top Fields Constructors Methods
org.antlr.v4.runtime

public abstract Class Recognizer<Symbol, ATNInterpreter extends org.antlr.v4.runtime.atn.ATNSimulator>

extends Object
Class Inheritance
Known Direct Subclasses
org.antlr.v4.runtime.Lexer, org.antlr.v4.runtime.Parser
Imports
org.antlr.v4.runtime.atn.ATN, .ATNSimulator, .ParseInfo, org.antlr.v4.runtime.misc.Args, .NotNull, .Nullable, .Utils, java.util.ArrayList, .Collections, .HashMap, .List, .Map, .WeakHashMap, java.util.concurrent.CopyOnWriteArrayList

Field Summary

Modifier and TypeField and Description
protected ATNInterpreter
private List<ANTLRErrorListener<? super Symbol>>
private int
public static final int
private static final Map<String[], Map<String, Integer>>
private static final Map<Vocabulary, Map<String, Integer>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
action(RuleContext _localctx, int ruleIndex, int actionIndex)

public void
addErrorListener(ANTLRErrorListener<? super Symbol> listener)

public ATN

Returns:

The ATN used by the recognizer for prediction.
getATN
()

Get the ATN used by the recognizer for prediction.

public String
getErrorHeader(RecognitionException e)

What is the error header, normally line/character position information?

public ANTLRErrorListener<? super Symbol>
public List<? extends ANTLRErrorListener<? super Symbol>>
public abstract String
getGrammarFileName()

For debugging and other purposes, might want the grammar name.

public abstract IntStream
public ATNInterpreter

Returns:

The ATN interpreter used by the recognizer for prediction.
getInterpreter
()

Get the ATN interpreter used by the recognizer for prediction.

public ParseInfo
getParseInfo()

If profiling during the parse/lex, this will return DecisionInfo records for each decision in recognizer in a ParseInfo object.

public Map<String, Integer>
getRuleIndexMap()

Get a map from rule names to rule indexes.

public abstract String[]
public String
getSerializedATN()

If this recognizer was generated, it will have a serialized ATN representation of the grammar.

public final int
public String
getTokenErrorDisplay(Token t)

Deprecated This method is not called by the ANTLR 4 Runtime.
How should a token be displayed in an error message?
public abstract String[]
getTokenNames()

Deprecated Use getVocabulary() instead.
Used to print out token names like ID during debugging and error reporting.
public int
getTokenType(String tokenName)

public Map<String, Integer>
getTokenTypeMap()

Get a map from token names to token types.

public Vocabulary

Returns:

A Vocabulary instance providing information about the vocabulary used by the grammar.
getVocabulary
()

Get the vocabulary used by the recognizer.

public boolean
precpred(RuleContext localctx, int precedence)

public void
removeErrorListener(ANTLRErrorListener<? super Symbol> listener)

public void
public boolean
sempred(RuleContext _localctx, int ruleIndex, int actionIndex)

public void
setInterpreter(ATNInterpreter
The ATN interpreter used by the recognizer for prediction.
interpreter
)

Set the ATN interpreter used by the recognizer for prediction.

public final void
setState(int atnState)

Indicate that the recognizer has changed internal state that is consistent with the ATN state passed in. This way we always know where we are in the ATN as the parser goes along.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_interpback to summary
protected ATNInterpreter _interp
_listenersback to summary
private List<ANTLRErrorListener<? super Symbol>> _listeners
Annotations
@SuppressWarnings:serial
@NotNull
_stateNumberback to summary
private int _stateNumber
EOFback to summary
public static final int EOF
ruleIndexMapCacheback to summary
private static final Map<String[], Map<String, Integer>> ruleIndexMapCache
tokenTypeMapCacheback to summary
private static final Map<Vocabulary, Map<String, Integer>> tokenTypeMapCache

Constructor Detail

Recognizerback to summary
public Recognizer()

Method Detail

actionback to summary
public void action(RuleContext _localctx, int ruleIndex, int actionIndex)
addErrorListenerback to summary
public void addErrorListener(ANTLRErrorListener<? super Symbol> listener)
Exceptions
NullPointerException:
if listener is null.
getATNback to summary
public ATN getATN()

Get the ATN used by the recognizer for prediction.

Returns:ATN

The ATN used by the recognizer for prediction.

Annotations
@NotNull
getErrorHeaderback to summary
public String getErrorHeader(RecognitionException e)

What is the error header, normally line/character position information?

Annotations
@NotNull
getErrorListenerDispatchback to summary
public ANTLRErrorListener<? super Symbol> getErrorListenerDispatch()
getErrorListenersback to summary
public List<? extends ANTLRErrorListener<? super Symbol>> getErrorListeners()
Annotations
@NotNull
getGrammarFileNameback to summary
public abstract String getGrammarFileName()

For debugging and other purposes, might want the grammar name. Have ANTLR generate an implementation for this method.

getInputStreamback to summary
public abstract IntStream getInputStream()
getInterpreterback to summary
public ATNInterpreter getInterpreter()

Get the ATN interpreter used by the recognizer for prediction.

Returns:ATNInterpreter

The ATN interpreter used by the recognizer for prediction.

Annotations
@NotNull
getParseInfoback to summary
public ParseInfo getParseInfo()

If profiling during the parse/lex, this will return DecisionInfo records for each decision in recognizer in a ParseInfo object.

Since
4.3
getRuleIndexMapback to summary
public Map<String, Integer> getRuleIndexMap()

Get a map from rule names to rule indexes.

Used for XPath and tree pattern compilation.

Annotations
@NotNull
getRuleNamesback to summary
public abstract String[] getRuleNames()
getSerializedATNback to summary
public String getSerializedATN()

If this recognizer was generated, it will have a serialized ATN representation of the grammar.

For interpreters, we don't know their serialized ATN despite having created the interpreter from it.

Annotations
@NotNull
getStateback to summary
public final int getState()
getTokenErrorDisplayback to summary
public String getTokenErrorDisplay(Token t)

Deprecated

This method is not called by the ANTLR 4 Runtime. Specific implementations of ANTLRErrorStrategy may provide a similar feature when necessary. For example, see DefaultErrorStrategy#getTokenErrorDisplay.

How should a token be displayed in an error message? The default is to display just the text, but during development you might want to have a lot of information spit out. Override in that case to use t.toString() (which, for CommonToken, dumps everything about the token). This is better than forcing you to override a method in your token objects because you don't have to go modify your lexer so that it creates a new Java type.

Annotations
@Deprecated
getTokenNamesback to summary
public abstract String[] getTokenNames()

Deprecated

Use getVocabulary() instead.

Used to print out token names like ID during debugging and error reporting. The generated parsers implement a method that overrides this to point to their String[] tokenNames.

Annotations
@Deprecated
getTokenTypeback to summary
public int getTokenType(String tokenName)
getTokenTypeMapback to summary
public Map<String, Integer> getTokenTypeMap()

Get a map from token names to token types.

Used for XPath and tree pattern compilation.

Annotations
@NotNull
getVocabularyback to summary
public Vocabulary getVocabulary()

Get the vocabulary used by the recognizer.

Returns:Vocabulary

A Vocabulary instance providing information about the vocabulary used by the grammar.

Annotations
@NotNull
@SuppressWarnings:deprecation
precpredback to summary
public boolean precpred(RuleContext localctx, int precedence)
removeErrorListenerback to summary
public void removeErrorListener(ANTLRErrorListener<? super Symbol> listener)
removeErrorListenersback to summary
public void removeErrorListeners()
sempredback to summary
public boolean sempred(RuleContext _localctx, int ruleIndex, int actionIndex)
setInterpreterback to summary
public void setInterpreter(ATNInterpreter interpreter)

Set the ATN interpreter used by the recognizer for prediction.

Parameters
interpreter:ATNInterpreter

The ATN interpreter used by the recognizer for prediction.

setStateback to summary
public final void setState(int atnState)

Indicate that the recognizer has changed internal state that is consistent with the ATN state passed in. This way we always know where we are in the ATN as the parser goes along. The rule context objects form a stack that lets us see the stack of invoking rules. Combine this and we have complete ATN configuration information.