Kipple is a stack-based, esoteric programming language invented by Rune Berg in March 2003.
Kipple has 27 stacks, 4 operators, and a control structure.
The stacks are named
z and contain 32-bit signed integers. There is also a special stack,
@, to make outputting numbers more convenient. When a number is pushed onto
@, the ASCII values of that number's digits are in fact pushed instead. (For example, if you push 12 to
@, it will push 49 and then 50 to
Input is pushed onto the input stack
i before the program is executed. The interpreter will ask for values to store in
i before execution. After execution finishes, anything on the output stack
o is popped to output as ASCII character . Since this is Kipple's only IO mechanism, interacting with a Kipple program is impossible.
An operand is either a stack identifier or a signed 32 bit integer.
The Push operator takes the operand to the left and pushes it onto the specified stack. For example,
12>a will push the value 12 onto stack
a>b will pop the topmost value from stack
a and push it onto stack
b. Popping an empty stack always returns 0.
a<b is equivalent to
a<b>c pops topmost value from
b and pushes to both
The Add operator pushes the sum of the topmost item on the stack and the operand onto the stack. If the operand is a stack, then the value is popped from it. For example, if the topmost value of stack
a is 1, then
a+2 will push 3 onto it. If
a is empty, then
a+2 will push 2 onto it. If the topmost values of stack
b are 1 and 2, then
a+b will pop the value 2 from stack
b and push 3 onto stack
The Subtract operator works exactly like the Add operator, except that it subtracts instead of adding.
The Clear operator empties the stack if its topmost item is 0.
The interpreter will ignore anything that isn't next to an operator, so the following program would work:
a+2 this will be ignored c<i. However, the proper way to add comments is by using the
# character. Anything between a
# and an end-of-line character is removed before execution. ASCII character #10 is defined as end-of-line in Kipple.
Operands may be shared by two operators, e.g.
a>b c>b c? may be written as
1>a<2 a+a will result in
a containing the values
[1 4] (from bottom to top) and not
[1 3]. Likewise for the
The Control Structure
There is only one control structure in Kipple: the loop.
(StackIndentifier code )
As long as the specified stack is not empty, the code within the matching parentheses will be repeated. Loops may contain other loops. For example,
(a a>b) will move all the values of stack
a onto stack
b, though the order will be reversed. A functionally identical, but more elegant way to do this is
This will output
33>o 100>o 108>o 114>o 111>o 87>o 32>o 111>o 108>o 108>o 101>o 72>o
This will print
"Hello World!". When the
o stack is being output, it starts to pop characters from top of the stack to bottom.
#prime.k by Jannis Harder u<200 #change 200 k<2>m u-2 (u-1 u>t u>z u<t (k>e e+0 e>r) (e>k) m+1 m>t m>z m<t t<0>z? t? 1>g (r>b m+0 m>a b+0 b>w (a-1 b+0 b>j j? 1>s (j<0>s j?) s? (s<0 w+0 w>b s?) a>t a>z t>a b-1 b>t b>z t>b z<0>t? z? a?) b? 1>p (b<0 b? 0>p) p? (p 0>r? 0>p? 0>g) ) g? (g m+0 m>k 0>g?) u?) (k>@ 10>o (@>o) )
This is a prime number generator, but I'm not sure how it works.
You must write a program/function that interprets Kipple. This program/function may get a Kipple program via a source file, or get it via STDIN directly from the user. If STDIN is not available, it must get it from keyboard input, and continue getting input until a specific unprintable character is entered. For example, if your interpreter is written in x86 machine code, it would get the Kipple program character by character from keyboard, and continue to do so until esc (or any other key other that does not emit a printable character) is pressed.
If there is an error, e.g. a syntax error or stack overflow, it must acknowledge it in some way, for example by returning 10 instead of 0 or error messages produced by the interpreter/compiler, BUT NOT PRINTING ERROR MESSAGES.
Any other regular rules for code golf apply for this challenge.
Your code will be tested with some of the examples in Kipple's samples archive
This is a code-golf . Shortest code in bytes will win. Good Luck!
Note that there is an optional operator in Kipple,
", but it is not a part of the specification and just an extra feature in official interpreter. I haven't mentioned it here so it does not need to be supported in your submission.
If you have any doubt about any part of specification , you can examine it with official interpreter written in Java . This will download a zip file containing compiled program and source code . It's licensed under the GPL.