ParserInterpreter

@uml A parser simulator that mimics what ANTLR's generated parser code does. A ParserATNSimulator is used to make predictions via adaptivePredict but this class moves a pointer through the ATN to simulate parsing. ParserATNSimulator just makes us efficient rather than having to backtrack, for example.

This properly creates parse trees even for left recursive rules.

We rely on the left recursive rule invocation and special predicate transitions to make left recursive rules work.

See TestParserInterpreter for examples.

Constructors

this
this(string grammarFileName, string[] tokenNames, string[] ruleNames, ATN atn, TokenStream input)

@uml deprecated Use {@link #ParserInterpreter(String, Vocabulary, Collection, ATN, TokenStream)} instead.

this
this(string grammarFileName, Vocabulary vocabulary, string[] ruleNames, ATN atn, TokenStream input)
Undocumented in source.

Members

Functions

addDecisionOverride
void addDecisionOverride(int decision, int tokenIndex, int forcedAlt)

@uml Override this parser interpreters normal decision-making process at a particular decision and input token index. Instead of allowing the adaptive prediction mechanism to choose the first alternative within a block that leads to a successful parse, force it to take the alternative, 1..n for n alternatives.

createInterpreterRuleContext
InterpreterRuleContext createInterpreterRuleContext(ParserRuleContext parent, int invokingStateNumber, int ruleIndex)

@uml Provide simple "factory" for InterpreterRuleContext's.

enterRecursionRule
void enterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence)

@uml @override

getATN
ATN getATN()

@uml @override

getATNState
ATNState getATNState()
Undocumented in source. Be warned that the author may not have intended to support it.
getGrammarFileName
string getGrammarFileName()

@uml @override

getOverrideDecisionRoot
InterpreterRuleContext getOverrideDecisionRoot()
Undocumented in source. Be warned that the author may not have intended to support it.
getRootContext
InterpreterRuleContext getRootContext()

@uml Return the root of the parse, which can be useful if the parser bails out. You still can access the top node. Note that, because of the way left recursive rules add children, it's possible that the root will not have any children if the start rule immediately called and left recursive rule that fails.

getRuleNames
string[] getRuleNames()

@uml @override

getTokenNames
string[] getTokenNames()

@uml @override

getVocabulary
Vocabulary getVocabulary()

@uml @override

parse
ParserRuleContext parse(int startRuleIndex)

@uml Begin parsing at startRuleIndex

recover
void recover(RecognitionException e)

@uml Rely on the error handler for this parser but, if no tokens are consumed to recover, add an error node. Otherwise, nothing is seen in the parse tree.

recoverInline
Token recoverInline()
Undocumented in source. Be warned that the author may not have intended to support it.
reset
void reset()

@uml @override

visitDecisionState
int visitDecisionState(DecisionState p)
Undocumented in source. Be warned that the author may not have intended to support it.
visitRuleStopState
void visitRuleStopState(ATNState p)
Undocumented in source. Be warned that the author may not have intended to support it.
visitState
void visitState(ATNState p)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

_parentContextStack
DList!ParentContextPair _parentContextStack;

@uml This stack corresponds to the _parentctx, _parentState pair of locals that would exist on call stack frames with a recursive descent parser; in the generated function for a left-recursive rule you'd see:

atn
ATN atn;
Undocumented in source.
decisionToDFA
DFA[] decisionToDFA;

@uml not shared like it is for generated parsers

grammarFileName
string grammarFileName;
Undocumented in source.
overrideDecision
int overrideDecision;

@uml We need a map from (decision,inputIndex)->forced alt for computing ambiguous parse trees. For now, we allow exactly one override.

overrideDecisionAlt
int overrideDecisionAlt;
Undocumented in source.
overrideDecisionInputIndex
int overrideDecisionInputIndex;
Undocumented in source.
overrideDecisionReached
bool overrideDecisionReached;

@uml latch and only override once; error might trigger infinite loop

overrideDecisionRoot
InterpreterRuleContext overrideDecisionRoot;

@uml What is the current context when we override a decisions? This tellsus what the root of the parse tree is when using override for an ambiguity/lookahead check.

rootContext
InterpreterRuleContext rootContext;
Undocumented in source.
ruleNames
string[] ruleNames;
Undocumented in source.
sharedContextCache
PredictionContextCache sharedContextCache;
Undocumented in source.
tokenNames
string[] tokenNames;
Undocumented in source.

