Execute SNUSP/Java: Difference between revisions

Content added Content deleted
(I think it's ready)
 
(Added % command)
Line 1: Line 1:
{{implementation|SNUSP}}{{collection|RCSNUSP}}[[Category:Java]]
{{implementation|SNUSP}}{{collection|RCSNUSP}}[[Category:Java]]
This implementation has all of the basic characters plus '@' and '#' (characters from modular SNUSP found on [http://esolangs.org/wiki/SNUSP esolangs]). The memory space grows to the right as needed, and the memory pointer cannot go negative. The program will exit if the memory pointer moves to a negative value or if the code pointer leaves the code space. The input ignores return characters because of the way <tt>BufferedReader</tt> is set up.
This implementation has all of the basic characters plus '%', '@', and '#' (characters from modular and bloated SNUSP found on [http://esolangs.org/wiki/SNUSP esolangs]). The memory space grows to the right as needed, and the memory pointer cannot go negative. The program will exit if the memory pointer moves to a negative value or if the code pointer leaves the code space. The input ignores return characters because of the way <tt>BufferedReader</tt> is set up. The random command places a random ASCII character (code 0 through 255 inclusive)in the current memory space.


The implementation comes in two classes: the main program and a code pointer class. The separation is for the easier addition of '&' (split) which could come in the future (the code pointer class would only need to extend <tt>Thread</tt> and code added to deal with the command). The main class decides on the input method (file or std in), reads the code, and starts the code pointer. It also figures out where the starting point in the code is ('$').<br clear=all>
The implementation comes in two classes: the main program and a code pointer class. The separation is for the easier addition of '&' (split) which could come in the future (the code pointer class would only need to extend <tt>Thread</tt> and code added to deal with the command). The main class decides on the input method (file or std in), reads the code, and starts the code pointer. It also figures out where the starting point in the code is ('$').<br clear=all>
Line 58: Line 58:
public class CodePtr{
public class CodePtr{
final int LEFT= 2, RIGHT= 0, UP= 3, DOWN= 1;//directions
final int LEFT= 2, RIGHT= 0, UP= 3, DOWN= 1;//directions
final String instChars= "><.,/\\+-#@$!?";//valid chars
final String instChars= "><.,/\\+%-#@$!?";//valid chars
ArrayList<String> code;//code array
ArrayList<String> code;//code array
int dir;//current direction
int dir;//current direction
Line 182: Line 182:
place= moveCP();//skip
place= moveCP();//skip
break;
break;
case '%':
//use a random regular ASCII character
mem.set(memPtr, (char)(Math.random() * 256));
default:
default:
}
}