Thread overview
How far can CTFE go?
Feb 02, 2012
H. S. Teoh
Feb 03, 2012
Manfred Nowak
Feb 04, 2012
Timon Gehr
February 02, 2012
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?

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

-- 
Guns don't kill people. Bullets do.
February 03, 2012
H. S. Teoh wrote:

> the ideal situation would be that CTFE can replace writing an arbitrarily complex helper program

Aebitrary complex helper programs may include viruses and other nice surprises. Walter does not want that adminstrators have to worry about a compilation step to torture the system in such a way.

Which restrictions may supress such torture seems unknown.

-manfred



February 04, 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());