elikaski / BF-it

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

[BUG?] Assigning before declaring works, but it shouldn't work. #35

Open NeeEoo opened 3 years ago

NeeEoo commented 3 years ago
int main() {
    a = 1;
    int a;

    printint(a);
}
elikaski commented 3 years ago

Good catch The reason for that is that before compiling the function we need to determine how much space to make for the local variables So the compiler actually does two passes: first it goes through all the variable declarations, and in the second pass actually compiles code while ignoring declarations Need to think how to make it smarter