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.0 | |
| download | ancient-projects-master.tar.gz ancient-projects-master.zip | |
Diffstat (limited to 'pbfi/pbfi-1.0')
| -rwxr-xr-x | pbfi/pbfi-1.0/src/Frame.java | 49 | ||||
| -rwxr-xr-x | pbfi/pbfi-1.0/src/Main.java | 119 |
2 files changed, 168 insertions, 0 deletions
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 @@ | |||
| 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 javax.swing.JButton; | ||
| 24 | import javax.swing.JTextArea; | ||
| 25 | import javax.swing.JScrollPane; | ||
| 26 | import java.awt.BorderLayout; | ||
| 27 | import java.awt.event.*; | ||
| 28 | |||
| 29 | public class Frame extends JFrame { | ||
| 30 | public static Main main; | ||
| 31 | public static JTextArea textArea; | ||
| 32 | public static JButton runButton; | ||
| 33 | public Frame() { | ||
| 34 | super( "Porky's Brain F*** Interpreter - v1.0" ); | ||
| 35 | main = new Main(); | ||
| 36 | textArea = new JTextArea( "Brain F*** source code here", 15, 15 ); | ||
| 37 | runButton = new JButton( "Run" ); | ||
| 38 | runButton.addActionListener( | ||
| 39 | new ActionListener() { | ||
| 40 | public void actionPerformed( ActionEvent e ) { | ||
| 41 | main.run( textArea.getText() ); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | ); | ||
| 45 | setLayout( new BorderLayout() ); | ||
| 46 | add( new JScrollPane( textArea ), BorderLayout.CENTER ); | ||
| 47 | add( runButton, BorderLayout.SOUTH ); | ||
| 48 | } | ||
| 49 | } \ 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 @@ | |||
| 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 | j++; | ||
| 56 | chars++; | ||
| 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 | ||
