[antlr-interest] Problems with rule variable initilization

Moschakis, Ioannis imoschak at gmail.com
Sat May 17 06:43:17 PDT 2008


Hello all,
I am trying to create a lexer/parser for sql in C with ANTLR and C target.
The problem that arises is that the code generated by ANTLR always tries to
initilize rule variables to NULL which is not acceptable at least for the
GCC compiler for variables of type ANTLR3_STRING_struct.
For example:
attr_assign_value returns [ ANTLR3_STRING_struct attName,
ANTLR3_STRING_struct val ]
    :   attr_name EQT value {
             $attName.appendS(&$attName,&$attr_name.attrName);
             $val.appendS(&$val,&$value.value);
         }
    ;

the previous rule generates the following code (part of it shown here) :
...
ANTLR3_STRING_struct attr_name1;
    #undef    RETURN_TYPE_attr_name1
    #define    RETURN_TYPE_attr_name1 ANTLR3_STRING_struct

    ANTLR3_STRING_struct value2;
    #undef    RETURN_TYPE_value2
    #define    RETURN_TYPE_value2 ANTLR3_STRING_struct

    /* Initialize rule variables
     */


    attr_name1 =  NULL;
    value2 = NULL;
    retval.start = LT(1);
...
The compiler says that attr_name1 = NULL and value2=NULL are incompatible
types which is ofcourse correct. Is there a way to tell ANTLR not to
generate these lines or generate custom code instead of this? Thanks in
advance for any help. Sorry for my bad English.

Regards,
imoschak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080517/bdbad3da/attachment.html 


More information about the antlr-interest mailing list