Inherited Members

From Parser

TraceListener
class TraceListener

TODO add class description

TrimToSizeListener
class TrimToSizeListener

TODO add class description

_errHandler
ANTLRErrorStrategy _errHandler;
Undocumented in source.
_input
TokenStream _input;
Undocumented in source.
_precedenceStack
IntegerStack _precedenceStack;
Undocumented in source.
ctx_
ParserRuleContext ctx_;

@uml The {@link ParserRuleContext} object for the currently executing rule. This is always non-null during the parsing process. @read @write

_buildParseTrees
bool _buildParseTrees;

@uml Specifies whether or not the parser should construct a parse tree during the parsing process. The default value is {@code true}.

_tracer
TraceListener _tracer;
Undocumented in source.
_parseListeners
ParseTreeListener[] _parseListeners;

@uml The list of {@link ParseTreeListener} listeners registered to receive events during the parse.

matchedEOF
bool matchedEOF;

@uml Indicates parser has match()ed EOF token. See {@link #exitRule()}.

reset
void reset()

@uml reset the parser's state

match
Token match(int ttype)

@uml Match current input symbol against {@code ttype}. If the symbol type matches, {@link ANTLRErrorStrategy#reportMatch} and {@link #consume} are called to complete the match process.

matchWildcard
Token matchWildcard()

@uml Match current input symbol as a wildcard. If the symbol type matches (i.e. has a value greater than 0), {@link ANTLRErrorStrategy#reportMatch} and {@link #consume} are called to complete the match process.

setBuildParseTree
void setBuildParseTree(bool buildParseTrees)

@uml Track the {@link ParserRuleContext} objects during the parse and hook them up using the {@link ParserRuleContext#children} list so that it forms a parse tree. The {@link ParserRuleContext} returned from the start rule represents the root of the parse tree.

getBuildParseTree
bool getBuildParseTree()

@uml Gets whether or not a complete parse tree will be constructed while parsing. This property is {@code true} for a newly constructed parser.

setTrimParseTree
void setTrimParseTree(bool trimParseTrees)

@uml Trim the internal lists of the parse tree during parsing to conserve memory. This property is set to {@code false} by default for a newly constructed parser.

getTrimParseTree
bool getTrimParseTree()

@uml The @return {@code true} if the {@link ParserRuleContext#children} list is trimed using the default {@link Parser.TrimToSizeListener} during the parse process.

getParseListeners
ParseTreeListener[] getParseListeners()
Undocumented in source. Be warned that the author may not have intended to support it.
addParseListener
void addParseListener(ParseTreeListener listener)

@uml Registers {@code listener} to receive events during the parsing process.

removeParseListener
void removeParseListener(ParseTreeListener listener)
Undocumented in source. Be warned that the author may not have intended to support it.
removeParseListeners
void removeParseListeners()

@uml Remove all parse listeners.

triggerEnterRuleEvent
void triggerEnterRuleEvent()

@uml Notify any parse listeners of an enter rule event.

triggerExitRuleEvent
void triggerExitRuleEvent()

@uml Notify any parse listeners of an exit rule event.

tokenFactory
TokenFactory!CommonToken tokenFactory()

@uml @override

tokenFactory
void tokenFactory(TokenFactory!CommonToken factory)

Tell our token source and error strategy about a new way to create tokens. @uml @override

getATNWithBypassAlts
ATN getATNWithBypassAlts()

@uml The ATN with bypass alternatives is expensive to create so we create it lazily.

compileParseTreePattern
ParseTreePattern compileParseTreePattern(string pattern, int patternRuleIndex)
Undocumented in source. Be warned that the author may not have intended to support it.
compileParseTreePattern
ParseTreePattern compileParseTreePattern(string pattern, int patternRuleIndex, Lexer lexer)

@uml The same as {@link #compileParseTreePattern(String, int)} but specify a {@link Lexer} rather than trying to deduce it from this parser.

getErrorHandler
auto getErrorHandler()
Undocumented in source. Be warned that the author may not have intended to support it.
setErrorHandler
void setErrorHandler(ANTLRErrorStrategy handler)
Undocumented in source. Be warned that the author may not have intended to support it.
getInputStream
TokenStream getInputStream()

@uml @override

setInputStream
void setInputStream(IntStream input)

@uml @override

getTokenStream
TokenStream getTokenStream()
Undocumented in source. Be warned that the author may not have intended to support it.
setTokenStream
void setTokenStream(TokenStream input)

@uml Set the token stream and reset the parser.

getCurrentToken
Token getCurrentToken()

@uml Match needs to return the current input symbol, which gets put into the label for the associated token ref; e.g., x=ID.

notifyErrorListeners
void notifyErrorListeners(string msg)

@uml @final

notifyErrorListeners
void notifyErrorListeners(Token offendingToken, string msg, RecognitionException e)
Undocumented in source. Be warned that the author may not have intended to support it.
consume
Token consume()

@uml Consume and return the {@linkplain #getCurrentToken current symbol}.

addContextToParseTree
void addContextToParseTree()
Undocumented in source. Be warned that the author may not have intended to support it.
enterRule
void enterRule(ParserRuleContext localctx, int state, int ruleIndex)
Undocumented in source. Be warned that the author may not have intended to support it.
exitRule
void exitRule()
Undocumented in source. Be warned that the author may not have intended to support it.
enterOuterAlt
void enterOuterAlt(ParserRuleContext localctx, int altNum)
Undocumented in source. Be warned that the author may not have intended to support it.
getPrecedence
int getPrecedence()

@uml Get the precedence level for the top-most precedence rule.

enterRecursionRule
void enterRecursionRule(ParserRuleContext localctx, int ruleIndex)

@uml . @deprecated Use {@link #enterRecursionRule(ParserRuleContext, int, int, int)} instead.

enterRecursionRule
void enterRecursionRule(ParserRuleContext localctx, int state, int ruleIndex, int precedence)
Undocumented in source. Be warned that the author may not have intended to support it.
pushNewRecursionContext
void pushNewRecursionContext(ParserRuleContext localctx, int state, int ruleIndex)

@uml Like {@link #enterRule} but for recursive rules. Make the current context the child of the incoming localctx.

unrollRecursionContexts
void unrollRecursionContexts(ParserRuleContext _parentctx)
Undocumented in source. Be warned that the author may not have intended to support it.
getInvokingContext
ParserRuleContext getInvokingContext(int ruleIndex)
Undocumented in source. Be warned that the author may not have intended to support it.
precpred
bool precpred(InterfaceRuleContext localctx, int precedence)

@uml @override

inContext
bool inContext(string context)
Undocumented in source. Be warned that the author may not have intended to support it.
isExpectedToken
bool isExpectedToken(int symbol)

@uml Checks whether or not {@code 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.

isMatchedEOF
bool isMatchedEOF()
Undocumented in source. Be warned that the author may not have intended to support it.
getExpectedTokens
IntervalSet getExpectedTokens()

@uml Computes the set of input symbols which could follow the current parser state and context, as given by {@link #getState} and {@link #getContext}, espectively.

getExpectedTokensWithinCurrentRule
IntervalSet getExpectedTokensWithinCurrentRule()
Undocumented in source. Be warned that the author may not have intended to support it.
getRuleIndex
int getRuleIndex(string ruleName)

@uml Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found.

getRuleContext
ParserRuleContext getRuleContext()
Undocumented in source. Be warned that the author may not have intended to support it.
getRuleInvocationStack
string[] getRuleInvocationStack()

@uml Return List<String> of the rule names in your parser instance leading up to a call to the current rule. You could override if you want more details such as the file/line info of where in the ATN a rule is invoked.

getRuleInvocationStack
string[] getRuleInvocationStack(RuleContext p)
Undocumented in source. Be warned that the author may not have intended to support it.
getDFAStrings
string[] getDFAStrings()

@uml For debugging and other purposes.

dumpDFA
void dumpDFA()

@uml For debugging and other purposes.

getSourceName
string getSourceName()
Undocumented in source. Be warned that the author may not have intended to support it.
getParseInfo
ParseInfo getParseInfo()

@uml @override

setProfile
void setProfile(bool profile)
Undocumented in source. Be warned that the author may not have intended to support it.
setTrace
void setTrace(bool trace)
Undocumented in source. Be warned that the author may not have intended to support it.
isTrace
bool isTrace()

@uml Gets whether a {@link TraceListener} is registered as a parse listener for the parser.

ctx
ParserRuleContext ctx()
Undocumented in source. Be warned that the author may not have intended to support it.
ctx
void ctx(ParserRuleContext ctx)
Undocumented in source. Be warned that the author may not have intended to support it.
numberOfSyntaxErrors
int numberOfSyntaxErrors()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta