How far can CTFE go?

Timon Gehr timon.gehr at gmx.ch
Fri Feb 3 16:54:55 PST 2012


On 02/03/2012 12:22 AM, H. S. Teoh wrote:
> I'm experimenting with pluggable expression parser modules, and I'm
> wondering if I can use CTFE to build parser tables and such. What are
> the current limitations of CTFE? Are dynamic arrays of structs
> supported? Associative arrays?  What about compile-time cross-module
> initialization?
>
> The idea is to have a library of modules that parse different kinds of
> expressions, and depending on which subset of modules are actually
> imported into the main program, the capability of the generated parser
> will vary. E.g., the basic parser understands only scalar expressions;
> import the vector module and it gets extended to handle vector
> expressions; import another module and it understands other kinds of
> expressions (matrices, etc.).  The parser will be fully specified at
> compile-time (I'm not planning to support dynamically loading parsing
> modules), so ideally this should be possible to handle using CTFE.
>
> Or is this just a fool's errand?

This should work just fine. There is at least one compile-time parser 
generator for D around, but I cannot find it.

>
> On another level, how far are we expecting CTFE to go eventually? In my
> mind, the ideal situation would be that CTFE can replace writing an
> arbitrarily complex helper program that generates D code (either
> functions or data, etc.) which then gets incorporated into the main
> program.
>
>
> T
>

It can already do that!

mixin(arbitrarily_complex_helper_function());






More information about the Digitalmars-d-learn mailing list