org.antlr.tool
Class Interpreter

java.lang.Object
  extended by org.antlr.tool.Interpreter

public class Interpreter
extends java.lang.Object

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.


Field Summary
protected  Grammar grammar
           
protected  IntStream input
           
 
Constructor Summary
Interpreter(Grammar grammar, IntStream input)
           
 
Method Summary
 java.lang.String getSourceName()
           
 Token nextToken()
           
 ParseTree parse(java.lang.String startRule)
           
 void parse(java.lang.String startRule, DebugEventListener actions, java.util.List visitedStates)
           
 ParseTree parse(java.lang.String startRule, java.util.List visitedStates)
           
protected  void parseEngine(java.lang.String startRule, NFAState start, NFAState stop, IntStream input, java.util.Stack ruleInvocationStack, DebugEventListener actions, java.util.List visitedStates)
          Fill a list of all NFA states visited during the parse
 int predict(DFA dfa)
          Given an input stream, return the unique alternative predicted by matching the input.
 void reportScanError(RecognitionException re)
           
 CommonToken scan(java.lang.String startRule)
           
 void scan(java.lang.String startRule, DebugEventListener actions, java.util.List visitedStates)
          For a given input char stream, try to match against the NFA starting at startRule.
 CommonToken scan(java.lang.String startRule, java.util.List visitedStates)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

grammar

protected Grammar grammar

input

protected IntStream input
Constructor Detail

Interpreter

public Interpreter(Grammar grammar,
                   IntStream input)
Method Detail

nextToken

public Token nextToken()

scan

public void scan(java.lang.String startRule,
                 DebugEventListener actions,
                 java.util.List 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.

Throws:
RecognitionException

scan

public CommonToken scan(java.lang.String startRule)
                 throws RecognitionException
Throws:
RecognitionException

scan

public CommonToken scan(java.lang.String startRule,
                        java.util.List visitedStates)
                 throws RecognitionException
Throws:
RecognitionException

parse

public void parse(java.lang.String startRule,
                  DebugEventListener actions,
                  java.util.List visitedStates)
           throws RecognitionException
Throws:
RecognitionException

parse

public ParseTree parse(java.lang.String startRule)
                throws RecognitionException
Throws:
RecognitionException

parse

public ParseTree parse(java.lang.String startRule,
                       java.util.List visitedStates)
                throws RecognitionException
Throws:
RecognitionException

parseEngine

protected void parseEngine(java.lang.String startRule,
                           NFAState start,
                           NFAState stop,
                           IntStream input,
                           java.util.Stack ruleInvocationStack,
                           DebugEventListener actions,
                           java.util.List visitedStates)
                    throws RecognitionException
Fill a list of all NFA states visited during the parse

Throws:
RecognitionException

predict

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.


reportScanError

public void reportScanError(RecognitionException re)

getSourceName

public java.lang.String getSourceName()