123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- [
- Written In Brainfuck (wib) v0.96
- Brainfuck to C translator by Mats Linander
- This program reads brainfuck sourcecode from stdin, translates it into c code
- and outputs it to stdout. Wib assumes that EOF == -1.
- Windows based c compilers may have problems compiling code generated by wib
- as it produces unix style newlines ('\n'==0x0a).
- Changelog
- v0.96: 2003-05-??
- * New itoa routine
- * Some tinkering to reduce size
- v0.95: 2003-05-03
- * Bugfix. Wib said "++*p" where it should have been "--*p".
- v0.94: 2003-04-22
- * Wib is now officially an optimizing translator, a series of n '+' now
- produces an output of *p+=n;\n. The same goes for '-'.
- v0.93: 2002-08-22
- * Removed all - that were immediately followed by + and vice versa.
- v0.92: 2002-08-21
- * Changed the output for dots, EOF should be EOF and nothing else.
- AFAIK this means wib follows the spec.
- * Made wib assume EOF==EOF&&EOF!='\0'
- * Put this stuff within brackets. Since *p is always zero at this point,
- the loop will never be entered and any chars can be used here.
- * Changed the GPL copyright statement to the ordinary one, including special
- chars.
- v0.91: 2002-05-23
- * Added the GPL license statement thingie
- v0.90: 2002-05-20
- * Wib now outputs 'if((*p=getchar())==EOF)*p=0;\n' when a dot is read
- Noticed that almost every other bf compiler does it so why not mine?
- v0.80: 2002-05-19
- * First working version
- Copyright (C) 2002, 2003, 2004 Mats Linander
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- ]
- +++++++[->>+++++<<]>>.<[-]<[-]+++++++[->+++++[->>+++<<]<]>>>.<<[-]<[-]>>>[-
- <<+>>>+>+>+>+>+>+<<<<<<]<<[->>+<<]>>>+++++.>------.>+++.>++++++++++++.>----
- -.>----.>>++++++++[-<++++>]<.>>++++++[->+++++[-<<++>>]<]<.<<[->>>+>+>+>+>+>
- +>+ <<<<<<<<<]>>>>> >>>[-<<<<<<<<+ >>>>>>>>]<<<<<+++
- +++++ ++++++.>+++++++++++ ++++. >-.>+++ +.>++++++++++.>>+
- ++>++ +++++++[-<<+++++>>] <<+. >.>>++ ++++[->+++++[-<<+
- +>>]< ]<++.>++++++++++.<< <<<< <<<<<< <<<<<<.>.>.>.>.>.
- >.>.> .>.>.>.>.>+++.>---- --.>> >>>[-]< [->+<]<[->+<]<[->
- +<]<[ ->+<]>>>>>+++++++[- >+++++++[-<<<<<<+ +>>>>>>]<]<<<<<.>
- .>.>. >.<<<<+.>>.<<--.<<< <<- .<<.>> >>>>>+.-------.>+
- ++++. ---....<++.>>>---.> .<<<< ++++++ .>>.<<--.<<<<<.<<
- .++++ ++++++.>>--.<+.>>>- -.>>> >>>.>. <<<<<.<++.<
- <.<<< ----------.>>>>>-.> >.<.< +.<<<< <++++++++.
- +.>>> >>>>>>>+++[->>++<<] >>-.< .<<<<< <++[- >>>>>>>>>
- >+>>> >+>+>+>+>+>+>+>+>>> +>>>> +>+>+> +>+>>> +<<<<<<<
- <<<<<< <<<<<<<<<<<<<<<<< <<<<<] <<<<[- >>>>>> >>>>>>>>
- >>+>>>> >>> >>> >>>>+<< <<<<<< <<<<<< <<<<<<<<
- <<<<<<<< ] > > >>>>>--- -[->>> >>+>+> >+>>>>>>
- >>>>>+>+>> +>> >>>>>>+>+> >+<<<< <<<<< <<<<<<<<
- <<<<<<<<<<<< <<<<] >>>[->>>>> >>+ >>>>>>>>>>
- >>>>+<<<<<<<<<<<<<<<<<<<<<]>[->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<
- <<<<<<<<<<<<<<<<<<<]>+>->>-->-->>+++++>++++>--------->----------->---------
- ---->-------->--------------->++>---->-->>--->-->>+++++++>-------->------->
- ---->----------->---->-->>--->>++<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[-]<[-]<[-]
- <[-]<[-],+[---------------------------------------------->[-]+<[>[-]<[->>+<
- <]]>[>>[-]>[-]<<<[>>+>[-]++++++++++[-<---------->]+<[>[-]<[-<<<+>>>]]<<<[->
- >>+<<<]>>>>[[-]<[-]>++++++++++[-<---------->]>>>>.<.<<.>>>>++.------------.
- -..+++++++++++.>.<<<<<<[-]]++++++++++[-<++++++++++>]<<,--------------------
- -------------------------<[-]+>[<[-]>[-<<+>>]]<<[->>+<<]>]>>>>>>>.<.<<.>>>>
- ++.-->>>>>>>>>>>>>>>>>>>>>>>>>>>[-]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[->>>>>
- >>>>>>>>>>>>>>>>>> >>>>>>>>>>+<<<
- <<<<<<<<<<<<<<<<< <<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>[->+<]
- >>>++++++++++[-< ++++++++++>]<<>>[-]>[-]>[-]>[-]>[-]>[- ]>[-]<<<<<<<<[
- ->>+>+<<<]>>>[- <<<+>>>]<<<>[->>+>+<<<]>>>[-<<<+>>>]< < <<>>>[>>[-]<<<
- [->>>+>>+<<<<< ] >>>>>[-<<<<<+>>>>>]<<<<[<->->>>+<<<< >> >>>>+<<<<<<[[-
- >>>>>+<<<<<]> >> >>>[-]<<<<<<]>>>>>[-<<<<<+>>>>>]<<< <<> >>>>>[[-]<<<<<
- [-]>>>>>]<<< <<] <[[->>>>>+<<<<<]>>+>>[-<<<+>>>]<<< <]>> >>>[-<<<<<+>>>
- >>]<<<<][-] <[-] >>[-<<+>>]>[-<<+>>]>[-]>[-]>[-]<< <<<<< <>[->>>+>+<<<<
- ]>>>>[-<<< <+>>> >]<<[->>+>+<<<]>>>[-<<<+>>>]<<[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<<<<<<<<[-]>[-]]>[- <<+>>]<<+ +>[-]+<[>[-]<[
- ->>+<< ]]>[>>[-] >[-]<<<[>>+>[-]++++++++++[-<- --------- >]+<[>[-]<[-<<
- <+>>>] ]<<<[->>> +<<<]>>>>[[-]<
- [-]>++ ++++++++ [-<---------->]>>>>.<.<.>>>++. -------- ----.-..+++++++
- ++++.> .<<<<<< [-]]++++++++++[-<++++++++++>]<< ,------ ----------------
- ------ ------ ---------<[-]+>[<[-]>[-<<+>>]]<< [->>+< <]>]>>>>>>>.<.<.>
- >>++.- ->>>> >>>>>>>>>>>>>>>>>>>>>>>[-]<<<<<<< <<<<< <<<<<<<<<<<<<<<<<<
- <<<[-> >>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<< <<<< <<<<<<<<<<<<<<<<<<<
- <<<<<] >>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[->+< ]>> >++++++++++[-<++++++
- ++++>] << >>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<< <[ ->>+>+<<<]>>>[-<<<+>>
- >]<<<> [ ->>+>+<<<]>>>[-<<<+>>>]<<<<>>>[>>[-]< < <[->>>+>>+<<<<<]>>>>>[
- -<<<<< +>>>>>]<<<<[<->->>>+<<<<>>>>>>+<<<<<<[ [->>>>>+<<<<<]>>>>>>[-]
- <<<<<< ]>>>>>[-<<<<<+>>>>>]<<<<<>>>>>>[[-]<<<< <[-]>>>>>]<<<<<]<[[->>>>
- >+<<<< <]>>+>>[-<<<+>>>]<<<<]>>>
- >>[-<<<<<+>>>>>]<<<<][-]<[-]>>[-<<+>>]>[-<<+>>]>[-]>[-]>[-]<<<<<<<<>[->>>+>
- +<<<<]>>>>[-<<<<+>>>>]<<[->>+>+<<<]>>>[-<<<+>>>]<<[->-<]>>[-]+<[>-<[-]]>[[-
- ]<<<[-]<+>>>>]<[-]<[-]<<<<>>>>[-]>[-]<<<<<[->>>>+>+<<<<<]>>>>>[-<<<<<+>>>>>
- ]<>[-]+<[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<<<[-]]>[-<<+>>]<<-->[-]+<[>-<[->>+<<]]>[>>>>>>.<..>>>.>.<<
- <<<<<<<[-]]>[-<<+>>]<<----------------------------->[-]+<[>-<[->>+<<]]>[>>>
- >>>>>>>>>>>>>>>>>>>>>.>.>.>.>.>.>.>.>.>.<<<<<<<<<<.<<<<<<<<<<<<<<<<<<<<<<<[
- -]]>[-<<+>>]<<-->[-]+<[>-<[->>+<<]]>[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.<<<
- <<<<<<<<.<<<<<<<<<<<<<<<<<<<<<<<[-]]>[-<<+>>]<<++++++++++++++++++++++++++++
- +++++++++++++++++++++>[-]+<[>-<[->>+<<]]>[>>>>>>>.<.>>++.-->>>>.>.<<.>>>.>.
- >.>.>.>>>.>.>.<<<<<<<<<<<<<<<<<<<<<<<[-]]>[-<<+>>]<<-->[-]+<[>-<[->>+<<]]>[
- >>>>>>.>>>>.>.>>>.>.>.>.>.>.>.>.>.>.<<<<<<<<<<<<<<<<<<<<<<<[-]]>[-<<+>>]<<+
- ++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<+<[>[-]>,+<<[-]][-]>
- [>[-]<[-]]>[-<<+>>]<<]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.<<<<<<<<<<<.
|