[antlr-interest] Suggestion to improve the 'ParseTreeDebugParser' class in antlr

Prashant Deva prashant.deva at gmail.com
Fri Apr 15 04:05:09 PDT 2005


Here is a portion of the comment from the
'addCurrentTokenToParseTree()' method in the ParseTreeDebugParser
class-

/**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.
*  ....
*/

And this is how the current match method is declared - 
public void match(int i) 
{		
  addCurrentTokenToParseTree();
  super.match(i);
}



What i am suggesting is that instead of the above code, we have code like this- 

public void match(int i) 
{		
 Token t ;
 if ( LA(1)==Token.EOF_TYPE ) ;
        t = new antlr.CommonToken("EOF");
 else
   t = LT(1); 

  super.match(i);

 addTokenToParseTree(t);
}


This way the parse tree won't contain the mismtached token, as the
token won't be added to the tree if the exception is thrown.

PRASHANT


More information about the antlr-interest mailing list