[antlr-interest] XML output .

cintyram <cintyram at yahoo.com> cintyram at yahoo.com
Wed Jan 29 13:18:42 PST 2003


hi ,
 this post actually addresses two related issues , so i did not post
them in seperate mails

i am trying to visualise the ast constructed by my parser,
and the easiest way i felt was to output it in xml and view it in a
browser;

1. i wanted the outpout in a string istead of in a strem , so i
modified the method  in baseast.cpp as follows  ;
 actually i wanted to put the token names but i dont know how to
access them from the baseast class ; they are available to the parser
and tree parser ; since wanting to know the token names from the ast
or from any where a token is available seems to me to be a useful
feature, what would be a standard way to do it? 
[eg: put a static pointer to the table in Token class , and provide
methods to assign to it when ever we need names? ]


ANTLR_USE_NAMESPACE(std)string BaseAST::toStringList() const
{
    ANTLR_USE_NAMESPACE(std)string ts="";
    int type;
    
    char str[10] ;
    
    ts += "\n<NODE_" ;
    ts += itoa(this->getType() , str , 10  );
    ts += ">\n" ; 
        
    if (getFirstChild())
    {
        /// ts+=" ( ";
        ts+=toString();
        ts+=getFirstChild()->toStringList();
        /// ts+=" )\n";
    }
    else
    {
        ts+=" ";
        ts+=toString();
    }
        
     ts += "\n</NODE_" ;
     ts += itoa(this->getType() , str , 10  );
     ts += ">\n" ; 
    

    if (getNextSibling())
        ts+=getNextSibling()->toStringList();

    return ts;
}

2. in my method xml out put like 

 <tag>
 <
</tag>
is not being accepted as valid by the browser ;

even if i enclose it in double quotes.. 
how do i over come this ?
thanks in advance
ram



 

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



More information about the antlr-interest mailing list