Whitespace

Implements a virtual machine for the Whitespace language.

Whitespace is an imperative, stack based language. The only significant tokens are the white space characters: [Space], [Tab], and [LF]. Anything else is treated as a comment and ignored.

You can use this implementation to experiment with the Whitespace language, and to disassemble whitespace code into (slightly) more readable assmbler code.

Usage

java Whitespace [options] myprog.ws

...or, if you use the scripts in the bin directory...

ws [options] myprog.ws

Options are:

-a
Annotate a Whitespace program instead of executing it. This will dis-assemble Whitespace code to the sort of assembler used by WsAsm.
-v
Verbose output about the program execution. With -a, gives a more verbose annotation.
-V
Same as -v, but more verbose.
-x
Enables extensions to the original Whitespace language.

Example

This Whitespace code prints some Fibonacci numbers.

   	
    
		    	
 
 
 	 			     			  	  		 			 
   	

   		 			  		  	 	 				    			 	  
 
 
 	 			     			  	  		 			 
 
	 	  	
	      	
 
 			   	
	    
    	    
 
		  	
		 		  	   		 				 		 			  		  	 	
		 
 
 		 			  		  	 	 				    			 	  

   		  	   		 				 		 			  		  	 	




   			     			  	  		 			 
	
 	   	 	 
	
  
	



Too hard to read? Here it is with white space made visible.

[Space][Space][Space][Tab][LineFeed]
[Space][Space][Space][Space][LineFeed]
[Tab][Tab][Space][Space][Space][Space][Tab][LineFeed]
[Space][LineFeed]
[Space][LineFeed]
[Space][Tab][Space][Tab][Tab][Tab][Space][Space][Space][Space][Space][Tab][Tab][Tab][Space][Space][Tab][Space][Space][Tab][Tab][Space][Tab][Tab][Tab][Space][LineFeed]
[Space][Space][Space][Tab][LineFeed]
[LineFeed]
[Space][Space][Space][Tab][Tab][Space][Tab][Tab][Tab][Space][Space][Tab][Tab][Space][Space][Tab][Space][Tab][Space][Tab][Tab][Tab][Tab][Space][Space][Space][Space][Tab][Tab][Tab][Space][Tab][Space][Space][LineFeed]
[Space][LineFeed]
[Space][LineFeed]
[Space][Tab][Space][Tab][Tab][Tab][Space][Space][Space][Space][Space][Tab][Tab][Tab][Space][Space][Tab][Space][Space][Tab][Tab][Space][Tab][Tab][Tab][Space][LineFeed]
[Space][LineFeed]
[Tab][Space][Tab][Space][Space][Tab][LineFeed]
[Tab][Space][Space][Space][Space][Space][Space][Tab][LineFeed]
[Space][LineFeed]
[Space][Tab][Tab][Tab][Space][Space][Space][Tab][LineFeed]
[Tab][Space][Space][Space][Space][LineFeed]
[Space][Space][Space][Space][Tab][Space][Space][Space][Space][LineFeed]
[Space][LineFeed]
[Tab][Tab][Space][Space][Tab][LineFeed]
[Tab][Tab][Space][Tab][Tab][Space][Space][Tab][Space][Space][Space][Tab][Tab][Space][Tab][Tab][Tab][Tab][Space][Tab][Tab][Space][Tab][Tab][Tab][Space][Space][Tab][Tab][Space][Space][Tab][Space][Tab][LineFeed]
[Tab][Tab][Space][LineFeed]
[Space][LineFeed]
[Space][Tab][Tab][Space][Tab][Tab][Tab][Space][Space][Tab][Tab][Space][Space][Tab][Space][Tab][Space][Tab][Tab][Tab][Tab][Space][Space][Space][Space][Tab][Tab][Tab][Space][Tab][Space][Space][LineFeed]
[LineFeed]
[Space][Space][Space][Tab][Tab][Space][Space][Tab][Space][Space][Space][Tab][Tab][Space][Tab][Tab][Tab][Tab][Space][Tab][Tab][Space][Tab][Tab][Tab][Space][Space][Tab][Tab][Space][Space][Tab][Space][Tab][LineFeed]
[LineFeed]
[LineFeed]
[LineFeed]
[LineFeed]
[Space][Space][Space][Tab][Tab][Tab][Space][Space][Space][Space][Space][Tab][Tab][Tab][Space][Space][Tab][Space][Space][Tab][Tab][Space][Tab][Tab][Tab][Space][LineFeed]
[Tab][LineFeed]
[Space][Tab][Space][Space][Space][Tab][Space][Tab][Space][LineFeed]
[Tab][LineFeed]
[Space][Space][LineFeed]
[Tab][LineFeed]
[LineFeed]
[LineFeed]
[LineFeed]

If that's still too hard, see the assembler version of the same example.

Compliance

This implements Whitespace v0.3 from the original Whitespace site (recovered from the Wayback Machine and now available here). That means it includes the instructions in the Stack IMP added for v0.3 by the original developer: [Space][LF][LF] and [Space][Tab][LF] (or in WsAsm, drop and slide).

I found another developer had made a v0.4 which has an instruction added to randomise the stack. This implementation does not include that instruction.

One difference is that this implementation explicitly prevents use of negatve heap addresses. In the original implementation, writing to some negative addresses was ok, but others caused massive memory allocations or program crash.

Extensions

If enabled with the option -x, there are some extensions available to the original Whitespace language.

None of this is enabled unless you run the interpreter with the extensions flag, -x. The default is standard Whitespace.

Possible further extensions?