elikaski / BF-it

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

Add multiple file support and executing BrainF code from a function #77

Open Ponali opened 9 months ago

Ponali commented 9 months ago

(feature request) It would be nice to have a way to seperate code into files. For example, i would make a subfolder in the BF-it folder with my code's name (let's say the name is calculator), and put multiple .code files inside, with one called main.code If a .code file required another file, it would have a line that'll be like this: #import calculation.code (using .code in the line could be optional) When it will import another file, every variable and function that is inside the file will be copied, for example: inside calculation.code:

int square(int a){
  return a*a;
}

inside main.code:

#import calculation.code

int sqresult=0;
int num=0;
void main(){
  print("Enter a number...");
  num = readint();
  sqresult = calculation.square(num);
  print("The number ");
  printint(num);
  print(" squared is equal to ");
  printint(sqresult);
  print(".\n");
}

What would be also nice is to be able to insert BrainF code at compile time, for example:

int res = 0;
void main(){
  res = insert("++++[>++++++++<-]>[<+>-]<");
  if(res==32){
    print("BrainF insert success")
  } else {
    print("Error, res = ");
    printint(res);
    print(" and not 32.")
  }
}

(if you ever implement this, is it possible that you don't make it remove comments? thanks!)