CTFE & code generators based on PEG grammars?

Alex AJ at gmail.com
Sat Apr 6 14:19:58 UTC 2019


On Saturday, 6 April 2019 at 12:06:22 UTC, Robert M. Münch wrote:
> I like the idea of DSL which are transpiled into the target 
> language that gets compiled or are interpreted at run-time. 
> Since D is compiled, I would like to transpile the DSL to D at 
> compile-time.
>
> The idea is, that I can write a string (or maybe even a scope 
> block?) in my DSL and use a CTFE grammer to transpile the code.
>
> Does anybody has any experience with such an approach? Are the 
> CTFE facilities overall sufficient to implement something like 
> this? Or is there a much better approach?


Sure, there is no problem. PEG actually has several grammars. 
CTFE is CT, and CTFE is in general RT(as long as it depends on no 
RT inputs). That is CTFE is CT RTFE where runtime functions are 
executed at compile time when the inputs are CT.

The issues is that you get no debugger support to help you and so 
it can be a real pain for complex languages.



More information about the Digitalmars-d-learn mailing list