Boost logo

Boost :

Subject: Re: [boost] compile time parser generator
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2012-01-07 20:32:33


From: Dave Abrahams
> on Fri Jan 06 2012, "Martin Bidlingmaier" <Martin.Bidlingmaier-AT-gmx.de> wrote:

>> 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?

> It was only a matter of time before someone proposed this. Of course it
> has a chance to make it into boost. I guess the the first question will
> be, "can you describe some plausible use-cases?"

Regular expressions.

If there were an interpreted language (perhaps domain specific) with a simple grammar then we could inline string constants with code into C++ code that gets parsed at compile time to generate executable code. So simple things like sed and awk scripts could also be inlined into C++ as string literals and translated to executable code at compile time instead of runtime if you combine the interpreter library with the compile time parsing library. The benefit over run time interpretation of the string is debatable. It is only a performance optimization. I would say regular expression is the thing that is crying out for it. The real question is what kind of syntax errors will it generate when parsing fails? It would be nice to catch badly formed regular expressions at compile time, for example, though not so nice if the errors are not so nice. What this allows us to do is extend the language in the form of libraries (in a hackish sort of way) which is the desire of modern language theorists from what I've been told by my language theorist friends. I'd say it's almost as exciting as overloading the comma operator.

Regards,
Luke


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk