betterC CTFE nested switch

Abby loniro7678 at twit-mail.com
Mon Feb 17 10:18:32 UTC 2020


Hi there guys,
I was trying to generated code during compile time. Bassicly I'm 
creating a tokenizer and I would like to generated nested switch 
using betterC.

Basically convert something like this:

enum tokens =
[
     ['!', '='],
     ['>', '='],
     ['>'],
];

to:

switch(str[i])
{
     case '!':
         switch(str[i + 1])
         {
             case '=':
                 onToken(['!', '=']);
                 break;
             default: break;
         }
         break;
     case '>':
         switch(str[i + 1])
         {
             case '=':
                 onToken(['>', '=']);
                 break;
             default:
                 onToken(['>']);
                 break;
         }
         break;
     default: break;
}

but right now I'm stuck and I don't know how to achieve this. I 
was able to find out that:

1) Switches has to be labeled and the only way I know how to do 
so is to use string code and then mixing it. I was hoping for 
example to mixing only labels before switch and after continue 
and break but this does not seem to work :/

2) Format does not work in compile time using betterC (sprintf 
also does not work


Thank you very much for any kind if help
Kind regards Abby



More information about the Digitalmars-d-learn mailing list