[antlr-interest] bug in C target?

Rupert Mazzucco mazzucco at iiasa.ac.at
Tue Aug 28 08:10:19 PDT 2007


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


More information about the antlr-interest mailing list