elikaski / BF-it

A C-like language to Brainfuck compiler, written in Python
MIT License
120 stars 11 forks source link

Add enums #57

Open elikaski opened 3 years ago

elikaski commented 3 years ago

Could be nice to have user-defined enums

enum RESULT {
   SUCCESS=0,
   FAILURE=1,
   UNKNOWN=2
}

That can be used inside switch-case as literals:

switch (result) {
   case SUCCESS: ...
   case FAILURE: ....
   case UNKNOWN: ...
}

And as parameters to functions

void foo(RESULT r) {
   if (r == SUCCESS) ...
}
NeeEoo commented 3 years ago

#define would work like this. Enums i think, works like this RESULT.FAILURE

elikaski commented 3 years ago

There are several ways to use enums, I don't mind which one we choose as long as it works 😄

NeeEoo commented 3 years ago

It would probably be better to just replace RESULT.FAILURE with 1 in the compilation process.