Whitespace programming language
Whitespace Programming language, a new language out there with only three tokens: space, tab and line feed.
Here is a sample ws program from their tutorial:
The language itself is an imperative, stack based language. Each command consists of a series of tokens, beginning with the Instruction Modification Parameter (IMP). These are listed in the table below.
IMP Meaning
[Space] Stack Manipulation
[Tab][Space] Arithmetic
[Tab][Tab] Heap access
[LF] Flow Control
[Tab][LF] I/O
Here is a sample ws program from their tutorial:
Annotated Example
Here is an annotated example of a program which counts from 1 to 10, outputting
the current value as it goes.
[Space][Space][Space][Tab][LF] Put a 1 on the stack
[LF][Space][Space][Space][Tab][Space][Space]
[Space][Space][Tab][Tab][LF]
Set a Label at this point
[Space][LF][Space]Duplicate the top stack item
[Tab][LF][Space][Tab]Output the current value
[Space][Space][Space][Tab][Space][Tab][Space][LF]
Put 10 (newline) on the stack...
[Tab][LF][Space][Space]...and output the newline
[Space][Space][Space][Tab][LF]Put a 1 on the stack
[Tab][Space][Space][Space]Addition. This increments our current value.
[Space][LF][Space]Duplicate that value so we can test it
[Space][Space][Space][Tab][Space][Tab][Tab][LF]
Push 11 onto the stack
[Tab][Space][Space][Tab]Subtraction. So if we've reached the end, we have a zero on the stack.
[LF][Tab][Space][Space][Tab][Space][Space]
[Space][Tab][Space][Tab][LF]If we have a zero, jump to the end
[LF][Space][LF][Space][Tab][Space]
[Space][Space][Space][Tab][Tab][LF]
Jump to the start
[LF][Space][Space][Space][Tab][Space]
[Space][Space][Tab][Space][Tab][LF]
Set the end label
[Space][LF][LF]Discard our accumulator, to be tidy
[LF][LF][LF]Finish
What could be simpler? The source code for this program is available
here. Have fun!
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home