[antlr-interest] bug in C target?

Jim Idle jimi at temporal-wave.com
Tue Aug 28 11:30:00 PDT 2007


It is to do with the way parameters are parsed in the .g source file. You can probably create typedef for the function pointer and use that though. Or you could create a struct that contains the function pointers you need and so on, which is how the runtime works. However, you may find it better to not pass around function pointers.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Rupert Mazzucco
> Sent: Tuesday, August 28, 2007 8:10 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] bug in C target?
> 
> 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?
> 
> 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
> 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.484 / Virus Database: 269.12.10/976 - Release Date:
> 8/27/2007 6:20 PM
> 

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.484 / Virus Database: 269.12.10/976 - Release Date: 8/27/2007 6:20 PM
 


More information about the antlr-interest mailing list