help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

callbacks, #define/typedef tricks


From: Kynn Jones
Subject: callbacks, #define/typedef tricks
Date: Thu, 4 Jun 2009 09:37:37 -0400

Hi.  I want to write a "base parser" for JSON that can be easily customized
to generate objects in any interpreted language (such as Perl or R) whose
underlying implementation is in C.

The idea is that I need a good way to plugin callbacks corresponding to the
various "parser events".  E.g. I want to be able to write rules like

%token <toktext> __INTEGER __FLOAT __STRING __BOOLEAN __NULL
%type  <THINGIE> value object array
...
value:
        __INTEGER       { $$ = (CALLBACK_FOR_INTEGER)($1); }
      | __FLOAT         { $$ = (CALLBACK_FOR_FLOAT)($1); }
      | __STRING        { $$ = (CALLBACK_FOR_STRING)($1); }
      | __BOOLEAN       { $$ = (CALLBACK_FOR_BOOLEAN)($1); }
      | __NULL          { $$ = (CALLBACK_FOR_NULL)(); }
      | object
      | array
      ;

For each target language (R, Perl, Python, etc.), a different set of
callbacks would be plugged in.  There are two main objstacles, as I see it.
 First, the mechanics of plugging in these callbacks in a way that is
straightforward and safe.  Second, the fact that the return types for all
these callbacks will differ from one target language to the next, so THINGIE
would have different meanings depending on the target language.

I think I could muddle through with these two problems, and probably come up
with a m4-heavy monstrosity filled with mysterious macrobatics, but I
thought I'd see how others may have solved them.  Are there any features in
Bison that would be particularly helpful with any of these problems and that
I should focus on?  Does anyone know of any Bison parser (with a publicly
accessible source code, and preferably written in C) that attempts this sort
of pluggable polymorphic callback architecture?  (Yes, I definitely want to
stay with C, rather than C++.)

TIA!

kynnjo


reply via email to

[Prev in Thread] Current Thread [Next in Thread]