├── README.md ├── bfcomp_v2.bf ├── examples └── game.bf ├── old ├── bfcomp_v0.bf └── bfcomp_v1.bf └── tools ├── bf.c ├── bfstrip.c ├── str_to_bf.c └── test.c /README.md: -------------------------------------------------------------------------------- 1 | # Brainf--k compiler: written in brainf--k! 2 | *By Truttle1* 3 | 4 | This is a (not very optimized) compiler that turns brainf--k code into assembly, which can then be assembled and run on Linux. The compiler was written in brainf--k itself, and v2 was compiled using v1. 5 | 6 | ## How to use 7 | 8 | If no version has been compiled yet, you can use the provided brainf--k compiler written in C (in the tools folder), which can be compiled using your favorite C compiler. 9 | 10 | When the self hosting compiler is set up, the input program is read in through stdin, and the program is outputted in stdout. So, to create an asm file, you would do: 11 | 12 | `./bfcomp < examples/game.bf > game.asm` 13 | 14 | Compiling and running these programs has been tested on Arch Linux and on Windows 11 running Ubuntu in a WSL environment, both running on a 64 bit AMD processor (because it was just one computer). 15 | 16 | Assembling and linking is accomplished by 17 | 18 | `nasm -f elf64 game.asm` 19 | 20 | `ld -o game game.o` 21 | 22 | 23 | 24 | ## v2 changes 25 | - In v1, there was a bug caused by brainf--k's cell limitations that only permitted 253 [] pairs. This version addresses that by making the loops use two cells for ID, rather than one. This enables programs like `game.bf` to compile correctly. -------------------------------------------------------------------------------- /bfcomp_v2.bf: -------------------------------------------------------------------------------- 1 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.--.+++++++++++++++++.-----------.++++++.-.------------------------------------------------------------------------------.++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++..---------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.++++++++++++++.-----------------.------------------------------------------------------------------.++++++++++++++++++++.----.+++++++++.---.--------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.--.+++++++++++++++++.-----------.++++++.-.------------------------------------------------------------------------------.++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------.+++++++++++++++++++.----.----------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.+++.-------------.-.+++++++++++.----------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+.-------------------.+++++++++++++++++.++.----------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+.-------------------.+++++++++++++++++.++.----------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.--------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---.+++++++++++++++++++.-------------------.---------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------.+++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++++++.----.+++++++++.---.--------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------------.+++++++++++++.---.----------------.+++++++++++++.+++..+.------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.--------------.+++++.------------.-------------------------------------------------.------------.++++++++++++++++.--------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.-----------.-------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-----------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..+.--------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------------.+++++++++++++.---.----------------.+++++++++++++.+++..+.------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.--------------------------------------. 2 | [-] 3 | >>>>>> 4 | ++ >>>>> ++ # The label counters 5 | >>>- # Stack base of 255 6 | 7 | <<<<<<< 8 | <<<<<<< 9 | >, 10 | [ 11 | 12 | ############## BEGIN PLUS 13 | #### COPY #### 14 | [>+<-]> 15 | [<+<+>>-] 16 | + 17 | < 18 | << ++++ ++ [>> ---- --- << -] >> - # Subtracts 43 from {1} using an extra cell 19 | 20 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 21 | [>[-]<[-]] 22 | > 23 | [ # This happens when input == 43 24 | >>> 25 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------..------------------------------------------------------------. 26 | [-] 27 | <<< 28 | [-] 29 | ] 30 | << # Return to {1} 31 | ############## END PLUS 32 | 33 | # BETWEEN: MOVE ONE RIGHT 34 | [>+<-]> 35 | 36 | ############## BEGIN MINUS 37 | #### COPY #### 38 | [>+<-]> 39 | [<+<+>>-] 40 | + 41 | < 42 | << ++++ ++ [>> ---- --- << -] >> --- # Subtracts 45 from {1} using an extra cell 43 | 44 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 45 | [>[-]<[-]] 46 | > 47 | [ # This happens when input == 45 48 | >>> 49 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.-------------------.------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------..------------------------------------------------------------. 50 | [-] 51 | <<< 52 | [-] 53 | ] 54 | << # Return to {1} 55 | ############## END MINUS 56 | 57 | # BETWEEN: MOVE ONE RIGHT 58 | [>+<-]> 59 | 60 | ############## BEGIN LEFT 61 | #### COPY #### 62 | [>+<-]> 63 | [<+<+>>-] 64 | + 65 | < 66 | << ++++ ++ [>> ---- ---- -- << -] >> # Subtracts 60 from {1} using an extra cell 67 | 68 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 69 | [>[-]<[-]] 70 | > 71 | [ # This happens when input == 60 72 | >>> 73 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.-------------------.------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------...------------------------------------------------------------. 74 | [-] 75 | <<< 76 | [-] 77 | ] 78 | << # Return to {1} 79 | ############## END LEFT 80 | 81 | # BETWEEN: MOVE ONE RIGHT 82 | [>+<-]> 83 | 84 | ############## BEGIN RIGHT 85 | #### COPY #### 86 | [>+<-]> 87 | [<+<+>>-] 88 | + 89 | < 90 | << ++++ ++ [>> ---- ---- -- << -] >> -- # Subtracts 62 from {1} using an extra cell 91 | 92 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 93 | [>[-]<[-]] 94 | > 95 | [ # This happens when input == 62 96 | >>> 97 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------...------------------------------------------------------------. 98 | [-] 99 | <<< 100 | [-] 101 | ] 102 | << # Return to {1} 103 | ############## END RIGHT 104 | 105 | # BETWEEN: MOVE ONE RIGHT 106 | [>+<-]> 107 | 108 | ############## BEGIN DOT 109 | #### COPY #### 110 | [>+<-]> 111 | [<+<+>>-] 112 | + 113 | < 114 | << ++++ ++ [>> ---- --- << -] >> ---- # Subtracts 46 from {1} using an extra cell 115 | 116 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 117 | [>[-]<[-]] 118 | > 119 | [ # This happens when input == 46 120 | >>> 121 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++++++++++..----------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.---------.+++++.++++++.---------------------.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------------------------------------------------------. 122 | [-] 123 | <<< 124 | [-] 125 | ] 126 | << # Return to {1} 127 | ############## END DOT 128 | 129 | # BETWEEN: MOVE ONE RIGHT 130 | [>+<-]> 131 | 132 | ############## BEGIN COMMA 133 | #### COPY #### 134 | [>+<-]> 135 | [<+<+>>-] 136 | + 137 | < 138 | << ++++ ++ [>> ---- --- << -] >> -- # Subtracts 44 from {1} using an extra cell 139 | 140 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 141 | [>[-]<[-]] 142 | > 143 | [ # This happens when input == 44 144 | >>> 145 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++++++++++..----------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.-----.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------------------------------------------------------. 146 | [-] 147 | <<< 148 | [-] 149 | ] 150 | << # Return to {1} 151 | ############## END COMMA 152 | 153 | 154 | # BETWEEN: MOVE ONE RIGHT 155 | [>+<-]> 156 | 157 | ############## BEGIN OPEN BRACKET 158 | #### COPY #### 159 | [>+<-]> 160 | [<+<+>>-] 161 | + 162 | < 163 | << ++++ ++++ ++ [>> ---- ---- - << -] >> - # Subtracts 91 from {1} using an extra cell 164 | 165 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 166 | [>[-]<[-]] 167 | > 168 | [ # This happens when input == 91 169 | >>>> # Move to cell containing A counter 170 | [<+>-] # Move it a cell to the left 171 | < # Go to it 172 | [>+>+<<-] # Two copies 173 | 174 | >>>>>> # Move to cell containing X counter 175 | [<+>-] # Move it a cell to the left 176 | < # Go to it 177 | [>+>+<<-] # Two copies 178 | 179 | >>>>+> # Go to start of the stack; temporarily make base of stack 0 180 | 181 | [>] # Proceed to end of stack 182 | < 183 | [[>>+<<-]<] # Shift everything in the stack two cells to the right 184 | - # Base of stack is 255 again 185 | << # Go to copy of A counter 186 | [>+>>+<<<-] # Enqueue with a second copy 187 | <<<<< # Go to copy of X counter 188 | [>+>>>> >>>> +<<<< <<<< <-] # Enqueue with a second copy 189 | >>>>> # Go to empty cell between A counter copies 190 | ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ + # A 191 | > 192 | [-<.>] # Print A counter many times 193 | 194 | <<<<<< 195 | ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ # X 196 | > 197 | [-<.>] # Print X counter many times 198 | # The rest up to the end label 199 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++.+++.--------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.++++++++++++++++.--------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++.------------------------------------------------------------------------------------------. 200 | [-] 201 | >>> 202 | [<+>-] 203 | < 204 | [>+>>+<<<-] # Put the copy there again: A counter 205 | <<<< 206 | [<+>-] 207 | < 208 | [>+>>+<<<-] # Put the copy there again: X counter 209 | 210 | >>>>>>>+> # Increment A to B for the end label 211 | [-<.>] # Print B counter many times 212 | <[-] # Reset B 213 | <<<< 214 | [-<.>] # Print X counter many times 215 | <[-] # Reset X 216 | 217 | >>>> 218 | [<+>-] 219 | <[->+>+<<] 220 | >>>+< 221 | ++++++[>-<[-]] # Check if A counter is 250 222 | > 223 | [<<<<<<<+>>>>>[-]>>[-]] 224 | 225 | <<+ # Increment label counter 226 | <<+++++ +++++.[-] #New Line 227 | <<<<<<< 228 | [-] 229 | ] 230 | << # Return to {1} 231 | ############## END OPEN BRACKET 232 | 233 | 234 | # BETWEEN: MOVE ONE RIGHT 235 | [>+<-]> 236 | 237 | ############## BEGIN CLOSING BRACKET 238 | #### COPY #### 239 | [>+<-]> 240 | [<+<+>>-] 241 | + 242 | < 243 | << ++++ ++++ ++ [>> ---- ---- - << -] >> --- # Subtracts 93 from {1} using an extra cell 244 | 245 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 246 | [>[-]<[-]] 247 | > 248 | [ # This happens when input == 93 249 | >>>> >>>> >>>> > # Go to the first item on the stack 250 | [<<+<+>>>-] # Pop out two copies 251 | > # Next item in Stack 252 | [<<<< <<<<+<+>>>> >>>> >-] # Pop out two copies 253 | > 254 | [[<<+>>-]>] # Shift stack 255 | +[-<+]- # Go to 255 256 | <<<< # Go to empty cell 257 | ++++++++++ ++++++++++ ++++++++++ ++++++++++ ++++++++++ ++++++++++ +++++ # A 258 | < 259 | jmp 260 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.+++.--------------------------------------------------------------------------------.[-] 261 | >>> # One of the stack copies 262 | [<<.>>-] # Print A that many times 263 | <<<< # One of the X copies 264 | [>>++++ ++++ ++++ ++++ ++++ +++.---- ---- ---- ---- ---- ---<<-] # Print X that many times 265 | 266 | ++++++++++.[-] # Newline 267 | >>+>>> # B; go to second copy 268 | [<<<.>>>-] # Print B that many times to create exit label 269 | <<< 270 | ++++ ++++ ++++ ++++ ++++ ++ # X 271 | <<< 272 | [->>>.<<<] # Print X 273 | 274 | >>> 275 | ---------- ---------- ----------. # Colon 276 | [-] 277 | ++++++++++. # Newline 278 | [-] 279 | <<<<<<<<[-] # Reset 280 | ] 281 | << # Return to {1} 282 | ############## END CLOSING BRACKET 283 | 284 | [-]> 285 | # INPUT AGAIN FOR NEXT LOOP 286 | , 287 | 288 | ] 289 | 290 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++++++++.------.--------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------.+++.----------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-----------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.---------.+++++.++++++.---------------------.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.-----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----.---------.+++++++++++.---------------.-------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.+++++++++++++++++.-----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------------.+++++++++++.++++++.-.----------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------.----.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------.-------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-----------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.+++++++++++++++.----------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.-----.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++.----------------..+++++++++++++++++++++++++++.---------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++.----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------------.+++++.+++++.----------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------.----.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------.-------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-----------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.+++++++++++++++. 291 | -------------------------------------------------------------------------------- /examples/game.bf: -------------------------------------------------------------------------------- 1 | :: TEXT : Intro :: 2 | >[-]+++++++[<++++++++++>-]<-.>++++++[<++++++>-]<.-----.+.>+++[<++++++>-]<+.>++++ 3 | ++++[<----------->-]<.>+++++++[<++++++++++++>-]<.------------.---.>+++++++[<---- 4 | ------>-]<+.>++++[<+++++++++++>-]<.>++++[<+++++++>-]<+.+++++++++++++++++.>+++++[ 5 | <----->-]<.+++++++++++++++++.--------------.>++++++[<----------->-]<--.>++++++++ 6 | [<+++++++++++>-]<-.>+++[<------->-]<-.>+++[<++++++>-]<.>+++++++[<------------>-] 7 | <+.>+++++++[<+++++++++++>-]<.----.+++++.----------.+++++.+++++.-------.>+++++++[ 8 | <---------->-]<-.>++++++++[<+++++++++>-]<.+.++++++++++.>+++++++[<------------>-] 9 | <+.>++++++++[<++++++++++>-]<-.++++++++.---------.>++++++[<------------->-]<.>+++ 10 | +++[<+++++++++++>-]<.>+++[<++++++>-]<+.--.----------.+++++.---------.+++++++++++ 11 | +++..>+++++++[<------------>-]<+.>++++++++[<+++++++++>-]<+.+++++.>++++++[<------ 12 | ------->-]<.>+++++[<++++++++++>-]<.>+++[<++++++>-]<+.+++++++++++.++++.---------- 13 | -.+++.-------.>+++++++[<---------->-]<+.>++++[<+++++++++++>-]<.>+++[<+++++++>-]< 14 | .+++++++++++++.----------.>+++++++[<-------->-]<.------------.>++++++[<+++++++++ 15 | ++>-]<+.--.+++++++++++++++++..+++++++.----------------.+++++.-------.>+++++++[<- 16 | --------->-]<-.>++++++++[<++++++++>-]<+.>++++++++[<-------->-]<-.>++++++++[<++++ 17 | ++++++>-]<.----.-----------.>+++[<++++++>-]<.+.-----------.------.>++++++[<----- 18 | ------>-]<-.>+++++++[<++++++++++++>-]<-.++++.--------.+++.--------------.>++++++ 19 | [<----------->-]<--.>++++++++[<++++++++>-]<+.+++++++++++++.----------.>++++++[<- 20 | ---------->-]<--.>+++++++[<++++++++++++>-]<.+++.--------.>++++++++[<---------->- 21 | ]<+.>+++++++[<++++++++++++>-]<-.------.------------.+++++++++++..>+++++++[<----- 22 | ------>-]<+.>++++++++[<+++++++++>-]<.---.----.+++++++++++.---.+++++.-------.>+++ 23 | ++++[<---------->-]<-.>++++++++[<++++++++++>-]<.-.+++++.-----------.++++++.-.+++ 24 | ++.>+++++++[<---------->-]<-.------------.>++++++++[<+++++++++++>-]<-.---------- 25 | -----.---.+++++++++.>++++++[<------------->-]<.>+++++++[<++++++++++++>-]<-.++.-- 26 | ---------------..+.+++++++++.--.+++++++++++++.>+++++++[<----------->-]<.-------- 27 | ----.>++++++++[<+++++++++>-]<.---.>+++++++[<---------->-]<+.>++++++++[<+++++++++ 28 | ++>-]<-.>+++[<------->-]<-.>+++[<++++++>-]<.>+++++++[<------------>-]<+.>+++++++ 29 | +[<++++++++>-]<+.>+++[<++++++>-]<+..>+++[<------>-]<-.++.++++++++.------.-.>++++ 30 | ++[<----------->-]<--.>++++++[<+++++++++++>-]<.>++++[<++++++>-]<-.>++++++++[<--- 31 | -------->-]<-.>++++[<+++++++++++++>-]<.>+++++[<+++++++>-]<.--------.>++++++++[<- 32 | --------->-]<+.>+++++[<++++++++++>-]<+.>+++++[<+++++>-]<.---.++++.--------.+++++ 33 | +++++++++.>+++++++++[<--------->-]<-.[-] 34 | 35 | :: GAME STARTS HERE 36 | <<->> >>>> ++++ ++++ >>> ++++ >>> ++++ >>> ++ > ++ < :: INIT VALUES 37 | << <<<< <<<< <<<< + :: GOES TO BEGINNING CELL 38 | [ 39 | <<<<<<<< 40 | :: TEXT : Eidex HP 41 | [-]>[-]< 42 | +++++++++++++..---.>++++++[<++++++++++>-]<-.>+++ 43 | +++[<++++++>-]<.-----.+.>+++[<++++++>-]<+.>++++++++[<----------->-]<.>+++++[<+++ 44 | +++++>-]<.++++++++.>+++[<------->-]<-.>+++++[<----->-]<-. 45 | 46 | 47 | >>>>>>>> 48 | 49 | >>>> >> ++++ ++++[< ++++ ++>-]<.> ++++ ++++ [<------>-] 50 | 51 | <<<<<<<< 52 | 53 | <<<<<<<<< 54 | :: TEXT : Slime A HP 55 | [-]>[-]<+++++++++++++.---.>++++ 56 | ++++[<+++++++++>-]<+.>+++++[<+++++>-]<.---.++++.--------.>+++++++[<---------->-] 57 | <+.>++++[<++++++++>-]<+.>++++[<-------->-]<-.>+++++[<++++++++>-]<.++++++++.>+++[ 58 | <------->-]<-.>+++++[<----->-]<-. 59 | 60 | >>>>>>>>> >>>>>>>>>>> 61 | ++++++++[<++++++>-]<.>++++++++[<------>- 62 | ]<<<<<<<< <<<<<<<<<<<<<<<<< 63 | 64 | :: TEXT : Slime B HP 65 | [-]>[-]<+++++++++++++.---.>++++++++[<++++ 66 | +++++>-]<+.>+++++[<+++++>-]<.---.++++.--------.>+++++++[<---------->-]<+.>++++[< 67 | ++++++++>-]<++.->++++[<-------->-]<-.>+++++[<++++++++>-]<.++++++++.>+++[<------- 68 | >-]<-.>+++++[<----->-]<-. 69 | 70 | >>>>>>>>> >>>>>>>>>>> >>>>>>>> 71 | ++++++++[<++++++>-]<.>++++++++[<------>-] 72 | <<<<<<<<< <<<<<<<<<<< <<<<< 73 | 74 | :: TEXT : POTIONS LEFT 75 | [-]>[-]<+++++++++++++.---.+++.---.>++++++ 76 | +[<++++++++++>-]<.-.+++++.-----------.++++++.-.+++++.>+++++[<---------->-]<-.>++ 77 | ++[<+++++++++++>-]<.-------.+.++++++++++++++.>+++++[<----->-]<-.>+++++[<----->-] 78 | <-. 79 | 80 | >>>>>>>>> >>>>>>>>> >>>>>>>>>>> 81 | ++++++++[<++++++>-]<.>++++++++[<------>-] 82 | <<<<<<<<<<<<<< 83 | 84 | 85 | <<<< <<<< 86 | 87 | :: TEXT : INSTRUCTIONS 88 | [-]>[-]<+++++++++++++..---.>+++++[<+++++++++++>-]<.++.+++++++++++++++++.-------- 89 | ---.++++++.-.+++++.>+++++[<----->-]<.>+++++[<--------->-]<.---.>++++++++[<+++++ 90 | ++++>-]<++.>+++[<+++++++++>-]<.>++++++++[<---------->-]<+.>++++++++[<++++++++>- 91 | ]<+.>+++[<++++++>-]<+..>+++[<------>-]<-.++.++++++++.>+++++[<--------------->-] 92 | <.>+++++[<++++++++++>-]<+.>+++++[<+++++>-]<.---.++++.--------.>+++++++[<------- 93 | --->-]<+.>++++[<++++++++>-]<+.>+++[<------->-]<.------------.>+++++++[<++++++++ 94 | ++++>-]<.+++++.---------.-----------.>+++++++[<---------->-]<+.+++++++.>+++++[< 95 | +++++>-]<+.>+++++[<----->-]<-.>+++++[<----->-]<-.---.>++++++++[<+++++++++>-]<++ 96 | .>+++[<+++++++++>-]<.>++++++++[<---------->-]<+.>++++++++[<++++++++>-]<+.>+++[< 97 | ++++++>-]<+..>+++[<------>-]<-.++.++++++++.>+++++[<--------------->-]<.>+++++[< 98 | ++++++++++>-]<+.>+++++[<+++++>-]<.---.++++.--------.>+++++++[<---------->-]<+.> 99 | +++++[<+++++++>-]<-.>+++[<------->-]<-.------------.>+++++++[<++++++++++++>-]<. 100 | +++++.---------.-----------.>+++++++[<---------->-]<+.+++++++.>+++[<+++++++++>- 101 | ]<.>+++[<--------->-]<.>+++++[<----->-]<-.---.>++++++++[<+++++++++>-]<++.>+++[< 102 | +++++++++>-]<.>++++++++[<---------->-]<+.>+++++++[<++++++++++++>-]<+.--.------- 103 | -------.>+++++++[<---------->-]<+.>++++++++[<++++++++>-]<+.>++++++++[<--------> 104 | -]<-.>++++++++[<++++++++++>-]<.-.+++++.-----------.++++++.-.>++++++[<---------- 105 | ->-]<.------------.>+++++++[<++++++++++++>-]<.+++++.---------.-----------.>++++ 106 | +++[<---------->-]<+.+++++++.>++++[<+++++++>-]<.>++++[<------->-]<.>+++++[<---- 107 | ->-]<-.---.+++.---.>++++++[<++++++++++>-]<-.>++++++[<++++++>-]<.-----.+.>+++[<+ 108 | +++++>-]<+.>+++++++++[<--------->-]<.>+++++++[<+++++++++++>-]<-.>+++++++[<----- 109 | ------->-]<+.>+++++[<+++++++++>-]<+.>++++[<++++++>-]<-.>+++[<++++++>-]<+.----.> 110 | +++++++[<------------>-]<.>++++[<++++++++>-]<+.>+++++[<+++++++>-]<-.+++++++++++ 111 | ++++++.-----------.++++++.-.>++++[<------------->-]<. 112 | 113 | >>>> >>>> 114 | 115 | <,> 116 | ++++++++[<-------->-] 117 | < 118 | -[-[->>>]>>>]>>>>>>> :: GO TO SELECTED SPOT 119 | >[ 120 | 121 | :: TEXT : Eidex uses Potion 122 | <<<< <<<< <<<< <<<< <<<< <<<< 123 | 124 | [-]>[-]<+++++++++++++.---.>++++++[<++++++++++>-]<-.>++++++[<++++++>-]<.-----.+. 125 | >+++[<++++++>-]<+.>++++++++[<----------->-]<.>+++++++[<++++++++++++>-]<+.--.--- 126 | -----------.++++++++++++++.>+++++++[<------------>-]<+.>++++++++[<++++++++>-]<+ 127 | .>++++++++[<-------->-]<-.>++++++[<++++++++>-]<.-.+++++.-----------.++++++.-.>+ 128 | ++++[<--------->-]<-.>++++++++[<++++++++>-]<+.+++++++++++++.----------.>++++++[ 129 | <----------->-]<--.>+++++++++[<+++++++++>-]<+.-------------.--.++++++++++++.+++ 130 | ++++.-----------------.+++++++++++++.+.>+++++++[<------------>-]<+.>+++[<++++++ 131 | >-]<+.->+++[<------>-]<.>+++++[<++++++++>-]<.++++++++.>++++++[<-------->-]<+.[-] 132 | 133 | >>>> >>>> >>>> >>>> >>>> >>>> 134 | 135 | -<-<<<<<<<<<+++< :: POTION 136 | 137 | ]< 138 | [ 139 | 140 | <<<< <<<< <<<< <<<< <<<< <<<< 141 | [-]>[-]<+++++++++++++.---.>++++++[<++++++++++>-]<-.>++++++[<++++++>-]<.-----.+. 142 | >+++[<++++++>-]<+.>++++++++[<----------->-]<.>++++++++[<++++++++>-]<+.>+++[<+++ 143 | +++>-]<+..>+++[<------>-]<-.++.++++++++.++++++++.>+++++++[<------------>-]<+.>+ 144 | ++++++[<++++++++++++>-]<.------------.---.>+++++++[<---------->-]<+.>+++++[<+++ 145 | +++++++>-]<+.-------.---.++++.--------.>++++++[<------>-]<-.>++++++++[<++++++++ 146 | +++>-]<-.--------------.+++++++++++.------------.>++++++++[<--------->-]<.>++++ 147 | ++++[<+++++++++>-]<.+.++++++++++.>+++++++[<------------>-]<+.>+++++[<++++++++++ 148 | >-]<+.++++.--------.+++.--------------.>++++++[<------>-]<.>+++++++[<++++++++++ 149 | >-]<.+++++++++.+++.>+++++++++[<--------->-]<-.+++++++++++++++++.--------------- 150 | --.>+++++[<++++++++>-]<.++++++++.>++++++[<-------->-]<.>++++++++[<++++++++++>-] 151 | <-.---------.>+++++++[<---------->-]<.>++++++[<+++++++++++>-]<++.---.++++++++++ 152 | ++.------------.++++++.--.>++++++[<----------->-]<--. 153 | >>>> >>>> >>>> >>>> >>>> >>>> 154 | 155 | -< 156 | 157 | ] :: REMOVE HP 158 | +[-<+]- :: BACK TO ANCHOR 159 | 160 | :: ENEMY 1 TURN 161 | >>>> >>>> > 162 | [ 163 | <<<< <<<< <<<< <<<< <<<< <<<< 164 | [-]>[-]<+++++++++++++.---.>++++++++[<+++++++++>-]<+.-------.---.++++.--------.> 165 | ++++++[<------>-]<-.>++++[<++++++++>-]<+.>++++[<-------->-]<-.>++++[<++++++++>- 166 | ]<+.>+++++[<++++++++++>-]<+..>+++[<------>-]<-.++.++++++++.++++++++.>+++++++[<- 167 | ----------->-]<+.>+++++++[<++++++++++>-]<.+++++++++.+++.>+++++++++[<--------->- 168 | ]<-.+++++++++++++++++.-----------------.>++++++[<+++++++++++>-]<++.---.++++++++ 169 | ++++.------------.++++++.--.>++++++[<----------->-]<--. 170 | >>>> >>>> >>>> >>>> >>>> >>>> 171 | <<<->> 172 | 173 | ] 174 | +[-<+]- 175 | 176 | :: ENEMY 2 TURN 177 | >>>> >>>> >>>> 178 | [ 179 | 180 | <<<< <<<< <<<< <<<< <<<< <<<< 181 | [-]>[-]<+++++++++++++.---.>++++++++[<+++++++++>-]<+.-------.---.++++.--------.> 182 | ++++++[<------>-]<-.>++++[<++++++++>-]<++.->++++[<-------->-]<-.>++++[<++++++++ 183 | >-]<+.>+++++[<++++++++++>-]<+..>+++[<------>-]<-.++.++++++++.++++++++.>+++++++[ 184 | <------------>-]<+.>+++++++[<++++++++++>-]<.+++++++++.+++.>+++++++++[<--------- 185 | >-]<-.+++++++++++++++++.-----------------.>++++++[<+++++++++++>-]<++.---.++++++ 186 | ++++++.------------.++++++.--.>++++++[<----------->-]<--. 187 | >>>> >>>> >>>> >>>> >>>> >>>> 188 | 189 | <<<<<<->>>>> 190 | 191 | ] 192 | +[-<+]- 193 | 194 | :: IS ENEMY 1 ALIVE 195 | >[-]>>>>>>>>[<<<<<<<<+>] 196 | +[-<+]- 197 | 198 | :: IS ENEMY 2 ALIVE 199 | >>>> >>>> >>>>[<<<<<<<<<<<+>] 200 | +[-<+]- 201 | 202 | :: IS PLAYER ALIVE 203 | >>>>>+>[<-<] 204 | <[<<<<[-]] 205 | 206 | +[-<+]- 207 | <,>> 208 | ] 209 | 210 | :: ENDING MESSAGES 211 | 212 | <<<< <<<< <<<< <<<< <<<< <<<< <<<< 213 | [-]>[-]< 214 | +++++++++++++. 215 | ---. 216 | >>>> >>>> >>>> >>>> >>>> >>>> >>>> 217 | >>>>> 218 | [[-]>[-]+++++++[<++++++++++>-]<-.>++++++[<++++++>-]<.-----.+.>+++[<++++++>-] 219 | <+.>++++++++[<----------->-]<.>+++++[<+++++++++++>-]<.>+++[<++++++>-]<.+++++.+++ 220 | ++.>+++++++++[<--------->-]<-.[-]] 221 | 222 | >>>[[-]>[-]+++++++[<++++++++++>-]<-.>++++++[<++++++>-]<.-----.+.>+++[<++++++>-]< 223 | +.>++++++++[<----------->-]<.>++++[<+++++++++++>-]<.>+++++[<+++++++>-]<.++++.--- 224 | -----------.++++++++++++++.[-]>>>>>>>>>>>>>>>>>>>>>>] 225 | 226 | >>>[[-]>[-]+++++++[<++++++++++>-]<-.>++++++[<++++++>-]<.-----.+.>+++[<++++++>-]< 227 | +.>++++++++[<----------->-]<.>++++[<+++++++++++>-]<.>+++++[<+++++++>-]<.++++.--- 228 | -----------.++++++++++++++.[-]] -------------------------------------------------------------------------------- /old/bfcomp_v0.bf: -------------------------------------------------------------------------------- 1 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.--.+++++++++++++++++.-----------.++++++.-.------------------------------------------------------------------------------.++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++..---------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.++++++++++++++.-----------------.------------------------------------------------------------------.++++++++++++++++++++.----.+++++++++.---.--------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.--.+++++++++++++++++.-----------.++++++.-.------------------------------------------------------------------------------.++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------.+++++++++++++++++++.----.----------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.+++.-------------.-.+++++++++++.----------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+.-------------------.+++++++++++++++++.++.----------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+.-------------------.+++++++++++++++++.++.----------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.--------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---.+++++++++++++++++++.-------------------.---------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------.+++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++++++.----.+++++++++.---.--------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------------.+++++++++++++.---.----------------.+++++++++++++.+++..+.------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.--------------.+++++.------------.-------------------------------------------------.------------.++++++++++++++++.--------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.-----------.-------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-----------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..+.--------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------------.+++++++++++++.---.----------------.+++++++++++++.+++..+.------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.--------------------------------------. 2 | [-] 3 | 4 | >, 5 | [ 6 | 7 | ############## BEGIN PLUS 8 | #### COPY #### 9 | [>+<-]> 10 | [<+<+>>-] 11 | + 12 | < 13 | << ++++ ++ [>> ---- --- << -] >> - # Subtracts 43 from {1} using an extra cell 14 | 15 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 16 | [>[-]<[-]] 17 | > 18 | [ # This happens when input == 43 19 | >>>>>> 20 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------..------------------------------------------------------------. 21 | [-] 22 | <<<<<< 23 | [-] 24 | ] 25 | << # Return to {1} 26 | ############## END PLUS 27 | 28 | # BETWEEN: MOVE ONE RIGHT 29 | [>+<-]> 30 | 31 | ############## BEGIN MINUS 32 | #### COPY #### 33 | [>+<-]> 34 | [<+<+>>-] 35 | + 36 | < 37 | << ++++ ++ [>> ---- --- << -] >> --- # Subtracts 45 from {1} using an extra cell 38 | 39 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 40 | [>[-]<[-]] 41 | > 42 | [ # This happens when input == 45 43 | >>>>>> 44 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.-------------------.------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------..------------------------------------------------------------. 45 | [-] 46 | <<<<<< 47 | [-] 48 | ] 49 | << # Return to {1} 50 | ############## END MINUS 51 | 52 | # BETWEEN: MOVE ONE RIGHT 53 | [>+<-]> 54 | 55 | ############## BEGIN LEFT 56 | #### COPY #### 57 | [>+<-]> 58 | [<+<+>>-] 59 | + 60 | < 61 | << ++++ ++ [>> ---- ---- -- << -] >> # Subtracts 60 from {1} using an extra cell 62 | 63 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 64 | [>[-]<[-]] 65 | > 66 | [ # This happens when input == 60 67 | >>>>>> 68 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.-------------------.------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------...------------------------------------------------------------. 69 | [-] 70 | <<<<<< 71 | [-] 72 | ] 73 | << # Return to {1} 74 | ############## END LEFT 75 | 76 | # BETWEEN: MOVE ONE RIGHT 77 | [>+<-]> 78 | 79 | ############## BEGIN RIGHT 80 | #### COPY #### 81 | [>+<-]> 82 | [<+<+>>-] 83 | + 84 | < 85 | << ++++ ++ [>> ---- ---- -- << -] >> -- # Subtracts 62 from {1} using an extra cell 86 | 87 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 88 | [>[-]<[-]] 89 | > 90 | [ # This happens when input == 62 91 | >>>>>> 92 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------...------------------------------------------------------------. 93 | [-] 94 | <<<<<< 95 | [-] 96 | ] 97 | << # Return to {1} 98 | ############## END RIGHT 99 | 100 | # BETWEEN: MOVE ONE RIGHT 101 | [>+<-]> 102 | 103 | ############## BEGIN DOT 104 | #### COPY #### 105 | [>+<-]> 106 | [<+<+>>-] 107 | + 108 | < 109 | << ++++ ++ [>> ---- --- << -] >> ---- # Subtracts 46 from {1} using an extra cell 110 | 111 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 112 | [>[-]<[-]] 113 | > 114 | [ # This happens when input == 46 115 | >>>>>> 116 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++++++++++..----------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.---------.+++++.++++++.---------------------.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------------------------------------------------------. 117 | [-] 118 | <<<<<< 119 | [-] 120 | ] 121 | << # Return to {1} 122 | ############## END DOT 123 | 124 | # BETWEEN: MOVE ONE RIGHT 125 | [>+<-]> 126 | 127 | ############## BEGIN COMMA 128 | #### COPY #### 129 | [>+<-]> 130 | [<+<+>>-] 131 | + 132 | < 133 | << ++++ ++ [>> ---- --- << -] >> -- # Subtracts 44 from {1} using an extra cell 134 | 135 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 136 | [>[-]<[-]] 137 | > 138 | [ # This happens when input == 44 139 | >>>>>> 140 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++++++++++..----------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.-----.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------------------------------------------------------. 141 | [-] 142 | <<<<<< 143 | [-] 144 | ] 145 | << # Return to {1} 146 | ############## END COMMA 147 | 148 | 149 | [-]> 150 | # INPUT AGAIN FOR NEXT LOOP 151 | , 152 | 153 | ] 154 | 155 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++++++++.------.--------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------.+++.----------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-----------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.---------.+++++.++++++.---------------------.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.-----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----.---------.+++++++++++.---------------.-------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.+++++++++++++++++.-----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------------.+++++++++++.++++++.-.----------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------.----.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------.-------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-----------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.+++++++++++++++.----------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.-----.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++.----------------..+++++++++++++++++++++++++++.---------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++.----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------------.+++++.+++++.----------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------.----.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------.-------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-----------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.+++++++++++++++. 156 | -------------------------------------------------------------------------------- /old/bfcomp_v1.bf: -------------------------------------------------------------------------------- 1 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.--.+++++++++++++++++.-----------.++++++.-.------------------------------------------------------------------------------.++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++..---------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.++++++++++++++.-----------------.------------------------------------------------------------------.++++++++++++++++++++.----.+++++++++.---.--------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.--.+++++++++++++++++.-----------.++++++.-.------------------------------------------------------------------------------.++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------.+++++++++++++++++++.----.----------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.+++.-------------.-.+++++++++++.----------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+.-------------------.+++++++++++++++++.++.----------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+.-------------------.+++++++++++++++++.++.----------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.--------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---.+++++++++++++++++++.-------------------.---------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------.+++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++++++.----.+++++++++.---.--------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------------.+++++++++++++.---.----------------.+++++++++++++.+++..+.------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.--------------.+++++.------------.-------------------------------------------------.------------.++++++++++++++++.--------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.-----------.-------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-----------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..+.--------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------------.+++++++++++++.---.----------------.+++++++++++++.+++..+.------------------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.--------------------------------------. 2 | [-] 3 | >>>>>> 4 | + # The label counter 5 | >>>- # Stack base of 255 6 | 7 | 8 | <<< 9 | <<<<<< 10 | >, 11 | [ 12 | 13 | ############## BEGIN PLUS 14 | #### COPY #### 15 | [>+<-]> 16 | [<+<+>>-] 17 | + 18 | < 19 | << ++++ ++ [>> ---- --- << -] >> - # Subtracts 43 from {1} using an extra cell 20 | 21 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 22 | [>[-]<[-]] 23 | > 24 | [ # This happens when input == 43 25 | >>> 26 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------..------------------------------------------------------------. 27 | [-] 28 | <<< 29 | [-] 30 | ] 31 | << # Return to {1} 32 | ############## END PLUS 33 | 34 | # BETWEEN: MOVE ONE RIGHT 35 | [>+<-]> 36 | 37 | ############## BEGIN MINUS 38 | #### COPY #### 39 | [>+<-]> 40 | [<+<+>>-] 41 | + 42 | < 43 | << ++++ ++ [>> ---- --- << -] >> --- # Subtracts 45 from {1} using an extra cell 44 | 45 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 46 | [>[-]<[-]] 47 | > 48 | [ # This happens when input == 45 49 | >>> 50 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.-------------------.------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------..------------------------------------------------------------. 51 | [-] 52 | <<< 53 | [-] 54 | ] 55 | << # Return to {1} 56 | ############## END MINUS 57 | 58 | # BETWEEN: MOVE ONE RIGHT 59 | [>+<-]> 60 | 61 | ############## BEGIN LEFT 62 | #### COPY #### 63 | [>+<-]> 64 | [<+<+>>-] 65 | + 66 | < 67 | << ++++ ++ [>> ---- ---- -- << -] >> # Subtracts 60 from {1} using an extra cell 68 | 69 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 70 | [>[-]<[-]] 71 | > 72 | [ # This happens when input == 60 73 | >>> 74 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.-------------------.------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------...------------------------------------------------------------. 75 | [-] 76 | <<< 77 | [-] 78 | ] 79 | << # Return to {1} 80 | ############## END LEFT 81 | 82 | # BETWEEN: MOVE ONE RIGHT 83 | [>+<-]> 84 | 85 | ############## BEGIN RIGHT 86 | #### COPY #### 87 | [>+<-]> 88 | [<+<+>>-] 89 | + 90 | < 91 | << ++++ ++ [>> ---- ---- -- << -] >> -- # Subtracts 62 from {1} using an extra cell 92 | 93 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 94 | [>[-]<[-]] 95 | > 96 | [ # This happens when input == 62 97 | >>> 98 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.------------.------------.++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------...------------------------------------------------------------. 99 | [-] 100 | <<< 101 | [-] 102 | ] 103 | << # Return to {1} 104 | ############## END RIGHT 105 | 106 | # BETWEEN: MOVE ONE RIGHT 107 | [>+<-]> 108 | 109 | ############## BEGIN DOT 110 | #### COPY #### 111 | [>+<-]> 112 | [<+<+>>-] 113 | + 114 | < 115 | << ++++ ++ [>> ---- --- << -] >> ---- # Subtracts 46 from {1} using an extra cell 116 | 117 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 118 | [>[-]<[-]] 119 | > 120 | [ # This happens when input == 46 121 | >>> 122 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++++++++++..----------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.---------.+++++.++++++.---------------------.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------------------------------------------------------. 123 | [-] 124 | <<< 125 | [-] 126 | ] 127 | << # Return to {1} 128 | ############## END DOT 129 | 130 | # BETWEEN: MOVE ONE RIGHT 131 | [>+<-]> 132 | 133 | ############## BEGIN COMMA 134 | #### COPY #### 135 | [>+<-]> 136 | [<+<+>>-] 137 | + 138 | < 139 | << ++++ ++ [>> ---- --- << -] >> -- # Subtracts 44 from {1} using an extra cell 140 | 141 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 142 | [>[-]<[-]] 143 | > 144 | [ # This happens when input == 44 145 | >>> 146 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++++++++++..----------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.-----.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------------------------------------------------------. 147 | [-] 148 | <<< 149 | [-] 150 | ] 151 | << # Return to {1} 152 | ############## END COMMA 153 | 154 | 155 | # BETWEEN: MOVE ONE RIGHT 156 | [>+<-]> 157 | 158 | ############## BEGIN OPEN BRACKET 159 | #### COPY #### 160 | [>+<-]> 161 | [<+<+>>-] 162 | + 163 | < 164 | << ++++ ++++ ++ [>> ---- ---- - << -] >> - # Subtracts 91 from {1} using an extra cell 165 | 166 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 167 | [>[-]<[-]] 168 | > 169 | [ # This happens when input == 91 170 | >>>> # Move to cell containing stack position 171 | [<+>-] # Move it a cell to the left 172 | < # Go to it 173 | [>+>+<<-] # Two copies 174 | >>>>+> # Go to start of the stack; temporarily make base of stack 0 175 | 176 | [>] # Proceed to end of stack 177 | < 178 | [[>+<-]<] # Shift everything in the stack one cell to the right 179 | - # Base of stack is 255 again 180 | << # Go to copy of counter 181 | [>+>>+<<<-] # Enqueue with a second copy 182 | ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ + # A 183 | > 184 | [-<.>] # Print A counter many times 185 | 186 | # The rest up to the end label 187 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++.+++.--------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++.-----.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-------------------------------------------------.------------.++++++++++++++++.--------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++.------------------------------------------------------------------------------------------. 188 | [-] 189 | << 190 | [<+>-] 191 | < 192 | [>+>>+<<<-] # Put the copy there again 193 | >>+> # Increment A to B for the end label 194 | [-<.>] # Print B counter many times 195 | <[-] # Reset B 196 | <+ # Increment label counter 197 | <<+++++ +++++.[-] #New Line 198 | << 199 | [-] 200 | ] 201 | << # Return to {1} 202 | ############## END OPEN BRACKET 203 | 204 | 205 | # BETWEEN: MOVE ONE RIGHT 206 | [>+<-]> 207 | 208 | ############## BEGIN CLOSING BRACKET 209 | #### COPY #### 210 | [>+<-]> 211 | [<+<+>>-] 212 | + 213 | < 214 | << ++++ ++++ ++ [>> ---- ---- - << -] >> --- # Subtracts 93 from {1} using an extra cell 215 | 216 | # If the input is NOT zero put a zero in {2} stopping the following block from occuring 217 | [>[-]<[-]] 218 | > 219 | [ # This happens when input == 93 220 | >>>>>>>> # Go to the first item on the stack 221 | [<<+<+>>>-] # Pop out two copies 222 | > # Next item in Stack 223 | [[<+>-]>] # Shift stack 224 | +[-<+]- # Go to 255 225 | <<<< # Go to empty cell 226 | ++++++++++ ++++++++++ ++++++++++ ++++++++++ ++++++++++ ++++++++++ +++++ # A 227 | < 228 | 229 | jmp 230 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.+++.--------------------------------------------------------------------------------.[-] 231 | >>> # One of the stack copies 232 | [<<.>>-] # Print A that many times 233 | ++++++++++.[-] # Newline 234 | <<+>>> # B; go to second copy 235 | [<<<.>>>-] # Print B that many times to create exit label 236 | <<< 237 | --------. # Colon 238 | [-] 239 | ++++++++++. # Newline 240 | [-] 241 | <<<[-] # Reset 242 | ] 243 | << # Return to {1} 244 | ############## END CLOSING BRACKET 245 | 246 | [-]> 247 | # INPUT AGAIN FOR NEXT LOOP 248 | , 249 | 250 | ] 251 | 252 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++++++++.------.--------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------.+++.----------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-----------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.---------.+++++.++++++.---------------------.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.-----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----.---------.+++++++++++.---------------.-------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.+++++++++++++++++.-----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------------.+++++++++++.++++++.-.----------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------.----.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------.-------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-----------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.+++++++++++++++.----------------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.-----.++++.+++++.-------.+++++++++++++++++.--------------------------------------------------------.------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++++++++++++.----------------------------------------------------------------------------.------------.++++++++++++++++.----------------..+++++++++++++++++++++++++++.---------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.----.+++.------------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.+++++.-------------------------------------------------------------.------------.++++++++++++++++.----------------..+++++++++++++++++++++++++++.---------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------------.+++++.+++++.----------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------.----.-----------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.----------.-------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++.---.+++++++++++++++++++.-------------------.-----------------------------------------------------------------.+++++++++++.-----------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------.+++++++++++++++++++++++++++++++++++++.-----------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.+++++++.--------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------.++++++++++++++++++++.----------------------------------------------------------------------------.------------.+++++++++++++++++.---------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.----------------.--.+++++++++++..--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------.+++++++++++++++. 253 | -------------------------------------------------------------------------------- /tools/bf.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | 3 | //Very basic brainfuck compiler written in C, for reference 4 | int main(int argc, char* argv[]) { 5 | int loop_stk[4096]; 6 | int loop_stk_ptr = 0; 7 | int loop_count = 0; 8 | 9 | if(argc != 3) { 10 | printf("Usage: bf [input (bf)] [output (asm)]\n"); 11 | return -1; 12 | } 13 | 14 | FILE* input = fopen(argv[1], "r"); 15 | FILE* output = fopen(argv[2], "w"); 16 | fprintf(output,"section .bss\n"); 17 | fprintf(output,"data resb 4096\n"); 18 | 19 | fprintf(output,"section .text\n"); 20 | fprintf(output,"global _start\n"); 21 | 22 | fprintf(output,"_start:\n"); 23 | 24 | // Zero the data 25 | fprintf(output,"mov r8, 0\n"); 26 | fprintf(output,"mov rdi, data\n"); 27 | fprintf(output,"mov rcx, 4096\n"); 28 | fprintf(output,"zero_loop:\n"); 29 | fprintf(output,"mov byte [rdi], 0\n"); 30 | fprintf(output,"inc rdi\n"); 31 | fprintf(output,"loop zero_loop\n"); 32 | fprintf(output,"mov r8, 0\n"); 33 | 34 | 35 | // Stuff 36 | 37 | char c; 38 | while ((c = fgetc(input)) != EOF) { 39 | switch(c){ 40 | case '>': 41 | fprintf(output, "add r8, 1\n"); 42 | fprintf(output, "and r8, 0xFFF\n"); 43 | break; 44 | 45 | case '<': 46 | fprintf(output, "sub r8, 1\n"); 47 | fprintf(output, "and r8, 0xFFF\n"); 48 | break; 49 | 50 | case '+': 51 | fprintf(output, "add byte [data + r8], 1\n"); 52 | fprintf(output, "and byte [data + r8], 0xFF\n"); 53 | break; 54 | 55 | case '-': 56 | fprintf(output, "sub byte [data + r8], 1\n"); 57 | fprintf(output, "and byte [data + r8], 0xFF\n"); 58 | break; 59 | 60 | case '.': 61 | fprintf(output, "call print_char\n"); 62 | break; 63 | 64 | case ',': 65 | fprintf(output, "call read_char\n"); 66 | break; 67 | 68 | case '[': 69 | fprintf(output, "start_%d:\n", loop_count); 70 | loop_stk[loop_stk_ptr] = loop_count; 71 | loop_stk_ptr += 1; 72 | fprintf(output, "cmp byte [data + r8], 0\n"); 73 | fprintf(output, "jz end_%d\n", loop_count); 74 | loop_count++; 75 | break; 76 | 77 | case ']': 78 | fprintf(output, "jmp start_%d\n", loop_stk[loop_stk_ptr - 1]); 79 | fprintf(output, "end_%d:\n", loop_stk[loop_stk_ptr - 1]); 80 | loop_stk_ptr -= 1; 81 | break; 82 | } 83 | } 84 | 85 | fprintf(output,"mov rax, 60\n"); 86 | fprintf(output,"xor rdi, rdi\n"); 87 | fprintf(output,"syscall\n"); 88 | 89 | 90 | 91 | // Print character 92 | fprintf(output,"print_char:\n"); 93 | fprintf(output,"mov rax, 1 ; write\n"); 94 | fprintf(output,"mov rdi, 1 ; stdout\n"); 95 | fprintf(output,"lea rsi, [data + r8]\n"); 96 | fprintf(output,"mov rdx, 1\n"); 97 | fprintf(output,"syscall\n"); 98 | fprintf(output,"ret\n"); 99 | 100 | // Read character 101 | fprintf(output,"read_char:\n"); 102 | fprintf(output,"mov rax, 0 ; read\n"); 103 | fprintf(output,"mov rdi, 0 ; stdin\n"); 104 | fprintf(output,"lea rsi, [data + r8]\n"); 105 | fprintf(output,"mov rdx, 1\n"); 106 | fprintf(output,"syscall\n"); 107 | fprintf(output,"ret\n"); 108 | return 0; 109 | } -------------------------------------------------------------------------------- /tools/bfstrip.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | 3 | //Strip non-bf commands from input 4 | int main(int argc, char* argv[]) { 5 | FILE* input = fopen("input.bf", "r"); 6 | FILE* output = fopen("output.bf", "w"); 7 | 8 | char c; 9 | while ((c = fgetc(input)) != EOF) { 10 | switch(c){ 11 | case '>': 12 | case '<': 13 | case '+': 14 | case '-': 15 | case '.': 16 | case ',': 17 | case '[': 18 | case ']': 19 | fprintf(output, "%c", c); 20 | break; 21 | } 22 | } 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /tools/str_to_bf.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "string.h" 3 | 4 | //Generate very inefficient in-place text 5 | int main(int argc, char* argv[]) { 6 | char result[99999] = ""; 7 | unsigned int current = 0; 8 | if (argc < 2) { 9 | printf("Usage: %s \n", argv[0]); 10 | return 1; 11 | } 12 | FILE* input = fopen(argv[1], "r"); 13 | 14 | char c; 15 | while ((c = fgetc(input)) != EOF) { 16 | while(current > c) { 17 | char temp[99999]; 18 | snprintf(temp, sizeof(temp), "%s-", result); 19 | strncpy(result, temp, sizeof(result)); 20 | current--; 21 | } 22 | while(current < c) { 23 | char temp[99999]; 24 | snprintf(temp, sizeof(temp), "%s+", result); 25 | strncpy(result, temp, sizeof(result)); 26 | current++; 27 | } 28 | char temp[99999]; 29 | snprintf(temp, sizeof(temp), "%s.", result); 30 | strncpy(result, temp, sizeof(result)); 31 | } 32 | 33 | printf("%s\n", result); 34 | } -------------------------------------------------------------------------------- /tools/test.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | 3 | //I forgot why I made this but it's in the repo anyway. 4 | int main() { 5 | char c = 'a'; 6 | 7 | printf("%c", c); 8 | return 0; 9 | } --------------------------------------------------------------------------------