[cfe-dev] Help getting started

Douglas Gregor dgregor at apple.com
Tue Jan 3 08:46:08 PST 2012

On Dec 31, 2011, at 7:10 PM, Dave Abrahams wrote:

> Hi all,
> I'm interested in implementing a C++ syntax extension, described here:
> http://cpp-next.com/archive/2011/11/having-it-all-pythy-syntax/.  The
> idea is that it would be a pure syntax extension for function
> templates. With a little help from a C++ grammar expert, I have the
> grammar productions written out already.  What's not clear to me now,
> though, is what approach to take in implementing it.  One possibility is
> to reimplement the code for parsing function templates, but that code
> does a *lot* more than merely parsing.  Another approach I can think of
> is to modify the existing function template parsing code to handle this
> alternate syntax in parallel, but that looks hard.  Any advice
> appreciated.

When you're implementing a feature for the first time, it's typically easier to build up from nothing rather than splice the feature into existing parsing code. This way, you can slowly grow the syntax and semantics that you want to accept, and won't get nearly as many surprises ("wait, I meant to disallow that…"). Naturally, you should factor out common functionality along the way so you're not repeating code.

For the extension you're discussing, specifically, it looks like it's syntactically distinct enough that it should be relatively easy to identify based on the "[] unqualified-id" prefix when you're parsing one of your new function (templates). You'll want to synthesize template parameters and parameter/function declarators so that your new parsing code ends up calling a similar sequence of Sema actions to the "normal" code path.

	- Doug

More information about the cfe-dev mailing list