FileDocCategorySizeDatePackage
ParseTreeDebugParser.javaAPI DocGlassfish v2 API3522Wed Feb 08 12:31:22 GMT 2006persistence.antlr.debug

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);

Fields Summary
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.
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.
Constructors Summary
public ParseTreeDebugParser(int k_)

 // n replacements plus step 0

	   
		super(k_);
	
public ParseTreeDebugParser(ParserSharedInputState state, int k_)

		super(state,k_);
	
public ParseTreeDebugParser(TokenBuffer tokenBuf, int k_)

		super(tokenBuf, k_);
	
public ParseTreeDebugParser(TokenStream lexer, int k_)

		super(lexer,k_);
	
Methods Summary
protected voidaddCurrentTokenToParseTree()
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).

		if (inputState.guessing>0) {
			return;
		}
		ParseTreeRule root = (ParseTreeRule)currentParseTreeRoot.peek();
		ParseTreeToken tokenNode = null;
		if ( LA(1)==Token.EOF_TYPE ) {
			tokenNode = new ParseTreeToken(new persistence.antlr.CommonToken("EOF"));
		}
		else {
			tokenNode = new ParseTreeToken(LT(1));
		}
		root.addChild(tokenNode);
	
public intgetNumberOfDerivationSteps()

		return numberOfDerivationSteps;
	
public persistence.antlr.ParseTreegetParseTree()

		return mostRecentParseTreeRoot;
	
public voidmatch(int i)

		addCurrentTokenToParseTree();
		super.match(i);
	
public voidmatch(persistence.antlr.collections.impl.BitSet bitSet)

		addCurrentTokenToParseTree();
		super.match(bitSet);
	
public voidmatchNot(int i)

		addCurrentTokenToParseTree();
		super.matchNot(i);
	
public voidtraceIn(java.lang.String s)
Create a rule node, add to current tree, and make it current root

		if (inputState.guessing>0) {
			return;
		}
		ParseTreeRule subRoot = new ParseTreeRule(s);
		if ( currentParseTreeRoot.size()>0 ) {
			ParseTreeRule oldRoot = (ParseTreeRule)currentParseTreeRoot.peek();
			oldRoot.addChild(subRoot);
		}
		currentParseTreeRoot.push(subRoot);
		numberOfDerivationSteps++;
	
public voidtraceOut(java.lang.String s)
Pop current root; back to adding to old root

		if (inputState.guessing>0) {
			return;
		}
		mostRecentParseTreeRoot = (ParseTreeRule)currentParseTreeRoot.pop();