diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-03-26 19:27:18 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-03-26 19:27:18 +0100 |
| commit | 7167b4341ef290d56fb96e2af10883a4b925d83b (patch) | |
| tree | 1eb1b9e5ab82ddd89540e68d6b22ae69514575c6 /pbfi/pbfi-1.1/src | |
| download | ancient-projects-master.tar.gz ancient-projects-master.zip | |
Diffstat (limited to 'pbfi/pbfi-1.1/src')
| -rwxr-xr-x | pbfi/pbfi-1.1/src/99BottlesOfBeer.bfk | 249 | ||||
| -rwxr-xr-x | pbfi/pbfi-1.1/src/Frame.java | 209 | ||||
| -rwxr-xr-x | pbfi/pbfi-1.1/src/HelloWorld.bfk | 20 | ||||
| -rwxr-xr-x | pbfi/pbfi-1.1/src/Main.java | 119 | ||||
| -rwxr-xr-x | pbfi/pbfi-1.1/src/Quine.bfk | 13 |
5 files changed, 610 insertions, 0 deletions
diff --git a/pbfi/pbfi-1.1/src/99BottlesOfBeer.bfk b/pbfi/pbfi-1.1/src/99BottlesOfBeer.bfk new file mode 100755 index 0000000..d9d65d9 --- /dev/null +++ b/pbfi/pbfi-1.1/src/99BottlesOfBeer.bfk | |||
| @@ -0,0 +1,249 @@ | |||
| 1 | Programma che stampa il testo completo della canzone 99 bottles of beer | ||
| 2 | |||
| 3 | ########################## | ||
| 4 | ### | ||
| 5 | ### Severely updated version! | ||
| 6 | ### (now says "1 bottle" and | ||
| 7 | ### contains no extra "0" verse) | ||
| 8 | ### | ||
| 9 | ########################## | ||
| 10 | ### 99 Bottles of Beer ### | ||
| 11 | ### coded in Brainfuck ### | ||
| 12 | ### with explanations ### | ||
| 13 | ########################## | ||
| 14 | # | ||
| 15 | # This Bottles of Beer program | ||
| 16 | # was written by Andrew Paczkowski | ||
| 17 | # Coder Alias: thepacz | ||
| 18 | # three_halves_plus_one at yahoo dot com | ||
| 19 | ##### | ||
| 20 | |||
| 21 | > 0 in the zeroth cell | ||
| 22 | +++++++>++++++++++[<+++++>-] 57 in the first cell or "9" | ||
| 23 | +++++++>++++++++++[<+++++>-] 57 in second cell or "9" | ||
| 24 | ++++++++++ 10 in third cell | ||
| 25 | >+++++++++ 9 in fourth cell | ||
| 26 | |||
| 27 | ########################################## | ||
| 28 | ### create ASCII chars in higher cells ### | ||
| 29 | ########################################## | ||
| 30 | |||
| 31 | >>++++++++[<++++>-] " " | ||
| 32 | >++++++++++++++[<+++++++>-] b | ||
| 33 | +>+++++++++++[<++++++++++>-] o | ||
| 34 | ++>+++++++++++++++++++[<++++++>-] t | ||
| 35 | ++>+++++++++++++++++++[<++++++>-] t | ||
| 36 | >++++++++++++[<+++++++++>-] l | ||
| 37 | +>++++++++++[<++++++++++>-] e | ||
| 38 | +>+++++++++++++++++++[<++++++>-] s | ||
| 39 | >++++++++[<++++>-] " " | ||
| 40 | +>+++++++++++[<++++++++++>-] o | ||
| 41 | ++>++++++++++[<++++++++++>-] f | ||
| 42 | >++++++++[<++++>-] " " | ||
| 43 | >++++++++++++++[<+++++++>-] b | ||
| 44 | +>++++++++++[<++++++++++>-] e | ||
| 45 | +>++++++++++[<++++++++++>-] e | ||
| 46 | >+++++++++++++++++++[<++++++>-] r | ||
| 47 | >++++++++[<++++>-] " " | ||
| 48 | +>+++++++++++[<++++++++++>-] o | ||
| 49 | >+++++++++++[<++++++++++>-] n | ||
| 50 | >++++++++[<++++>-] " " | ||
| 51 | ++>+++++++++++++++++++[<++++++>-] t | ||
| 52 | ++++>++++++++++[<++++++++++>-] h | ||
| 53 | +>++++++++++[<++++++++++>-] e | ||
| 54 | >++++++++[<++++>-] " " | ||
| 55 | ++>+++++++++++++[<+++++++++>-] w | ||
| 56 | +>++++++++++++[<++++++++>-] a | ||
| 57 | >++++++++++++[<+++++++++>-] l | ||
| 58 | >++++++++++++[<+++++++++>-] l | ||
| 59 | >+++++[<++>-] LF | ||
| 60 | ++>+++++++++++++++++++[<++++++>-] t | ||
| 61 | +>++++++++++++[<++++++++>-] a | ||
| 62 | +++>+++++++++++++[<++++++++>-] k | ||
| 63 | +>++++++++++[<++++++++++>-] e | ||
| 64 | >++++++++[<++++>-] " " | ||
| 65 | +>+++++++++++[<++++++++++>-] o | ||
| 66 | >+++++++++++[<++++++++++>-] n | ||
| 67 | +>++++++++++[<++++++++++>-] e | ||
| 68 | >++++++++[<++++>-] " " | ||
| 69 | >++++++++++[<++++++++++>-] d | ||
| 70 | +>+++++++++++[<++++++++++>-] o | ||
| 71 | ++>+++++++++++++[<+++++++++>-] w | ||
| 72 | >+++++++++++[<++++++++++>-] n | ||
| 73 | >++++++++[<++++>-] " " | ||
| 74 | +>++++++++++++[<++++++++>-] a | ||
| 75 | >+++++++++++[<++++++++++>-] n | ||
| 76 | >++++++++++[<++++++++++>-] d | ||
| 77 | >++++++++[<++++>-] " " | ||
| 78 | ++>+++++++++++[<++++++++++>-] p | ||
| 79 | +>++++++++++++[<++++++++>-] a | ||
| 80 | +>+++++++++++++++++++[<++++++>-] s | ||
| 81 | +>+++++++++++++++++++[<++++++>-] s | ||
| 82 | >++++++++[<++++>-] " " | ||
| 83 | +>+++++++++++++[<++++++++>-] i | ||
| 84 | ++>+++++++++++++++++++[<++++++>-] t | ||
| 85 | >++++++++[<++++>-] " " | ||
| 86 | +>++++++++++++[<++++++++>-] a | ||
| 87 | >+++++++++++++++++++[<++++++>-] r | ||
| 88 | +>+++++++++++[<++++++++++>-] o | ||
| 89 | >+++++++++++++[<+++++++++>-] u | ||
| 90 | >+++++++++++[<++++++++++>-] n | ||
| 91 | >++++++++++[<++++++++++>-] d | ||
| 92 | >+++++[<++>-] LF | ||
| 93 | +++++++++++++ CR | ||
| 94 | |||
| 95 | [<]>>>> go back to fourth cell | ||
| 96 | |||
| 97 | ################################# | ||
| 98 | ### initiate the display loop ### | ||
| 99 | ################################# | ||
| 100 | |||
| 101 | [ loop | ||
| 102 | < back to cell 3 | ||
| 103 | [ loop | ||
| 104 | [>]<< go to last cell and back to LF | ||
| 105 | .. output 2 newlines | ||
| 106 | [<]> go to first cell | ||
| 107 | |||
| 108 | ################################### | ||
| 109 | #### begin display of characters### | ||
| 110 | ################################### | ||
| 111 | # | ||
| 112 | #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 113 | #X X b o t t l e s o f b e e r | ||
| 114 | #.>.>.>.>.>.>.>.>.>.>.>. | ||
| 115 | #o n t h e w a l l N | ||
| 116 | #[<]> go to first cell | ||
| 117 | #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> | ||
| 118 | #X X b o t t l e s o f b e e r N | ||
| 119 | #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 120 | #t a k e o n e d o w n a n d p a s s | ||
| 121 | #.>.>.>.>.>.>.>.>.>. | ||
| 122 | #i t a r o u n d N | ||
| 123 | ##### | ||
| 124 | |||
| 125 | [<]>> go to cell 2 | ||
| 126 | - subtract 1 from cell 2 | ||
| 127 | < go to cell 1 | ||
| 128 | |||
| 129 | ######################## | ||
| 130 | ### display last line ## | ||
| 131 | ######################## | ||
| 132 | # | ||
| 133 | #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 134 | #X X b o t t l e s o f b e e r | ||
| 135 | #.>.>.>.>.>.>.>.>.>.>. | ||
| 136 | #o n t h e w a l l | ||
| 137 | ##### | ||
| 138 | |||
| 139 | [<]>>>- go to cell 3/subtract 1 | ||
| 140 | ] end loop when cell 3 is 0 | ||
| 141 | ++++++++++ add 10 to cell 3 | ||
| 142 | <++++++++++ back to cell 2/add 10 | ||
| 143 | <- back to cell 1/subtract 1 | ||
| 144 | [>]<. go to last line/carriage return | ||
| 145 | [<]> go to first line | ||
| 146 | |||
| 147 | ######################## | ||
| 148 | ### correct last line ## | ||
| 149 | ######################## | ||
| 150 | # | ||
| 151 | #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 152 | #X X b o t t l e s o f b e e r | ||
| 153 | #.>.>.>.>.>.>.>.>.>.>. | ||
| 154 | #o n t h e w a l l | ||
| 155 | ##### | ||
| 156 | |||
| 157 | [<]>>>>- go to cell 4/subtract 1 | ||
| 158 | ] end loop when cell 4 is 0 | ||
| 159 | |||
| 160 | ############################################################## | ||
| 161 | ### By this point verses 99\10 are displayed but to work ### | ||
| 162 | ### with the lower numbered verses in a more readable way ### | ||
| 163 | ### we initiate a new loop for verses 9{CODE} that will not ### | ||
| 164 | ### use the fourth cell at all ### | ||
| 165 | ############################################################## | ||
| 166 | |||
| 167 | + add 1 to cell four (to keep it non\zero) | ||
| 168 | <-- back to cell 3/subtract 2 | ||
| 169 | |||
| 170 | [ loop | ||
| 171 | [>]<< go to last cell and back to LF | ||
| 172 | .. output 2 newlines | ||
| 173 | [<]> go to first cell | ||
| 174 | |||
| 175 | ################################### | ||
| 176 | #### begin display of characters### | ||
| 177 | ################################### | ||
| 178 | # | ||
| 179 | #>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 180 | # X b o t t l e s o f b e e r | ||
| 181 | #.>.>.>.>.>.>.>.>.>.>.>. | ||
| 182 | #o n t h e w a l l N | ||
| 183 | #[<]> go to first cell | ||
| 184 | #>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> | ||
| 185 | # X b o t t l e s o f b e e r N | ||
| 186 | #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 187 | #t a k e o n e d o w n a n d p a s s | ||
| 188 | #.>.>.>.>.>.>.>.>.>. | ||
| 189 | #i t a r o u n d N | ||
| 190 | ##### | ||
| 191 | |||
| 192 | [<]>> go to cell 2 | ||
| 193 | - subtract 1 from cell 2 | ||
| 194 | |||
| 195 | ######################## | ||
| 196 | ### display last line ## | ||
| 197 | ######################## | ||
| 198 | # | ||
| 199 | #.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 200 | #X b o t t l e s o f b e e r | ||
| 201 | #.>.>.>.>.>.>.>.>.>.>. | ||
| 202 | #o n t h e w a l l | ||
| 203 | ##### | ||
| 204 | |||
| 205 | [<]>>>- go to cell 3/subtract 1 | ||
| 206 | ] end loop when cell 3 is 0 | ||
| 207 | + add 1 to cell 3 to keep it non\zero | ||
| 208 | |||
| 209 | [>]<. go to last line/carriage return | ||
| 210 | [<]> go to first line | ||
| 211 | |||
| 212 | ######################## | ||
| 213 | ### correct last line ## | ||
| 214 | ######################## | ||
| 215 | # | ||
| 216 | #>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.> | ||
| 217 | # X b o t t l e o f b e e r | ||
| 218 | #.>.>.>.>.>.>.>.>.>.>.<<<<. | ||
| 219 | #o n t h e w a l l | ||
| 220 | ##### | ||
| 221 | |||
| 222 | [>]<< go to last cell and back to LF | ||
| 223 | .. output 2 newlines | ||
| 224 | [<]> go to first line | ||
| 225 | |||
| 226 | ######################### | ||
| 227 | ### the final verse ## | ||
| 228 | ######################### | ||
| 229 | # | ||
| 230 | #>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.> | ||
| 231 | # X b o t t l e o f b e e r | ||
| 232 | #.>.>.>.>.>.>.>.>.>.>.>. | ||
| 233 | #o n t h e w a l l N | ||
| 234 | #[<]> go to first cell | ||
| 235 | #>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> | ||
| 236 | # X b o t t l e o f b e e r N | ||
| 237 | #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 238 | #t a k e o n e d o w n a n d p a s s | ||
| 239 | #.>.>.>.>.>.>.>.>.>. | ||
| 240 | #i t a r o u n d N | ||
| 241 | #[>]< go to last line | ||
| 242 | #<<<.<<.<<<. | ||
| 243 | # n o | ||
| 244 | #[<]>>>> go to fourth cell | ||
| 245 | #>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> | ||
| 246 | # b o t t l e s o f b e e r | ||
| 247 | #.>.>.>.>.>.>.>.>.>.>.>. | ||
| 248 | #o n t h e w a l l N | ||
| 249 | #####fin## \ No newline at end of file | ||
diff --git a/pbfi/pbfi-1.1/src/Frame.java b/pbfi/pbfi-1.1/src/Frame.java new file mode 100755 index 0000000..906a16b --- /dev/null +++ b/pbfi/pbfi-1.1/src/Frame.java | |||
| @@ -0,0 +1,209 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> | ||
| 3 | |||
| 4 | This file is part of PBFI (Porky's Brain F*** Interpreter). | ||
| 5 | |||
| 6 | PBFI is free software; you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 2 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | |||
| 11 | PBFI is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with PBFI; if not, write to the Free Software | ||
| 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | |||
| 20 | */ | ||
| 21 | |||
| 22 | import javax.swing.*; | ||
| 23 | import java.awt.BorderLayout; | ||
| 24 | import java.awt.event.*; | ||
| 25 | import java.io.*; | ||
| 26 | |||
| 27 | public class Frame extends JFrame { | ||
| 28 | public static int valoreChooser; | ||
| 29 | public static boolean firstSave; | ||
| 30 | public static String defaultSave; | ||
| 31 | public static Main main; | ||
| 32 | public static JTextArea textArea; | ||
| 33 | public static JButton runButton; | ||
| 34 | public static JMenuBar bar; | ||
| 35 | public static JMenu menuFile, menuAiuto; | ||
| 36 | public static JMenuItem esci, esegui, salva, salvaConNome, apri, info; | ||
| 37 | public static JFileChooser chooser; | ||
| 38 | public static FileInputStream in; | ||
| 39 | public static FileOutputStream out; | ||
| 40 | public Frame() { | ||
| 41 | super( "Porky's BrainF** Interpreter - v1.1" ); | ||
| 42 | firstSave = true; | ||
| 43 | main = new Main(); | ||
| 44 | defaultSave = ""; | ||
| 45 | chooser = new JFileChooser(); | ||
| 46 | textArea = new JTextArea( "Digitare qui il codice BrainF***", 15, 15 ); | ||
| 47 | bar = new JMenuBar(); | ||
| 48 | menuFile = new JMenu( "File" ); | ||
| 49 | menuAiuto = new JMenu( "?" ); | ||
| 50 | esci = new JMenuItem( "Esci" ); | ||
| 51 | esegui = new JMenuItem( "Esegui" ); | ||
| 52 | salva = new JMenuItem( "Salva" ); | ||
| 53 | salvaConNome = new JMenuItem( "Salva con nome" ); | ||
| 54 | apri = new JMenuItem( "Apri" ); | ||
| 55 | info = new JMenuItem( "Aiuto" ); | ||
| 56 | menuFile.setMnemonic( 'F' ); | ||
| 57 | menuAiuto.setMnemonic( '?' ); | ||
| 58 | esci.setMnemonic( 'E' ); | ||
| 59 | esegui.setMnemonic( 's' ); | ||
| 60 | salva.setMnemonic( 'a' ); | ||
| 61 | salvaConNome.setMnemonic( 'n' ); | ||
| 62 | apri.setMnemonic( 'p' ); | ||
| 63 | info.setMnemonic( 'i' ); | ||
| 64 | esci.addActionListener( | ||
| 65 | new ActionListener() { | ||
| 66 | public void actionPerformed ( ActionEvent e ) { | ||
| 67 | System.exit( 0 ); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | ); | ||
| 71 | esegui.addActionListener( | ||
| 72 | new ActionListener() { | ||
| 73 | public void actionPerformed ( ActionEvent e ) { | ||
| 74 | main.run( textArea.getText() ); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | ); | ||
| 78 | salva.addActionListener( | ||
| 79 | new ActionListener() { | ||
| 80 | public void actionPerformed ( ActionEvent e ) { | ||
| 81 | if ( firstSave ) { | ||
| 82 | valoreChooser = chooser.showSaveDialog( Frame.this ); | ||
| 83 | switch ( valoreChooser ) { | ||
| 84 | case JFileChooser.APPROVE_OPTION: | ||
| 85 | try { | ||
| 86 | out = new FileOutputStream( chooser.getSelectedFile().getPath() ); | ||
| 87 | defaultSave = chooser.getSelectedFile().getPath(); | ||
| 88 | char caratteri[]; | ||
| 89 | byte bytes[]; | ||
| 90 | caratteri = textArea.getText().toCharArray(); | ||
| 91 | bytes = new byte[caratteri.length]; | ||
| 92 | for ( int i = 0; i < caratteri.length; i++ ) | ||
| 93 | bytes[i] = ( byte ) caratteri[i]; | ||
| 94 | out.write( bytes ); | ||
| 95 | } catch ( Exception ex ) { | ||
| 96 | JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); | ||
| 97 | } | ||
| 98 | break; | ||
| 99 | case JFileChooser.ERROR_OPTION: | ||
| 100 | JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); | ||
| 101 | break; | ||
| 102 | //case JFileChooser.CANCEL_OPTION: | ||
| 103 | } | ||
| 104 | firstSave = false; | ||
| 105 | } else { | ||
| 106 | try { | ||
| 107 | out = new FileOutputStream( defaultSave ); | ||
| 108 | char caratteri[]; | ||
| 109 | byte bytes[]; | ||
| 110 | caratteri = textArea.getText().toCharArray(); | ||
| 111 | bytes = new byte[caratteri.length]; | ||
| 112 | for ( int i = 0; i < caratteri.length; i++ ) | ||
| 113 | bytes[i] = ( byte ) caratteri[i]; | ||
| 114 | out.write( bytes ); | ||
| 115 | } catch ( Exception ex ) { | ||
| 116 | JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | } | ||
| 120 | } | ||
| 121 | ); | ||
| 122 | salvaConNome.addActionListener( | ||
| 123 | new ActionListener() { | ||
| 124 | public void actionPerformed ( ActionEvent e ) { | ||
| 125 | valoreChooser = chooser.showSaveDialog( Frame.this ); | ||
| 126 | switch ( valoreChooser ) { | ||
| 127 | case JFileChooser.APPROVE_OPTION: | ||
| 128 | try { | ||
| 129 | out = new FileOutputStream( chooser.getSelectedFile().getPath() ); | ||
| 130 | defaultSave = chooser.getSelectedFile().getPath(); | ||
| 131 | char caratteri[]; | ||
| 132 | byte bytes[]; | ||
| 133 | caratteri = textArea.getText().toCharArray(); | ||
| 134 | bytes = new byte[caratteri.length]; | ||
| 135 | for ( int i = 0; i < caratteri.length; i++ ) | ||
| 136 | bytes[i] = ( byte ) caratteri[i]; | ||
| 137 | out.write( bytes ); | ||
| 138 | } catch ( Exception ex ) { | ||
| 139 | JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); | ||
| 140 | } | ||
| 141 | break; | ||
| 142 | case JFileChooser.ERROR_OPTION: | ||
| 143 | JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); | ||
| 144 | break; | ||
| 145 | //case JFileChooser.CANCEL_OPTION: | ||
| 146 | } | ||
| 147 | firstSave = false; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | ); | ||
| 151 | apri.addActionListener( | ||
| 152 | new ActionListener() { | ||
| 153 | public void actionPerformed ( ActionEvent e ) { | ||
| 154 | valoreChooser = chooser.showOpenDialog( Frame.this ); | ||
| 155 | switch ( valoreChooser ) { | ||
| 156 | case JFileChooser.APPROVE_OPTION: | ||
| 157 | try { | ||
| 158 | String stringa; | ||
| 159 | byte bytes[]; | ||
| 160 | char caratteri[]; | ||
| 161 | in = new FileInputStream( chooser.getSelectedFile().getPath() ); | ||
| 162 | bytes = new byte[in.available()]; | ||
| 163 | caratteri = new char[in.available()]; | ||
| 164 | in.read( bytes ); | ||
| 165 | for ( int i = 0; i < bytes.length; i++ ) | ||
| 166 | caratteri[i] = ( char ) bytes[i]; | ||
| 167 | stringa = new String( caratteri ); | ||
| 168 | textArea.setText( stringa ); | ||
| 169 | } catch ( Exception ex ) { | ||
| 170 | JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); | ||
| 171 | } | ||
| 172 | break; | ||
| 173 | case JFileChooser.ERROR_OPTION: | ||
| 174 | JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); | ||
| 175 | break; | ||
| 176 | //case JFileChooser.CANCEL_OPTION: | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | ); | ||
| 181 | info.addActionListener( | ||
| 182 | new ActionListener() { | ||
| 183 | public void actionPerformed ( ActionEvent e ) { | ||
| 184 | JOptionPane.showMessageDialog( Frame.this, "Brainfuck è un linguaggio di programmazione esoterico per computer,\ncreato da Urban Müller intorno al 1993. Il linguaggio viene\nin taluni casi denominato Brainf*ck, Brainf***\no anche soltanto BF per evitare di offendere\nla sensibilità altrui.\nNella cartella src trovate alcuni esempi di programmi in questo linguaggio.\n\nPer maggiori informazioni visitate la pagina:\nhttp://it.wikipedia.org/wiki/Brainfuck", "BrainF*** - Informazioni", JOptionPane.INFORMATION_MESSAGE ); | ||
| 185 | } | ||
| 186 | } | ||
| 187 | ); | ||
| 188 | menuFile.add( esegui ); | ||
| 189 | menuFile.add( salva ); | ||
| 190 | menuFile.add( salvaConNome ); | ||
| 191 | menuFile.add( apri ); | ||
| 192 | menuFile.add( esci ); | ||
| 193 | menuAiuto.add( info ); | ||
| 194 | bar.add( menuFile ); | ||
| 195 | bar.add( menuAiuto ); | ||
| 196 | runButton = new JButton( "Esegui" ); | ||
| 197 | runButton.addActionListener( | ||
| 198 | new ActionListener() { | ||
| 199 | public void actionPerformed( ActionEvent e ) { | ||
| 200 | main.run( textArea.getText() ); | ||
| 201 | } | ||
| 202 | } | ||
| 203 | ); | ||
| 204 | setLayout( new BorderLayout() ); | ||
| 205 | setJMenuBar( bar ); | ||
| 206 | add( new JScrollPane( textArea ), BorderLayout.CENTER ); | ||
| 207 | add( runButton, BorderLayout.SOUTH ); | ||
| 208 | } | ||
| 209 | } \ No newline at end of file | ||
diff --git a/pbfi/pbfi-1.1/src/HelloWorld.bfk b/pbfi/pbfi-1.1/src/HelloWorld.bfk new file mode 100755 index 0000000..74025e4 --- /dev/null +++ b/pbfi/pbfi-1.1/src/HelloWorld.bfk | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | Questo è un esempio Hello World in BrainFuck (fonte: wikipedia) | ||
| 2 | notare che tutti i caratteri diversi dagli 8 comandi sono considerati un commento | ||
| 3 | |||
| 4 | ++++++++++ | ||
| 5 | [ | ||
| 6 | >+++++++>++++++++++>+++>+<<<<- | ||
| 7 | ] | ||
| 8 | >++. Loop iniziale (dopo viene stampata una H) | ||
| 9 | >+. e | ||
| 10 | +++++++. l | ||
| 11 | . l | ||
| 12 | +++. o | ||
| 13 | >++. | ||
| 14 | <<+++++++++++++++. | ||
| 15 | >. | ||
| 16 | +++. | ||
| 17 | ------. | ||
| 18 | --------. | ||
| 19 | >+. | ||
| 20 | >. | ||
diff --git a/pbfi/pbfi-1.1/src/Main.java b/pbfi/pbfi-1.1/src/Main.java new file mode 100755 index 0000000..597ae2a --- /dev/null +++ b/pbfi/pbfi-1.1/src/Main.java | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org> | ||
| 3 | |||
| 4 | This file is part of PBFI (Porky's Brain F*** Interpreter). | ||
| 5 | |||
| 6 | PBFI is free software; you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 2 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | |||
| 11 | PBFI is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with PBFI; if not, write to the Free Software | ||
| 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | |||
| 20 | */ | ||
| 21 | |||
| 22 | import javax.swing.JFrame; | ||
| 23 | import java.util.Scanner; | ||
| 24 | public class Main { | ||
| 25 | public static Scanner scanner; | ||
| 26 | public static char totalCode[], charCodeAux[], charCode[], chars; | ||
| 27 | public static byte a[]; | ||
| 28 | public static int i; | ||
| 29 | public static void main( String args[] ) { | ||
| 30 | Frame frame = new Frame(); | ||
| 31 | frame.setSize( 200, 300 ); | ||
| 32 | frame.setVisible( true ); | ||
| 33 | frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); | ||
| 34 | } | ||
| 35 | public static void run( String code ) { | ||
| 36 | chars = 'a'; | ||
| 37 | int j = 0; | ||
| 38 | totalCode = code.toCharArray(); | ||
| 39 | charCodeAux = new char[totalCode.length*2]; | ||
| 40 | for ( int k = 0; k < totalCode.length; k++ ) { | ||
| 41 | switch ( totalCode[k] ) { | ||
| 42 | case '>': | ||
| 43 | case '<': | ||
| 44 | case '+': | ||
| 45 | case '-': | ||
| 46 | case '.': | ||
| 47 | case ',': | ||
| 48 | charCodeAux[j] = totalCode[k]; | ||
| 49 | j++; | ||
| 50 | break; | ||
| 51 | case '[': | ||
| 52 | charCodeAux[j] = totalCode[k]; | ||
| 53 | j++; | ||
| 54 | charCodeAux[j] = chars; | ||
| 55 | chars++; | ||
| 56 | j++; | ||
| 57 | break; | ||
| 58 | case ']': | ||
| 59 | chars--; | ||
| 60 | charCodeAux[j] = chars; | ||
| 61 | j++; | ||
| 62 | charCodeAux[j] = totalCode[k]; | ||
| 63 | j++; | ||
| 64 | break; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | charCode = new char[j]; | ||
| 68 | for ( int k = 0; k < charCode.length; k++ ) | ||
| 69 | charCode[k] = charCodeAux[k]; | ||
| 70 | scanner = new Scanner( System.in ); | ||
| 71 | a = new byte[30000]; | ||
| 72 | for ( int count = 0; count < a.length; count++ ) | ||
| 73 | a[count] = 0; | ||
| 74 | i = 0; | ||
| 75 | execute( scanner, charCode, a, i, 0, charCode.length ); | ||
| 76 | } | ||
| 77 | public static void execute( Scanner scanner, char charCode[], byte a[], int i, int start, int stop ) { | ||
| 78 | for ( int count = start; count < stop; count++ ) { | ||
| 79 | switch ( charCode[count] ) { | ||
| 80 | case '>': | ||
| 81 | i++; | ||
| 82 | break; | ||
| 83 | case '<': | ||
| 84 | i--; | ||
| 85 | break; | ||
| 86 | case '+': | ||
| 87 | a[i]++; | ||
| 88 | break; | ||
| 89 | case '-': | ||
| 90 | a[i]--; | ||
| 91 | break; | ||
| 92 | case '.': | ||
| 93 | System.out.print( (char) a[i] ); | ||
| 94 | break; | ||
| 95 | case ',': | ||
| 96 | String stringa = scanner.nextLine(); | ||
| 97 | a[i] = (byte) ( ( stringa.toCharArray() )[0] ); | ||
| 98 | break; | ||
| 99 | case '[': | ||
| 100 | if ( a[i] == 0 ) { | ||
| 101 | count++; | ||
| 102 | char key = charCode[count]; | ||
| 103 | count++; | ||
| 104 | for ( ; charCode[count] != key; count++ ) ; | ||
| 105 | count++; | ||
| 106 | } | ||
| 107 | break; | ||
| 108 | case ']': | ||
| 109 | if ( a[i] != 0 ) { | ||
| 110 | count --; | ||
| 111 | char key = charCode[count]; | ||
| 112 | count --; | ||
| 113 | for ( ; charCode[count] != key; count-- ) ; | ||
| 114 | } | ||
| 115 | break; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | } | ||
| 119 | } \ No newline at end of file | ||
diff --git a/pbfi/pbfi-1.1/src/Quine.bfk b/pbfi/pbfi-1.1/src/Quine.bfk new file mode 100755 index 0000000..8456a6b --- /dev/null +++ b/pbfi/pbfi-1.1/src/Quine.bfk | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | Questo programma è un esempio di quine (programma che mostra in output il suo codice sorgente) in BrainFuck (fonte: wikipedia) | ||
| 2 | |||
| 3 | ->+>+++>>+>++>+>+++>>+>++>>>+>+>+>++>+>>>>+++>+>>++>+>+++>>++>++>>+>>+>++>++> | ||
| 4 | +>>>>+++>+>>>>++>++>>>>+>>++>+>+++>>>++>>++++++>>+>>++>+>>>>+++>>+++++>>+>+++ | ||
| 5 | >>>++>>++>>+>>++>+>+++>>>++>>+++++++++++++>>+>>++>+>+++>+>+++>>>++>>++++>>+>> | ||
| 6 | ++>+>>>>+++>>+++++>>>>++>>>>+>+>++>>+++>+>>>>+++>+>>>>+++>+>>>>+++>>++>++>+>+ | ||
| 7 | ++>+>++>++>>>>>>++>+>+++>>>>>+++>>>++>+>+++>+>+>++>>>>>>++>>>+>>>++>+>>>>+++> | ||
| 8 | +>>>+>>++>+>++++++++++++++++++>>>>+>+>>>+>>++>+>+++>>>++>>++++++++>>+>>++>+>> | ||
| 9 | >>+++>>++++++>>>+>++>>+++>+>+>++>+>+++>>>>>+++>>>+>+>>++>+>+++>>>++>>++++++++ | ||
| 10 | >>+>>++>+>>>>+++>>++++>>+>+++>>>>>>++>+>+++>>+>++>>>>+>+>++>+>>>>+++>>+++>>>+ | ||
| 11 | [[->>+<<]<+]+++++[->+++++++++<]>.[+]>>[<<+++++++[->+++++++++<]>- | ||
| 12 | .------------------->-[-<.<+>>]<[+]<+>>>]<<<[-[-[-[>>+<++++++[->+++++<]]>++++ | ||
| 13 | ++++++++++<]>+++<]++++++[->+++++++<]>+<<<-[->>>++<<<]>[->>.<<]<<] | ||
