996
|
1 #!@prefix@/bin/egobfi8
|
|
2 [
|
|
3 Written In Brainfuck (wib) v0.96
|
|
4 Brainfuck to C translator by Mats Linander
|
|
5
|
|
6 This program reads brainfuck sourcecode from stdin, translates it into c code
|
|
7 and outputs it to stdout. Wib assumes that EOF == -1.
|
|
8
|
|
9 Windows based c compilers may have problems compiling code generated by wib
|
|
10 as it produces unix style newlines ('\n'==0x0a).
|
|
11
|
|
12
|
|
13 Changelog
|
|
14
|
|
15 v0.96: 2003-05-??
|
|
16 * New itoa routine
|
|
17 * Some tinkering to reduce size
|
|
18 v0.95: 2003-05-03
|
|
19 * Bugfix. Wib said "++*p" where it should have been "--*p".
|
|
20 v0.94: 2003-04-22
|
|
21 * Wib is now officially an optimizing translator, a series of n '+' now
|
|
22 produces an output of *p+=n;\n. The same goes for '-'.
|
|
23 v0.93: 2002-08-22
|
|
24 * Removed all - that were immediately followed by + and vice versa.
|
|
25 v0.92: 2002-08-21
|
|
26 * Changed the output for dots, EOF should be EOF and nothing else.
|
|
27 AFAIK this means wib follows the spec.
|
|
28 * Made wib assume EOF==EOF&&EOF!='\0'
|
|
29 * Put this stuff within brackets. Since *p is always zero at this point,
|
|
30 the loop will never be entered and any chars can be used here.
|
|
31 * Changed the GPL copyright statement to the ordinary one, including special
|
|
32 chars.
|
|
33 v0.91: 2002-05-23
|
|
34 * Added the GPL license statement thingie
|
|
35 v0.90: 2002-05-20
|
|
36 * Wib now outputs 'if((*p=getchar())==EOF)*p=0;\n' when a dot is read
|
|
37 Noticed that almost every other bf compiler does it so why not mine?
|
|
38 v0.80: 2002-05-19
|
|
39 * First working version
|
|
40
|
|
41
|
|
42 Copyright (C) 2002, 2003, 2004 Mats Linander
|
|
43
|
|
44 This program is free software; you can redistribute it and/or modify
|
|
45 it under the terms of the GNU General Public License as published by
|
|
46 the Free Software Foundation; either version 2 of the License, or
|
|
47 (at your option) any later version.
|
|
48
|
|
49 This program is distributed in the hope that it will be useful,
|
|
50 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
51 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
52 GNU General Public License for more details.
|
|
53
|
|
54 You should have received a copy of the GNU General Public License
|
|
55 along with this program; if not, write to the Free Software
|
|
56 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
57
|
|
58 ]
|
|
59
|
|
60
|
|
61
|
|
62
|
|
63
|
|
64 +++++++[->>+++++<<]>>.<[-]<[-]+++++++[->+++++[->>+++<<]<]>>>.<<[-]<[-]>>>[-
|
|
65 <<+>>>+>+>+>+>+>+<<<<<<]<<[->>+<<]>>>+++++.>------.>+++.>++++++++++++.>----
|
|
66 -.>----.>>++++++++[-<++++>]<.>>++++++[->+++++[-<<++>>]<]<.<<[->>>+>+>+>+>+>
|
|
67 +>+ <<<<<<<<<]>>>>> >>>[-<<<<<<<<+ >>>>>>>>]<<<<<+++
|
|
68 +++++ ++++++.>+++++++++++ ++++. >-.>+++ +.>++++++++++.>>+
|
|
69 ++>++ +++++++[-<<+++++>>] <<+. >.>>++ ++++[->+++++[-<<+
|
|
70 +>>]< ]<++.>++++++++++.<< <<<< <<<<<< <<<<<<.>.>.>.>.>.
|
|
71 >.>.> .>.>.>.>.>+++.>---- --.>> >>>[-]< [->+<]<[->+<]<[->
|
|
72 +<]<[ ->+<]>>>>>+++++++[- >+++++++[-<<<<<<+ +>>>>>>]<]<<<<<.>
|
|
73 .>.>. >.<<<<+.>>.<<--.<<< <<- .<<.>> >>>>>+.-------.>+
|
|
74 ++++. ---....<++.>>>---.> .<<<< ++++++ .>>.<<--.<<<<<.<<
|
|
75 .++++ ++++++.>>--.<+.>>>- -.>>> >>>.>. <<<<<.<++.<
|
|
76 <.<<< ----------.>>>>>-.> >.<.< +.<<<< <++++++++.
|
|
77 +.>>> >>>>>>>+++[->>++<<] >>-.< .<<<<< <++[- >>>>>>>>>
|
|
78 >+>>> >+>+>+>+>+>+>+>+>>> +>>>> +>+>+> +>+>>> +<<<<<<<
|
|
79 <<<<<< <<<<<<<<<<<<<<<<< <<<<<] <<<<[- >>>>>> >>>>>>>>
|
|
80 >>+>>>> >>> >>> >>>>+<< <<<<<< <<<<<< <<<<<<<<
|
|
81 <<<<<<<< ] > > >>>>>--- -[->>> >>+>+> >+>>>>>>
|
|
82 >>>>>+>+>> +>> >>>>>>+>+> >+<<<< <<<<< <<<<<<<<
|
|
83 <<<<<<<<<<<< <<<<] >>>[->>>>> >>+ >>>>>>>>>>
|
|
84 >>>>+<<<<<<<<<<<<<<<<<<<<<]>[->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<
|
|
85 <<<<<<<<<<<<<<<<<<<]>+>->>-->-->>+++++>++++>--------->----------->---------
|
|
86 ---->-------->--------------->++>---->-->>--->-->>+++++++>-------->------->
|
|
87 ---->----------->---->-->>--->>++<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[-]<[-]<[-]
|
|
88 <[-]<[-],+[---------------------------------------------->[-]+<[>[-]<[->>+<
|
|
89 <]]>[>>[-]>[-]<<<[>>+>[-]++++++++++[-<---------->]+<[>[-]<[-<<<+>>>]]<<<[->
|
|
90 >>+<<<]>>>>[[-]<[-]>++++++++++[-<---------->]>>>>.<.<<.>>>>++.------------.
|
|
91 -..+++++++++++.>.<<<<<<[-]]++++++++++[-<++++++++++>]<<,--------------------
|
|
92 -------------------------<[-]+>[<[-]>[-<<+>>]]<<[->>+<<]>]>>>>>>>.<.<<.>>>>
|
|
93 ++.-->>>>>>>>>>>>>>>>>>>>>>>>>>>[-]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<[->>>>>
|
|
94 >>>>>>>>>>>>>>>>>> >>>>>>>>>>+<<<
|
|
95 <<<<<<<<<<<<<<<<< <<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>[->+<]
|
|
96 >>>++++++++++[-< ++++++++++>]<<>>[-]>[-]>[-]>[-]>[-]>[- ]>[-]<<<<<<<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>[-<<+>>]>[-<<+ >>]>[-]>[ -]>[-]<<<<<<<<
|
|
112 >[->>> +>+<<<<]> >>>[-<<<<+>>>>]<<[->>+>+<<<]> >>[-<<<+> >>]<<[->-<]>>[
|
|
113 -]+<[> -<[-]]>[[ -]<<<[-]<+>>>>]<[-]<[-]<<<<>> >>[-]>[-] <<<<<[->>>>+>+
|
|
114 <<<<<] >>>>>[-<< <<<+>>>>>]<>[-]+<[>[-]<[-]]>[ <<[-]<[-] <[->>+>+<<<]>>
|
|
115 >[-<<< +>>>]>[-] ]<<<<<>[-]+>[<[-]<[-]>>>[-<<< +>>>]++++ ++++[-<++++++>
|
|
116 ]<.[-] ]<[<<[[-] >>[-]++++++++[-<<++++++>>]<<. [-]]>>[-] ][-]++++++++[-
|
|
117 <+++++ +>]<.<[-] >[-]>[-]>[-]>[-]>[-]>[-]>[-]> [-]>[-]<< <<<<<<<<<<<<<<
|
|
118 <<<<<< <<<<<<<<< <<<<<.>.<<<<<<<<<<[-]>[-]]>[- <<+>>]<<+ +>[-]+<[>[-]<[
|
|
119 ->>+<< ]]>[>>[-] >[-]<<<[>>+>[-]++++++++++[-<- --------- >]+<[>[-]<[-<<
|
|
120 <+>>>] ]<<<[->>> +<<<]>>>>[[-]<
|
|
121 [-]>++ ++++++++ [-<---------->]>>>>.<.<.>>>++. -------- ----.-..+++++++
|
|
122 ++++.> .<<<<<< [-]]++++++++++[-<++++++++++>]<< ,------ ----------------
|
|
123 ------ ------ ---------<[-]+>[<[-]>[-<<+>>]]<< [->>+< <]>]>>>>>>>.<.<.>
|
|
124 >>++.- ->>>> >>>>>>>>>>>>>>>>>>>>>>>[-]<<<<<<< <<<<< <<<<<<<<<<<<<<<<<<
|
|
125 <<<[-> >>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<< <<<< <<<<<<<<<<<<<<<<<<<
|
|
126 <<<<<] >>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[->+< ]>> >++++++++++[-<++++++
|
|
127 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>>>>]<<<<][-]<[-]>
|
|
141 >[-<<+>>]>[-<<+>>]>[-]>[-]>[-]<<<<<<<<>[->>>+>+<<<<]>>>>[-<<<<+>>>>]<<[->>+
|
|
142 >+<<<]>>>[-<<<+>>>]<<[->-<]>>[-]+<[>-<[-]]>[[-]<<<[-]<+>>>>]<[-]<[-]<<<<>>>
|
|
143 >[-]>[-]<<<<<[->>>>+>+<<<<<]>>>>>[-<<<<<+>>>>>]<>[-]+<[>[-]<[-]]>[<<[-]<[-]
|
|
144 <[->>+>+<<<]>>>[-<<<+>>>]>[-]]<<<<<>[-]+>[<[-]<[-]>>>[-<<<+>>>]++++++++[-<+
|
|
145 +++++>]<.[-]]<[<<[[-]>>[-]++++++++[-<<++++++>>]<<.[-]]>>[-]][-]++++++++[-<+
|
|
146 +++++>]<.<[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
147 <<<<<<<<<<.>.<<<<<<<<<<[-]>[-]]>[-<<+>>]<<-->[-]+<[>-<[->>+<<]]>[>>>>..>>>.
|
|
148 <.>>.>.<<<<<<<<<[-]]>[-<<+>>]<<--------------->[-]+<[>-<[->>+<<]]>[>>>>>>.<
|
|
149 <..>>>>.>.<<<<<<<<<[-]]>[-<<+>>]<<-->[-]+<[>-<[->>+<<]]>[>>>>>>.<..>>>.>.<<
|
|
150 <<<<<<<[-]]>[-<<+>>]<<----------------------------->[-]+<[>-<[->>+<<]]>[>>>
|
|
151 >>>>>>>>>>>>>>>>>>>>>.>.>.>.>.>.>.>.>.>.<<<<<<<<<<.<<<<<<<<<<<<<<<<<<<<<<<[
|
|
152 -]]>[-<<+>>]<<-->[-]+<[>-<[->>+<<]]>[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.<<<
|
|
153 <<<<<<<<.<<<<<<<<<<<<<<<<<<<<<<<[-]]>[-<<+>>]<<++++++++++++++++++++++++++++
|
|
154 +++++++++++++++++++++>[-]+<[>-<[->>+<<]]>[>>>>>>>.<.>>++.-->>>>.>.<<.>>>.>.
|
|
155 >.>.>.>>>.>.>.<<<<<<<<<<<<<<<<<<<<<<<[-]]>[-<<+>>]<<-->[-]+<[>-<[->>+<<]]>[
|
|
156 >>>>>>.>>>>.>.>>>.>.>.>.>.>.>.>.>.>.<<<<<<<<<<<<<<<<<<<<<<<[-]]>[-<<+>>]<<+
|
|
157 ++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<+<[>[-]>,+<<[-]][-]>
|
|
158 [>[-]<[-]]>[-<<+>>]<<]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.<<<<<<<<<<<.
|