Anonymous user
Execute Brain****/Java: Difference between revisions
m
Added more description and some comments.
m (Added note about expansion to the right an Turing completeness.) |
m (Added more description and some comments.) |
||
Line 2:
In this implementation of [[Brainf***]], the code is read in all at once and checked for uneven brackets (unequal amounts of [ and ] commands). If that error occurs, the code will obviously not be run.
Under the hood, the program memory is an ArrayList of Integers which expands "infinitely" (limited by your system's memory) to the right (still [http://en.wikipedia.org/wiki/Turing_completeness Turing complete]). So, if the pointer moves past zero to the left, the program will exit and a "Pointer out of range" error message will be displayed. Due to the BufferedReader input class, return characters ([http://www.asciitable.com ASCII] 10 and 13) are ignored on input (the , command), but are not ignored on output (the . command).
More detailed information about the rest of the code can be found in the comments throughout it.
import java.io.BufferedReader;
Line 36 ⟶ 38:
}
char instruction;
//holds the cleaned up code
StringBuilder code= new StringBuilder();
|