[antlr-interest] Re: tree parsing errors (was <AST>:0:0: expecting IDENT, found '<ASTNULL>')

Terence Parr parrt at cs.usfca.edu
Sun Nov 28 10:04:24 PST 2004



On Nov 28, 2004, at 12:36 AM, Muhammad Masoom Alam wrote:
> Dear all
>
> during tree evaluation , we often this exception/error
>
> <AST>:0:0: expecting IDENT, found '<ASTNULL>'
> or
>
> <AST>: expecting IDENT, found '<empty tree>'
>
> is there is any specific reason for these errors ,
> becaz program is running as well, and if tree
> evaluation grammar is correct , why these errors are
> comming and how we can avoid them or stop them.
>
> i means some specfic soltuion ??

Hi.  First my profuse apologies.  This tree parser error is essentially 
worthless. :(  I have a suggestion, however, until I can pay attention 
to the tree parsers.

I have my own AST node in which I store the actual token matched as a 
payload.  You need to override:

     public void initialize(Token token) {
         this.token = token;
     }

so that you can store the token in the AST node.  Then, override 
getLine so you can get line info:

     public int getLine() {
         if ( token!=null ) {
             return token.getLine();
         }
         return 0;
     }

This works great except for imaginary nodes (nodes for which there was 
no real token).  I use this as "operators" in my tree to say things 
like "the subtree is a var decl"; e.g., DECL token type.  Creating a 
token "out of thin air" means you must set it's line number to 
something sane.  You will see me do things like this in my grammar:

{declNode.setLine(line); declNode.setColumn(col);}

where I have computed line/col from another (real) token.  Then error 
messages seem to be ok :)

Also turn on -traceTreeParser and it will tell you what rule you were 
in when you got the message.

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list