
Hi Martin,
with c++11's constexpr it got possible to parse strings in c++ at compile time. I've written a parser generator to create an AST for a given EBNF syntax at compile time, which can be traversed at both run time and compile time (actually, parsing can take place at run time, too, but it's probably rather slow). At the moment, the only compiler I know of that implements enough of c++11 features is gcc (version>= 4.6). Is refining my implementation worth the effort, has such a library a chance to make it into boost? Is maybe somebody already working on this?
We've been working on an open source library for building parsers parsing at compile-time. You can find the documentation of it here: http://abel.web.elte.hu/mpllibs/metaparse/index.html, the source code here: https://github.com/sabel83/mpllibs, example programs for using it here: https://github.com/sabel83/mpllibs/tree/master/libs/metaparse/example. There is a type-safe printf based on it (parsing the printf format string at compile-time) which you can also take a look at as an example: http://abel.web.elte.hu/mpllibs/safe_printf/index.html. The library uses parser combinators. It doesn't build an AST, unless you - as the user of the library - do it yourself. The reason behind it is that it would make compilation much slower. Building parsers from an EBNF is a manual task because of not building an AST, but it is not complicated and the resulting code reflects the EBNF. You can find an example for that in the following paper: Zoltán Porkoláb, Ábel Sinkovics: Domain-specific Language Integration with Compile-time Parser Generator Library In Eelco Visser, Jaakko Järvi, editors, Proceedings of the ninth international conference on Generative programming and component engineering (GPCE 2010). ACM, October 2010, pp. 137-146. The library provides a number of combinators already implemented and tested, see http://abel.web.elte.hu/mpllibs/metaparse/reference.html. The library is mostly based on the old standard with the exception of defining the text to parse, which needs to be a compile-time character sequence. As described in the paper mentioned above, it should be doable using user-defined literals (and a few other C++11 features), however we couldn't try it out on any compiler so far. How does your solution do it? Regards, Ábel