elikaski / BF-it

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

Add debug prints #14

Open elikaski opened 4 years ago

elikaski commented 4 years ago

Add the ability to include comments in the compile code, for every source code line. For example, if we have:

if (x) 
{y;}

Will compile to something like:

; start of if statement (line 5 column 10)
    ; start of evaluate if expression (line 5 column 11)
        ; evaluate variable x (line 5 column 14)
            <>>>--++<<<.......
        ; end of evaluate variable x (line 5 column 15)
    ; end of if expression evaluation (line 5 column 16)
    ; enter if scope (line 6 column 1)
        ; start of statement y (line 6 column 2)
            >>><<,++-- .......
        ; end of statement y (line 6 column 3)
    ; end of if scope (line 6 column 4)
; end of if statement (line 6 column 4)

Same for arithmetic calculations, loops, and so on

This will help users deeply understand BF algorithms, and will help the compiler developers to debug.