Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Brainf*ck Interpreter (Java)
// Made By Ice Scripter // Made this because I might use this for my final in my CS class. // WIP /* NOTES: Bug with loops */ import java.util.*; import java.util.Scanner; import java.lang.*; class Rextester { public static void main(String args[]) { Scanner input = new Scanner(System.in); String code = ""; // Use the input to insert code String output = ""; byte memory[] = new byte[8]; // Change the number to change the "slots" of memory int loops[] = new int[100]; // 100 Max loops int currentLoop = 0; int pointer = 0; System.out.println("Input your code >> "); code = input.nextLine(); System.out.println(code); // Remove if u put this through a real program for (int i = 0; i < code.length(); i++) { switch ( code.charAt(i) ) { case '>': pointer = (pointer + 1) % (memory.length); break; case '<': pointer = Math.floorMod(pointer-1, memory.length); break; case '+': memory[pointer] ++; break; case '-': memory[pointer] --; break; case '[': for (int x = 0; i < loops.length; i++) { if (loops[x] == 0) { currentLoop = x; loops[x] = i; break; } else if (x == loops.length-1) { System.out.println("Too many nested loops!"); return; } } break; case ']': if (memory[pointer] != 0) { i = loops[currentLoop]; System.out.println("Test"); } else { loops[currentLoop] = 0; currentLoop = 0; System.out.println("End loop"); } break; case '.': output += Character.toString((char)memory[pointer]); break; } } System.out.println("\nOutput: \n" + output); System.out.println("\nMemory: "); for (int i = 0; i < memory.length; i++) { System.out.println(memory[i] + "\t" + i); } } }
run
|
edit
|
history
|
help
0
jb11.0 threads tick tock 1.0
Job and Trait Generator
parameter const
1d
DFS in Graph
m-primes
Majors
Catalan number optimised
Coding Challenge - 04 (Perfect numbers)
boundary vs core