kipple03.html 5.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <HTML>
  2. <HEAD>
  3. <TITLE>The Kipple Language Specification</TITLE>
  4. <!-- LINK REL=StyleSheet HREF="../esoteric.css" TYPE="text/css" -->
  5. </HEAD>
  6. <BODY>
  7. <H1>The Kipple Language Specification</H1><HR>
  8. <P>Kipple is a minimalistic, <A HREF="http://www.wikipedia.org/wiki/Turing-complete">Turing-complete</A>, stack-based programming language where data is stored in 26 stacks named <EM>a</EM>-<EM>z</EM>. The values on the stacks are 32-bit signed integers. The language consists of four operators and one control structure. Each operator takes one or two operands, and an operand can either be a non-negative integer (<EM>0</EM>-<EM>2147483647</EM>) or a stack identifier (<EM>a</EM>-<EM>z</EM>). Stack identifiers are case insensitive. Note that allthough an integer operand has to be zero or positive, the stacks can hold negative numbers as well (which can be accomplished with the - operator). All the stacks start out empty, except stack <EM>i</EM> which will contain the programs input (see <A HREF="#IO">Input and Output</A>).</P>
  9. <H3>The operators</H3>
  10. <UL>
  11. <LI><P><STRONG>Push: &gt; or &lt;</STRONG><BR/>
  12. Syntax: <EM>Operand</EM><STRONG>&gt;</STRONG><EM>StackIndentifier</EM> or <EM>StackIndentifier</EM><STRONG>&lt;</STRONG><EM>Operand</EM><BR/>
  13. The Push operator takes the operand to the left and pushes it onto the specified stack. E.g. <code>12&gt;a</code> will push the value <EM>12</EM> onto stack <EM>a</EM>. <code>a&gt;b</code> will pop the topmost value from stack <EM>a</EM> and push it onto stack <EM>b</EM>. Popping an empty stack always returns <EM>0</EM>.
  14. <code>a&lt;b</code> is equivalent with <code>b&gt;a</code>.
  15. <LI><P><STRONG>Add: +</STRONG><BR/>
  16. Syntax: <EM>StackIndentifier</EM><STRONG>+</STRONG><EM>Operand</EM><BR/>
  17. 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. E.g. if the topmost value of stack <EM>a</EM> is <EM>1</EM>, then <CODE>a+2</CODE> will push <EM>3</EM> onto it. If <EM>a</EM> is empty, then <CODE>a+2</CODE> will push <EM>2</EM> onto it. If the topmost values of stack <EM>a</EM> and <EM>b</EM> are <EM>1</EM> and <EM>2</EM>, then <CODE>a+b</CODE> will pop the value <EM>2</EM> from stack <EM>b</EM> and push <EM>3</EM> onto stack <EM>a</EM>.
  18. <LI><P><STRONG>Subtract: -</STRONG><BR/>
  19. Syntax: <EM>StackIndentifier</EM><STRONG>-</STRONG><EM>Operand</EM><BR/>
  20. The Subtract operator works exactly like the Add operator, except that it subtracts instead of adding.
  21. <LI><P><STRONG>Clear: ?</STRONG><BR/>
  22. Syntax: <EM>StackIndentifier</EM><STRONG>?</STRONG><BR/>
  23. The Clear operator empties the stack if it's topmost item is <EM>0</EM>.
  24. </UL>
  25. <P>
  26. The interpreter will ignore anything that isn't next to an operator, so the following program would work: <CODE>a+2 this will be ignored c&lt;i</CODE>. 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.<BR/>
  27. </P>
  28. <P>Operands may be shared by two operators. E.g. <CODE>a&gt;b c&gt;b c?</CODE> may be written as <CODE>a&gt;b&lt;c?</CODE>.
  29. </P>
  30. <P>The program <CODE>1&gt;a&lt;2 a+a</CODE> will result in <EM>a</EM> containing the values <EM>[1 4]</EM> and <STRONG>not</STRONG> <EM>[1 3]</EM>. Likewise for the <STRONG>-</STRONG> operator.
  31. <H3>The control structure</H3>
  32. <P>There is only one control structure in Kipple: the loop.
  33. Syntax: <STRONG>(</STRONG><EM>StackIndentifier</EM> <EM>code</EM> <STRONG>)</STRONG>. As long as the specified stack is not empty, the <EM>code</EM> within the matching parentheses will be repeated. Loops may contain other loops. Example: <CODE>(a a>b)</CODE> will move all the values of stack <EM>a</EM> onto stack <EM>b</EM> (though the order will be reversed). A functionally identical, but more elegant way to do this is <CODE>(a>b)</CODE>.
  34. </P>
  35. <H3 ID="IO">Input and output</H3>
  36. <P>Before a Kipple program is executed, all input is pushed onto stack <EM>i</EM>. That means it's impossible to get input during program execution. Input is read as a string of bytes.</P>
  37. <P>When a Kipple program ends the contents of stack <EM>o</EM> are written to output. Output is written as bytes, even though the stack contains 32-bit integers. The following program will write it's input to output (i.e. cat): <CODE>(i&gt;o)</CODE></P>
  38. <P>To make output of numbers more convenient, the special stack <EM>@</EM> has been added to the language. When a program tries to push a value onto stack <EM>@</EM>, the ASCII values of each digit is pushed onto it instead. E.g. while the program <CODE>100&gt;o</CODE> will output "d" (d is ASCII #100), the program <CODE>100&gt;@ (@&gt;o)</CODE> will output "100".
  39. </P>
  40. <H3>Strings</H3>
  41. <P>There are no such things as strings in Kipple. However, the official interpreter has a preprocessor which translates strings (anything between double quotes) in the code to Kipple statements. <EM>Note that this is a feature of the interpreter, not the language!</EM></P> <P> Example: <CODE>o&lt;"abc"</CODE> will be translated into <CODE>o&lt;97 o&lt;98 o&lt;99</CODE>. <CODE>"abc"&gt;o</CODE> however, will be translated into <CODE>99&gt;o 98&gt;o 97&gt;o</CODE>. In other words, the order in which the characters are pushed onto the stack is depending on which push operator is used. Escape characters are currently not supported. Using the preprocessor, Hello World can be written as simple as this: <CODE>"Hello World!"&gt;o</CODE>
  42. </P>
  43. <!-- P><A HREF="index.html">Back to the Kipple Home Page</A></P -->
  44. <HR>
  45. <P>Copyright (C) 2003 <A HREF="mailto:rune@krokodille.com">Rune Berge</A><BR/>
  46. The Kipple language is licensed under the <A HREF="http://www.gnu.org/copyleft/gpl.html">GNU General Public License</A>.</P>
  47. <!-- H5>Last modified: <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">document.write(document.lastModified);</SCRIPT></H5 -->
  48. </BODY>
  49. </HTML>