From 7167b4341ef290d56fb96e2af10883a4b925d83b Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 26 Mar 2026 19:27:18 +0100 Subject: I found my old code! --- pbfi/PBFI.jar | Bin 0 -> 9636 bytes pbfi/pbfi-1.0/src/Frame.java | 49 +++++++ pbfi/pbfi-1.0/src/Main.java | 119 ++++++++++++++++ pbfi/pbfi-1.1/src/99BottlesOfBeer.bfk | 249 ++++++++++++++++++++++++++++++++++ pbfi/pbfi-1.1/src/Frame.java | 209 ++++++++++++++++++++++++++++ pbfi/pbfi-1.1/src/HelloWorld.bfk | 20 +++ pbfi/pbfi-1.1/src/Main.java | 119 ++++++++++++++++ pbfi/pbfi-1.1/src/Quine.bfk | 13 ++ 8 files changed, 778 insertions(+) create mode 100755 pbfi/PBFI.jar create mode 100755 pbfi/pbfi-1.0/src/Frame.java create mode 100755 pbfi/pbfi-1.0/src/Main.java create mode 100755 pbfi/pbfi-1.1/src/99BottlesOfBeer.bfk create mode 100755 pbfi/pbfi-1.1/src/Frame.java create mode 100755 pbfi/pbfi-1.1/src/HelloWorld.bfk create mode 100755 pbfi/pbfi-1.1/src/Main.java create mode 100755 pbfi/pbfi-1.1/src/Quine.bfk (limited to 'pbfi') diff --git a/pbfi/PBFI.jar b/pbfi/PBFI.jar new file mode 100755 index 0000000..2af11ff Binary files /dev/null and b/pbfi/PBFI.jar differ diff --git a/pbfi/pbfi-1.0/src/Frame.java b/pbfi/pbfi-1.0/src/Frame.java new file mode 100755 index 0000000..30f7f3c --- /dev/null +++ b/pbfi/pbfi-1.0/src/Frame.java @@ -0,0 +1,49 @@ +/* +Copyright 2009 Sebastiano Tronto + +This file is part of PBFI (Porky's Brain F*** Interpreter). + + PBFI 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. + + PBFI 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 PBFI; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.JTextArea; +import javax.swing.JScrollPane; +import java.awt.BorderLayout; +import java.awt.event.*; + +public class Frame extends JFrame { + public static Main main; + public static JTextArea textArea; + public static JButton runButton; + public Frame() { + super( "Porky's Brain F*** Interpreter - v1.0" ); + main = new Main(); + textArea = new JTextArea( "Brain F*** source code here", 15, 15 ); + runButton = new JButton( "Run" ); + runButton.addActionListener( + new ActionListener() { + public void actionPerformed( ActionEvent e ) { + main.run( textArea.getText() ); + } + } + ); + setLayout( new BorderLayout() ); + add( new JScrollPane( textArea ), BorderLayout.CENTER ); + add( runButton, BorderLayout.SOUTH ); + } +} \ No newline at end of file diff --git a/pbfi/pbfi-1.0/src/Main.java b/pbfi/pbfi-1.0/src/Main.java new file mode 100755 index 0000000..c7fe81d --- /dev/null +++ b/pbfi/pbfi-1.0/src/Main.java @@ -0,0 +1,119 @@ +/* +Copyright 2009 Sebastiano Tronto + +This file is part of PBFI (Porky's Brain F*** Interpreter). + + PBFI 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. + + PBFI 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 PBFI; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; +import java.util.Scanner; +public class Main { + public static Scanner scanner; + public static char totalCode[], charCodeAux[], charCode[], chars; + public static byte a[]; + public static int i; + public static void main( String args[] ) { + Frame frame = new Frame(); + frame.setSize( 200, 300 ); + frame.setVisible( true ); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + } + public static void run( String code ) { + chars = 'a'; + int j = 0; + totalCode = code.toCharArray(); + charCodeAux = new char[totalCode.length*2]; + for ( int k = 0; k < totalCode.length; k++ ) { + switch ( totalCode[k] ) { + case '>': + case '<': + case '+': + case '-': + case '.': + case ',': + charCodeAux[j] = totalCode[k]; + j++; + break; + case '[': + charCodeAux[j] = totalCode[k]; + j++; + charCodeAux[j] = chars; + j++; + chars++; + break; + case ']': + chars--; + charCodeAux[j] = chars; + j++; + charCodeAux[j] = totalCode[k]; + j++; + break; + } + } + charCode = new char[j]; + for ( int k = 0; k < charCode.length; k++ ) + charCode[k] = charCodeAux[k]; + scanner = new Scanner( System.in ); + a = new byte[30000]; + for ( int count = 0; count < a.length; count++ ) + a[count] = 0; + i = 0; + execute( scanner, charCode, a, i, 0, charCode.length ); + } + public static void execute( Scanner scanner, char charCode[], byte a[], int i, int start, int stop ) { + for (int count = start; count < stop; count++ ) { + switch ( charCode[count] ) { + case '>': + i++; + break; + case '<': + i--; + break; + case '+': + a[i]++; + break; + case '-': + a[i]--; + break; + case '.': + System.out.print( (char) a[i] ); + break; + case ',': + String stringa = scanner.nextLine(); + a[i] = (byte) ( ( stringa.toCharArray() )[0] ); + break; + case '[': + if ( a[i] == 0 ) { + count++; + char key = charCode[count]; + count++; + for ( ; charCode[count] != key; count++ ) ; + count++; + } + break; + case ']': + if ( a[i] != 0 ) { + count --; + char key = charCode[count]; + count --; + for ( ; charCode[count] != key; count-- ) ; + } + break; + } + } + } +} \ No newline at end of file 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 @@ +Programma che stampa il testo completo della canzone 99 bottles of beer + +########################## +### +### Severely updated version! +### (now says "1 bottle" and +### contains no extra "0" verse) +### +########################## +### 99 Bottles of Beer ### +### coded in Brainfuck ### +### with explanations ### +########################## +# +# This Bottles of Beer program +# was written by Andrew Paczkowski +# Coder Alias: thepacz +# three_halves_plus_one at yahoo dot com +##### + +> 0 in the zeroth cell ++++++++>++++++++++[<+++++>-] 57 in the first cell or "9" ++++++++>++++++++++[<+++++>-] 57 in second cell or "9" +++++++++++ 10 in third cell +>+++++++++ 9 in fourth cell + +########################################## +### create ASCII chars in higher cells ### +########################################## + +>>++++++++[<++++>-] " " +>++++++++++++++[<+++++++>-] b ++>+++++++++++[<++++++++++>-] o +++>+++++++++++++++++++[<++++++>-] t +++>+++++++++++++++++++[<++++++>-] t +>++++++++++++[<+++++++++>-] l ++>++++++++++[<++++++++++>-] e ++>+++++++++++++++++++[<++++++>-] s +>++++++++[<++++>-] " " ++>+++++++++++[<++++++++++>-] o +++>++++++++++[<++++++++++>-] f +>++++++++[<++++>-] " " +>++++++++++++++[<+++++++>-] b ++>++++++++++[<++++++++++>-] e ++>++++++++++[<++++++++++>-] e +>+++++++++++++++++++[<++++++>-] r +>++++++++[<++++>-] " " ++>+++++++++++[<++++++++++>-] o +>+++++++++++[<++++++++++>-] n +>++++++++[<++++>-] " " +++>+++++++++++++++++++[<++++++>-] t +++++>++++++++++[<++++++++++>-] h ++>++++++++++[<++++++++++>-] e +>++++++++[<++++>-] " " +++>+++++++++++++[<+++++++++>-] w ++>++++++++++++[<++++++++>-] a +>++++++++++++[<+++++++++>-] l +>++++++++++++[<+++++++++>-] l +>+++++[<++>-] LF +++>+++++++++++++++++++[<++++++>-] t ++>++++++++++++[<++++++++>-] a ++++>+++++++++++++[<++++++++>-] k ++>++++++++++[<++++++++++>-] e +>++++++++[<++++>-] " " ++>+++++++++++[<++++++++++>-] o +>+++++++++++[<++++++++++>-] n ++>++++++++++[<++++++++++>-] e +>++++++++[<++++>-] " " +>++++++++++[<++++++++++>-] d ++>+++++++++++[<++++++++++>-] o +++>+++++++++++++[<+++++++++>-] w +>+++++++++++[<++++++++++>-] n +>++++++++[<++++>-] " " ++>++++++++++++[<++++++++>-] a +>+++++++++++[<++++++++++>-] n +>++++++++++[<++++++++++>-] d +>++++++++[<++++>-] " " +++>+++++++++++[<++++++++++>-] p ++>++++++++++++[<++++++++>-] a ++>+++++++++++++++++++[<++++++>-] s ++>+++++++++++++++++++[<++++++>-] s +>++++++++[<++++>-] " " ++>+++++++++++++[<++++++++>-] i +++>+++++++++++++++++++[<++++++>-] t +>++++++++[<++++>-] " " ++>++++++++++++[<++++++++>-] a +>+++++++++++++++++++[<++++++>-] r ++>+++++++++++[<++++++++++>-] o +>+++++++++++++[<+++++++++>-] u +>+++++++++++[<++++++++++>-] n +>++++++++++[<++++++++++>-] d +>+++++[<++>-] LF ++++++++++++++ CR + +[<]>>>> go back to fourth cell + +################################# +### initiate the display loop ### +################################# + +[ loop + < back to cell 3 + [ loop + [>]<< go to last cell and back to LF + .. output 2 newlines + [<]> go to first cell + + ################################### + #### begin display of characters### + ################################### + # + #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #X X b o t t l e s o f b e e r + #.>.>.>.>.>.>.>.>.>.>.>. + #o n t h e w a l l N + #[<]> go to first cell + #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> + #X X b o t t l e s o f b e e r N + #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #t a k e o n e d o w n a n d p a s s + #.>.>.>.>.>.>.>.>.>. + #i t a r o u n d N + ##### + + [<]>> go to cell 2 + - subtract 1 from cell 2 + < go to cell 1 + + ######################## + ### display last line ## + ######################## + # + #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #X X b o t t l e s o f b e e r + #.>.>.>.>.>.>.>.>.>.>. + #o n t h e w a l l + ##### + + [<]>>>- go to cell 3/subtract 1 + ] end loop when cell 3 is 0 + ++++++++++ add 10 to cell 3 + <++++++++++ back to cell 2/add 10 + <- back to cell 1/subtract 1 + [>]<. go to last line/carriage return + [<]> go to first line + +######################## +### correct last line ## +######################## +# +#.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> +#X X b o t t l e s o f b e e r +#.>.>.>.>.>.>.>.>.>.>. +#o n t h e w a l l +##### + + [<]>>>>- go to cell 4/subtract 1 +] end loop when cell 4 is 0 + +############################################################## +### By this point verses 99\10 are displayed but to work ### +### with the lower numbered verses in a more readable way ### +### we initiate a new loop for verses 9{CODE} that will not ### +### use the fourth cell at all ### +############################################################## + ++ add 1 to cell four (to keep it non\zero) +<-- back to cell 3/subtract 2 + +[ loop + [>]<< go to last cell and back to LF + .. output 2 newlines + [<]> go to first cell + + ################################### + #### begin display of characters### + ################################### + # + #>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + # X b o t t l e s o f b e e r + #.>.>.>.>.>.>.>.>.>.>.>. + #o n t h e w a l l N + #[<]> go to first cell + #>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> + # X b o t t l e s o f b e e r N + #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #t a k e o n e d o w n a n d p a s s + #.>.>.>.>.>.>.>.>.>. + #i t a r o u n d N + ##### + + [<]>> go to cell 2 + - subtract 1 from cell 2 + + ######################## + ### display last line ## + ######################## + # + #.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> + #X b o t t l e s o f b e e r + #.>.>.>.>.>.>.>.>.>.>. + #o n t h e w a l l + ##### + + [<]>>>- go to cell 3/subtract 1 +] end loop when cell 3 is 0 ++ add 1 to cell 3 to keep it non\zero + +[>]<. go to last line/carriage return +[<]> go to first line + +######################## +### correct last line ## +######################## +# +#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.> +# X b o t t l e o f b e e r +#.>.>.>.>.>.>.>.>.>.>.<<<<. +#o n t h e w a l l +##### + +[>]<< go to last cell and back to LF +.. output 2 newlines +[<]> go to first line + +######################### +### the final verse ## +######################### +# +#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.> +# X b o t t l e o f b e e r +#.>.>.>.>.>.>.>.>.>.>.>. +#o n t h e w a l l N +#[<]> go to first cell +#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.> +# X b o t t l e o f b e e r N +#.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> +#t a k e o n e d o w n a n d p a s s +#.>.>.>.>.>.>.>.>.>. +#i t a r o u n d N +#[>]< go to last line +#<<<.<<.<<<. +# n o +#[<]>>>> go to fourth cell +#>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> +# b o t t l e s o f b e e r +#.>.>.>.>.>.>.>.>.>.>.>. +#o n t h e w a l l N +#####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 @@ +/* +Copyright 2009 Sebastiano Tronto + +This file is part of PBFI (Porky's Brain F*** Interpreter). + + PBFI 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. + + PBFI 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 PBFI; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.*; +import java.awt.BorderLayout; +import java.awt.event.*; +import java.io.*; + +public class Frame extends JFrame { +public static int valoreChooser; + public static boolean firstSave; + public static String defaultSave; + public static Main main; + public static JTextArea textArea; + public static JButton runButton; + public static JMenuBar bar; + public static JMenu menuFile, menuAiuto; + public static JMenuItem esci, esegui, salva, salvaConNome, apri, info; + public static JFileChooser chooser; + public static FileInputStream in; + public static FileOutputStream out; + public Frame() { + super( "Porky's BrainF** Interpreter - v1.1" ); + firstSave = true; + main = new Main(); + defaultSave = ""; + chooser = new JFileChooser(); + textArea = new JTextArea( "Digitare qui il codice BrainF***", 15, 15 ); + bar = new JMenuBar(); + menuFile = new JMenu( "File" ); + menuAiuto = new JMenu( "?" ); + esci = new JMenuItem( "Esci" ); + esegui = new JMenuItem( "Esegui" ); + salva = new JMenuItem( "Salva" ); + salvaConNome = new JMenuItem( "Salva con nome" ); + apri = new JMenuItem( "Apri" ); + info = new JMenuItem( "Aiuto" ); + menuFile.setMnemonic( 'F' ); + menuAiuto.setMnemonic( '?' ); + esci.setMnemonic( 'E' ); + esegui.setMnemonic( 's' ); + salva.setMnemonic( 'a' ); + salvaConNome.setMnemonic( 'n' ); + apri.setMnemonic( 'p' ); + info.setMnemonic( 'i' ); + esci.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + System.exit( 0 ); + } + } + ); + esegui.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + main.run( textArea.getText() ); + } + } + ); + salva.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + if ( firstSave ) { + valoreChooser = chooser.showSaveDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + out = new FileOutputStream( chooser.getSelectedFile().getPath() ); + defaultSave = chooser.getSelectedFile().getPath(); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + firstSave = false; + } else { + try { + out = new FileOutputStream( defaultSave ); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + } + } + } + } + ); + salvaConNome.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + valoreChooser = chooser.showSaveDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + out = new FileOutputStream( chooser.getSelectedFile().getPath() ); + defaultSave = chooser.getSelectedFile().getPath(); + char caratteri[]; + byte bytes[]; + caratteri = textArea.getText().toCharArray(); + bytes = new byte[caratteri.length]; + for ( int i = 0; i < caratteri.length; i++ ) + bytes[i] = ( byte ) caratteri[i]; + out.write( bytes ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + firstSave = false; + } + } + ); + apri.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + valoreChooser = chooser.showOpenDialog( Frame.this ); + switch ( valoreChooser ) { + case JFileChooser.APPROVE_OPTION: + try { + String stringa; + byte bytes[]; + char caratteri[]; + in = new FileInputStream( chooser.getSelectedFile().getPath() ); + bytes = new byte[in.available()]; + caratteri = new char[in.available()]; + in.read( bytes ); + for ( int i = 0; i < bytes.length; i++ ) + caratteri[i] = ( char ) bytes[i]; + stringa = new String( caratteri ); + textArea.setText( stringa ); + } catch ( Exception ex ) { + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + ex + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + } + break; + case JFileChooser.ERROR_OPTION: + JOptionPane.showMessageDialog( Frame.this, "Errore sconosciuto:\n\n" + e + "\n\nPer favore riportare il bug a sebastiano@luganega.org", "Errore", JOptionPane.ERROR_MESSAGE ); + break; + //case JFileChooser.CANCEL_OPTION: + } + } + } + ); + info.addActionListener( + new ActionListener() { + public void actionPerformed ( ActionEvent e ) { + 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 ); + } + } + ); + menuFile.add( esegui ); + menuFile.add( salva ); + menuFile.add( salvaConNome ); + menuFile.add( apri ); + menuFile.add( esci ); + menuAiuto.add( info ); + bar.add( menuFile ); + bar.add( menuAiuto ); + runButton = new JButton( "Esegui" ); + runButton.addActionListener( + new ActionListener() { + public void actionPerformed( ActionEvent e ) { + main.run( textArea.getText() ); + } + } + ); + setLayout( new BorderLayout() ); + setJMenuBar( bar ); + add( new JScrollPane( textArea ), BorderLayout.CENTER ); + add( runButton, BorderLayout.SOUTH ); + } +} \ 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 @@ +Questo è un esempio Hello World in BrainFuck (fonte: wikipedia) +notare che tutti i caratteri diversi dagli 8 comandi sono considerati un commento + +++++++++++ +[ + >+++++++>++++++++++>+++>+<<<<- +] +>++. Loop iniziale (dopo viene stampata una H) +>+. e ++++++++. l +. l ++++. o +>++. +<<+++++++++++++++. +>. ++++. +------. +--------. +>+. +>. 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 @@ +/* +Copyright 2009 Sebastiano Tronto + +This file is part of PBFI (Porky's Brain F*** Interpreter). + + PBFI 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. + + PBFI 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 PBFI; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import javax.swing.JFrame; +import java.util.Scanner; +public class Main { + public static Scanner scanner; + public static char totalCode[], charCodeAux[], charCode[], chars; + public static byte a[]; + public static int i; + public static void main( String args[] ) { + Frame frame = new Frame(); + frame.setSize( 200, 300 ); + frame.setVisible( true ); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + } + public static void run( String code ) { + chars = 'a'; + int j = 0; + totalCode = code.toCharArray(); + charCodeAux = new char[totalCode.length*2]; + for ( int k = 0; k < totalCode.length; k++ ) { + switch ( totalCode[k] ) { + case '>': + case '<': + case '+': + case '-': + case '.': + case ',': + charCodeAux[j] = totalCode[k]; + j++; + break; + case '[': + charCodeAux[j] = totalCode[k]; + j++; + charCodeAux[j] = chars; + chars++; + j++; + break; + case ']': + chars--; + charCodeAux[j] = chars; + j++; + charCodeAux[j] = totalCode[k]; + j++; + break; + } + } + charCode = new char[j]; + for ( int k = 0; k < charCode.length; k++ ) + charCode[k] = charCodeAux[k]; + scanner = new Scanner( System.in ); + a = new byte[30000]; + for ( int count = 0; count < a.length; count++ ) + a[count] = 0; + i = 0; + execute( scanner, charCode, a, i, 0, charCode.length ); + } + public static void execute( Scanner scanner, char charCode[], byte a[], int i, int start, int stop ) { + for ( int count = start; count < stop; count++ ) { + switch ( charCode[count] ) { + case '>': + i++; + break; + case '<': + i--; + break; + case '+': + a[i]++; + break; + case '-': + a[i]--; + break; + case '.': + System.out.print( (char) a[i] ); + break; + case ',': + String stringa = scanner.nextLine(); + a[i] = (byte) ( ( stringa.toCharArray() )[0] ); + break; + case '[': + if ( a[i] == 0 ) { + count++; + char key = charCode[count]; + count++; + for ( ; charCode[count] != key; count++ ) ; + count++; + } + break; + case ']': + if ( a[i] != 0 ) { + count --; + char key = charCode[count]; + count --; + for ( ; charCode[count] != key; count-- ) ; + } + break; + } + } + } +} \ 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 @@ +Questo programma è un esempio di quine (programma che mostra in output il suo codice sorgente) in BrainFuck (fonte: wikipedia) + + ->+>+++>>+>++>+>+++>>+>++>>>+>+>+>++>+>>>>+++>+>>++>+>+++>>++>++>>+>>+>++>++> + +>>>>+++>+>>>>++>++>>>>+>>++>+>+++>>>++>>++++++>>+>>++>+>>>>+++>>+++++>>+>+++ + >>>++>>++>>+>>++>+>+++>>>++>>+++++++++++++>>+>>++>+>+++>+>+++>>>++>>++++>>+>> + ++>+>>>>+++>>+++++>>>>++>>>>+>+>++>>+++>+>>>>+++>+>>>>+++>+>>>>+++>>++>++>+>+ + ++>+>++>++>>>>>>++>+>+++>>>>>+++>>>++>+>+++>+>+>++>>>>>>++>>>+>>>++>+>>>>+++> + +>>>+>>++>+>++++++++++++++++++>>>>+>+>>>+>>++>+>+++>>>++>>++++++++>>+>>++>+>> + >>+++>>++++++>>>+>++>>+++>+>+>++>+>+++>>>>>+++>>>+>+>>++>+>+++>>>++>>++++++++ + >>+>>++>+>>>>+++>>++++>>+>+++>>>>>>++>+>+++>>+>++>>>>+>+>++>+>>>>+++>>+++>>>+ + [[->>+<<]<+]+++++[->+++++++++<]>.[+]>>[<<+++++++[->+++++++++<]>- + .------------------->-[-<.<+>>]<[+]<+>>>]<<<[-[-[-[>>+<++++++[->+++++<]]>++++ + ++++++++++<]>+++<]++++++[->+++++++<]>+<<<-[->>>++<<<]>[->>.<<]<<] -- cgit v1.3