Package org.antlr.tool
Class Interpreter
java.lang.Object
org.antlr.tool.Interpreter
- All Implemented Interfaces:
org.antlr.runtime.TokenSource
The recognition interpreter/engine for grammars. Separated
out of Grammar as it's related, but technically not a Grammar function.
You create an interpreter for a grammar and an input stream. This object
can act as a TokenSource so that you can hook up two grammars (via
a CommonTokenStream) to lex/parse. Being a token source only makes sense
for a lexer grammar of course.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classA lexer listener that just creates token objects as they are matched. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.antlr.runtime.Tokenorg.antlr.runtime.tree.ParseTreeorg.antlr.runtime.tree.ParseTreevoidparse(String startRule, org.antlr.runtime.debug.DebugEventListener actions, List<NFAState> visitedStates) protected voidparseEngine(String startRule, NFAState start, NFAState stop, org.antlr.runtime.IntStream input, Stack<NFAState> ruleInvocationStack, org.antlr.runtime.debug.DebugEventListener actions, List<NFAState> visitedStates) Fill a list of all NFA states visited during the parseintGiven an input stream, return the unique alternative predicted by matching the input.voidreportScanError(org.antlr.runtime.RecognitionException re) org.antlr.runtime.CommonTokenorg.antlr.runtime.CommonTokenvoidscan(String startRule, org.antlr.runtime.debug.DebugEventListener actions, List<NFAState> visitedStates) For a given input char stream, try to match against the NFA starting at startRule.
-
Field Details
-
grammar
-
input
protected org.antlr.runtime.IntStream input
-
-
Constructor Details
-
Interpreter
-
-
Method Details
-
nextToken
public org.antlr.runtime.Token nextToken()- Specified by:
nextTokenin interfaceorg.antlr.runtime.TokenSource
-
scan
public void scan(String startRule, org.antlr.runtime.debug.DebugEventListener actions, List<NFAState> visitedStates) throws org.antlr.runtime.RecognitionException For a given input char stream, try to match against the NFA starting at startRule. This is a deterministic parse even though it is using an NFA because it uses DFAs at each decision point to predict which alternative will succeed. This is exactly what the generated parser will do. This only does lexer grammars. Return the token type associated with the final rule end state.- Throws:
org.antlr.runtime.RecognitionException
-
scan
public org.antlr.runtime.CommonToken scan(String startRule) throws org.antlr.runtime.RecognitionException - Throws:
org.antlr.runtime.RecognitionException
-
scan
public org.antlr.runtime.CommonToken scan(String startRule, List<NFAState> visitedStates) throws org.antlr.runtime.RecognitionException - Throws:
org.antlr.runtime.RecognitionException
-
parse
public void parse(String startRule, org.antlr.runtime.debug.DebugEventListener actions, List<NFAState> visitedStates) throws org.antlr.runtime.RecognitionException - Throws:
org.antlr.runtime.RecognitionException
-
parse
public org.antlr.runtime.tree.ParseTree parse(String startRule) throws org.antlr.runtime.RecognitionException - Throws:
org.antlr.runtime.RecognitionException
-
parse
public org.antlr.runtime.tree.ParseTree parse(String startRule, List<NFAState> visitedStates) throws org.antlr.runtime.RecognitionException - Throws:
org.antlr.runtime.RecognitionException
-
parseEngine
protected void parseEngine(String startRule, NFAState start, NFAState stop, org.antlr.runtime.IntStream input, Stack<NFAState> ruleInvocationStack, org.antlr.runtime.debug.DebugEventListener actions, List<NFAState> visitedStates) throws org.antlr.runtime.RecognitionException Fill a list of all NFA states visited during the parse- Throws:
org.antlr.runtime.RecognitionException
-
predict
Given an input stream, return the unique alternative predicted by matching the input. Upon error, return NFA.INVALID_ALT_NUMBER The first symbol of lookahead is presumed to be primed; that is, input.lookahead(1) must point at the input symbol you want to start predicting with. -
reportScanError
public void reportScanError(org.antlr.runtime.RecognitionException re) -
getSourceName
- Specified by:
getSourceNamein interfaceorg.antlr.runtime.TokenSource
-