Top Description Inners Fields Constructors Methods
org.antlr.tool

public Class Interpreter

extends Object
implements TokenSource
Class Inheritance
All Implemented Interfaces
org.antlr.runtime.TokenSource
Imports
org.antlr.analysis.DFA, org.antlr.analysis.*, org.antlr.misc.IntervalSet, org.antlr.runtime.*, org.antlr.runtime.debug.BlankDebugEventListener, .DebugEventListener, .ParseTreeBuilder, org.antlr.runtime.tree.ParseTree, java.util.List, .Stack

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 and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
Interpreter.LexerActionGetTokenType

A lexer listener that just creates token objects as they are matched.

Field Summary

Modifier and TypeField and Description
protected Grammar
protected IntStream

Constructor Summary

AccessConstructor and Description
public
Interpreter(Grammar grammar, IntStream input)

Method Summary

Modifier and TypeMethod and Description
public String
getSourceName()

Implements org.antlr.runtime.TokenSource.getSourceName.

Where are you getting tokens from?
public Token
nextToken()

Implements org.antlr.runtime.TokenSource.nextToken.

Return a Token object from your input stream (usually a CharStream).
public void
parse(String startRule, DebugEventListener actions, List<NFAState> visitedStates)

public ParseTree
parse(String startRule)

public ParseTree
parse(String startRule, List<NFAState> visitedStates)

protected void
parseEngine(String startRule, NFAState start, NFAState stop, IntStream input, Stack<NFAState> ruleInvocationStack, DebugEventListener actions, List<NFAState> visitedStates)

Fill a list of all NFA states visited during the parse

public int
predict(DFA dfa)

Given an input stream, return the unique alternative predicted by matching the input.

public void
public void
scan(String startRule, DebugEventListener actions, List<NFAState> visitedStates)

For a given input char stream, try to match against the NFA starting at startRule.

public CommonToken
scan(String startRule)

public CommonToken
scan(String startRule, List<NFAState> visitedStates)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

grammarback to summary
protected Grammar grammar
inputback to summary
protected IntStream input

Constructor Detail

Interpreterback to summary
public Interpreter(Grammar grammar, IntStream input)

Method Detail

getSourceNameback to summary
public String getSourceName()

Implements org.antlr.runtime.TokenSource.getSourceName.

Doc from org.antlr.runtime.TokenSource.getSourceName.

Where are you getting tokens from? normally the implication will simply ask lexers input stream.

Annotations
@Override
nextTokenback to summary
public Token nextToken()

Implements org.antlr.runtime.TokenSource.nextToken.

Doc from org.antlr.runtime.TokenSource.nextToken.

Return a Token object from your input stream (usually a CharStream). Do not fail/return upon lexing error; keep chewing on the characters until you get a good one; errors are not passed through to the parser.

Annotations
@Override
parseback to summary
public void parse(String startRule, DebugEventListener actions, List<NFAState> visitedStates) throws RecognitionException
parseback to summary
public ParseTree parse(String startRule) throws RecognitionException
parseback to summary
public ParseTree parse(String startRule, List<NFAState> visitedStates) throws RecognitionException
parseEngineback to summary
protected void parseEngine(String startRule, NFAState start, NFAState stop, IntStream input, Stack<NFAState> ruleInvocationStack, DebugEventListener actions, List<NFAState> visitedStates) throws RecognitionException

Fill a list of all NFA states visited during the parse

predictback to summary
public int predict(DFA dfa)

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.

reportScanErrorback to summary
public void reportScanError(RecognitionException re)
scanback to summary
public void scan(String startRule, DebugEventListener actions, List<NFAState> visitedStates) throws 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.

scanback to summary
public CommonToken scan(String startRule) throws RecognitionException
scanback to summary
public CommonToken scan(String startRule, List<NFAState> visitedStates) throws RecognitionException
org.antlr.tool back to summary

pack-priv Class Interpreter.LexerActionGetTokenType

extends BlankDebugEventListener
Class Inheritance

A lexer listener that just creates token objects as they are matched. scan() use this listener to get a single object. To get a stream of tokens, you must call scan() multiple times, recording the token object result after each call.

Field Summary

Modifier and TypeField and Description
pack-priv Grammar
g

public CommonToken

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
exitRule(String grammarFileName, String ruleName)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.exitRule.

Implements org.antlr.runtime.debug.DebugEventListener.exitRule.

This is the last thing executed before leaving a rule.
Inherited from org.antlr.runtime.debug.BlankDebugEventListener:
addChildbecomeRootbeginBacktrackbeginResynccommenceconsumeHiddenTokenconsumeNodeconsumeTokencreateNodecreateNodeendBacktrackendResyncenterAltenterDecisionenterRuleenterSubRuleerrorNodeexitDecisionexitSubRulelocationLTLTmarknilNoderecognitionExceptionrewindrewindsemanticPredicatesetTokenBoundariesterminate

Field Detail

gback to summary
pack-priv Grammar g
tokenback to summary
public CommonToken token

Constructor Detail

LexerActionGetTokenTypeback to summary
public LexerActionGetTokenType(Grammar g)

Method Detail

exitRuleback to summary
public void exitRule(String grammarFileName, String ruleName)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.exitRule.

Implements org.antlr.runtime.debug.DebugEventListener.exitRule.

Doc from org.antlr.runtime.debug.DebugEventListener.exitRule.

This is the last thing executed before leaving a rule. It is executed even if an exception is thrown. This is triggered after error reporting and recovery have occurred (unless the exception is not caught in this rule). This implies an "exitAlt" event. The grammarFileName allows composite grammars to jump around among multiple grammar files.

Annotations
@Override