On 4 Jun 2009, at 15:37, Kynn Jones wrote:
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.
...
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?
You might inquiry in the Usenet newsgroup comp.compilers.
(Yes, I definitely want to
stay with C, rather than C++.)
Bison is now quite good at C++, see
http://lists.gnu.org/archive/html/help-bison/2009-05/msg00040.html
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.
From what I can see from <http://en.wikipedia.org/wiki/JSON> you
somehow want to create these objects in other languages, right? One
way might be to use the Bison generated top generate an AST. The it is
not difficult to reverse that to pretty-print that AST into other
languages. In that example on that page, you might parse the Object
into C++ std::map. Then print out that object in other languages.
Hans
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison