antlr.debug

Class ParseTreeDebugParser


public class ParseTreeDebugParser
extends LLkParser

Override the standard matching and rule entry/exit routines to build parse trees. This class is useful for 2.7.3 where you can specify a superclass like class TinyCParser extends Parser(ParseTreeDebugParser);

Field Summary

protected Stack
currentParseTreeRoot
Each new rule invocation must have it's own subtree.
protected ParseTreeRule
mostRecentParseTreeRoot
Track most recently created parse subtree so that when parsing is finished, we can get to the root.
protected int
numberOfDerivationSteps
For every rule replacement with a production, we bump up count.

Fields inherited from class antlr.LLkParser

k

Fields inherited from class antlr.Parser

astFactory, inputState, returnAST, tokenNames, tokenTypeToASTClassMap, traceDepth

Constructor Summary

ParseTreeDebugParser(ParserSharedInputState state, int k_)
ParseTreeDebugParser(TokenBuffer tokenBuf, int k_)
ParseTreeDebugParser(TokenStream lexer, int k_)
ParseTreeDebugParser(int k_)

Method Summary

protected void
addCurrentTokenToParseTree()
This adds LT(1) to the current parse subtree.
int
getNumberOfDerivationSteps()
ParseTree
getParseTree()
void
match(BitSet bitSet)
Make sure current lookahead symbol matches the given set Throw an exception upon mismatch, which is catch by either the error handler or by the syntactic predicate.
void
match(int i)
Make sure current lookahead symbol matches token type t.
void
matchNot(int i)
void
traceIn(String s)
Create a rule node, add to current tree, and make it current root
void
traceOut(String s)
Pop current root; back to adding to old root

Methods inherited from class antlr.LLkParser

LA, LT, consume, traceIn, traceOut

Methods inherited from class antlr.Parser

LA, LT, addMessageListener, addParserListener, addParserMatchListener, addParserTokenListener, addSemanticPredicateListener, addSyntacticPredicateListener, addTraceListener, consume, consumeUntil, consumeUntil, defaultDebuggingSetup, getAST, getASTFactory, getFilename, getInputState, getTokenName, getTokenNames, getTokenTypeToASTClassMap, isDebugMode, mark, match, match, matchNot, panic, recover, removeMessageListener, removeParserListener, removeParserMatchListener, removeParserTokenListener, removeSemanticPredicateListener, removeSyntacticPredicateListener, removeTraceListener, reportError, reportError, reportWarning, rewind, setASTFactory, setASTNodeClass, setASTNodeType, setDebugMode, setFilename, setIgnoreInvalidDebugCalls, setInputState, setTokenBuffer, traceIn, traceIndent, traceOut

Field Details

currentParseTreeRoot

protected Stack currentParseTreeRoot
Each new rule invocation must have it's own subtree. Tokens are added to the current root so we must have a stack of subtree roots.

mostRecentParseTreeRoot

protected ParseTreeRule mostRecentParseTreeRoot
Track most recently created parse subtree so that when parsing is finished, we can get to the root.

numberOfDerivationSteps

protected int numberOfDerivationSteps
For every rule replacement with a production, we bump up count.

Constructor Details

ParseTreeDebugParser

public ParseTreeDebugParser(ParserSharedInputState state,
                            int k_)

ParseTreeDebugParser

public ParseTreeDebugParser(TokenBuffer tokenBuf,
                            int k_)

ParseTreeDebugParser

public ParseTreeDebugParser(TokenStream lexer,
                            int k_)

ParseTreeDebugParser

public ParseTreeDebugParser(int k_)

Method Details

addCurrentTokenToParseTree

protected void addCurrentTokenToParseTree()
            throws TokenStreamException
This adds LT(1) to the current parse subtree. Note that the match() routines add the node before checking for correct match. This means that, upon mismatched token, there will a token node in the tree corresponding to where that token was expected. For no viable alternative errors, no node will be in the tree as nothing was matched() (the lookahead failed to predict an alternative).

getNumberOfDerivationSteps

public int getNumberOfDerivationSteps()

getParseTree

public ParseTree getParseTree()

match

public void match(BitSet bitSet)
            throws MismatchedTokenException,
                   TokenStreamException
Make sure current lookahead symbol matches the given set Throw an exception upon mismatch, which is catch by either the error handler or by the syntactic predicate.
Overrides:
match in interface Parser

match

public void match(int i)
            throws MismatchedTokenException,
                   TokenStreamException
Make sure current lookahead symbol matches token type t. Throw an exception upon mismatch, which is catch by either the error handler or by the syntactic predicate.
Overrides:
match in interface Parser

matchNot

public void matchNot(int i)
            throws MismatchedTokenException,
                   TokenStreamException
Overrides:
matchNot in interface Parser

traceIn

public void traceIn(String s)
            throws TokenStreamException
Create a rule node, add to current tree, and make it current root
Overrides:
traceIn in interface LLkParser

traceOut

public void traceOut(String s)
            throws TokenStreamException
Pop current root; back to adding to old root
Overrides:
traceOut in interface LLkParser