[antlr-interest] bug in C target?

Thomas Brandon tbrandonau at gmail.com
Tue Aug 28 08:17:20 PDT 2007


On 8/29/07, Rupert Mazzucco <mazzucco at iiasa.ac.at> wrote:
> Hello,
>
> I'm trying to pass a function pointer to a rule, like so
>
>   grammar foo;
>   options { language='C'; }
>   file[void (*f)(char,char)]: SYM+;
>   SYM: .;
>
> Antlr produces the following garbled declaration in fooParser.h
> (similarly in fooParser.c)
>
>   /** \file
>    *  This C header file was generated by $ANTLR
>    *
>    *     -  From the grammar source file : foo.g
>   ...
>   /** Context tracking structure for fooParser
>    */
>   typedef struct fooParser_Ctx_struct
>   {
>       /** Built in ANTLR3 context tracker contains all the generic elements
>        *  required for context tracking.
>        */
>       pANTLR3_PARSER   pParser;
>
>       void (*file)    (struct fooParser_Ctx_struct * ctx, char));    unsigned char * (*getGrammarFileName)();
>   /*** PROBLEM HERE:                                      ^^^^^                             ***/
>       void        (*free)   (struct fooParser_Ctx_struct * ctx);
>
>   }
>       fooParser, * pfooParser;
>
> Passing a function pointer seems to work fine if the function takes only one argument,
> ie the code for file[void (*f)(char)] looks ok.
>
> Does anybody have an idea how to fix that?  Or am I not supposed to pass function
> pointers at all?
This is a known bug. ANTLR doesn't handle commas in argument action
blocks. It should, hopefully, be dealt with when the grammar used by
ANTLR is converted to a v3 grammar. I don't think you can escape
comma's. In C a workaround would be to use a typedef or define.

Tom.
>
> Regards
> --
> Rupert Mazzucco         <mazzucco at iiasa.ac.at>
> Research Scholar, Evolution and Ecology Program
> IIASA - Institute for Applied Systems Analysis
> Schlossplatz 1, 2361 Laxenburg, Austria
> Phone: +43 2236 807 522   Fax: +43 2236 713 13
>


More information about the antlr-interest mailing list