www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - scanner and parser generator for D

reply Marc <spamisbad dontdoit.org> writes:
Hi people,

I'm wondering if someone hasn't thought of developing an equivalent of Flex and
Bison generating D code, possibly reentrant (one of the major flex/bison flaws
being bad support for C++ code)

As a possibly more interesting alternative, I also had a look at the Spirit
library ( http://spirit.sourceforge.net/ ) and I think adapting its concepts to
D would be a really valuable addition to the D standard library (and would
represent a real stress test for the D overloadiing and templating models).

For people who are too lazy to click, Spirit is a pure C++ header-based library
that implements EBNF grammars using C++ objects and operators, and also include
scanning facilities.

regards,
Marc
Jun 22 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Marc wrote:

 Hi people,
 
 I'm wondering if someone hasn't thought of developing an equivalent 
 of Flex and Bison generating D code,
<snip> I started developing something called SPE (Stewart's Parsing Engine). The idea is that tokenising and parsing work similarly and are covered in a single input file, and the generated program generates a parse tree that a compiler/interpreter can then interpret. I got as far as writing a parser for part of SPE itself, as a hand-coding of what SPE would generate, but not actually doing anything with it. It's in Java at the mo. But I've thought about switching the project over to D.
 possibly reentrant
Not sure what you mean by this....
 (one of the major flex/bison flaws being bad support for C++ code)
I think that's a flaw of C++ actually. The design of SPE relies on context-free grammar - whether that'll change depends on finding a way of implementing it.... Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Jun 22 2004
parent reply Marc <spamisbad dontdoit.org> writes:
 possibly reentrant
Not sure what you mean by this....
i mean that the generated code would be elligible for multithreaded apps, ie. all state informations should be stored in a D class or structure.
 (one of the major flex/bison flaws being bad support for C++ code)
I think that's a flaw of C++ actually. The design of SPE relies on context-free grammar - whether that'll change depends on finding a way of implementing it....
what i mean is flex/bison generated code relies on static global variables that make it impossible to be used for a reentrant parser. There is a C++ mode for flex, but it uses deprecated C++ stream coding style. Have you taken a look at Spirit ? Its concepts are extremely interesting imho.
Jun 22 2004
parent reply Andy Friesen <andy ikagames.com> writes:
Marc wrote:

 Have you taken a look at Spirit ? Its concepts are extremely interesting imho.
Spirit relies very heavily on deducing template arguments on overloaded operators, so if you're suggesting implementing Spirit in D, you've got your work cut out for you. :) The existing Spirit library is, as you say, interesting, but somewhat brittle. When it does work, (on GCC and MSVC 7.1) it can take a long, long time to compile. When it doesn't, the error messages are long enough to make me nostalgic for STL errors. :) -- andy
Jun 22 2004
parent Marc <spamisevil sodontdoit.org> writes:
Spirit relies very heavily on deducing template arguments on overloaded 
operators, so if you're suggesting implementing Spirit in D, you've got 
your work cut out for you. :)

The existing Spirit library is, as you say, interesting, but somewhat 
brittle.  When it does work, (on GCC and MSVC 7.1) it can take a long, 
long time to compile.  When it doesn't, the error messages are long 
enough to make me nostalgic for STL errors. :)
indeed ! so i wonder how D would handle such stuff... i think it's a great playground for 'extreme' use of templates, overloading.. etc the brittleness of Spirit is an evidence of the difficulty to implement a C++ compiler, and so comes D...
Jun 22 2004