The Kipple 05 Language Specification


NOTE: This is a work in progress, and may be changed without notice!
Changes in the new revision are marked in red.

The main changes in this version are the new custom stack feature, a relaxed language syntax and the division of language features into Core and Kipple-ized features. The syntax of the language has been made less strict in order to facilitate polyglotting, obfuscation and other bad coding practices.

Kipple is a minimalistic, Turing-complete, stack-based programming language where all data is stored in stacks. There are two levels of Kipple implementations: Core Kipple and Kipple-ized Kipple. A Core implementation implements only the features in the Core features section. A Kipple-ized implementation includes some, or all of the optional features from the Kipple-ized features section. An implementation that includes all Kipple-ized features is called a fully Kipple-ized implementation.

Core features

The values on the stacks are signed integers, with a width of at least 32 bits. The language consists of four operators and one control structure. Each operator takes one or two operands, and an operand can be either a non-negative integer or a stack identifier. Valid stack identifiers are any single ASCII characters in the range #33-#126 (inclusive), except digits. This means that the stacks a and A are not the same, unlike in the previous version of Kipple. Note that allthough an integer operand has to be zero or positive, the stacks can hold negative numbers as well (which can be accomplished by subtraction). All the stacks start out empty, except stack i which will contain the program's input (see Input and Output).

The operators

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. Proper comments using the # character has been removed from the core language, and is now an optional feature.

Operands may be shared between operators. E.g. a>b c>b c? may be written as a>b<c?.

Operators that do not have the proper operands will be ignored. E.g. >a or 2+ . The following code is also valid: >++<- . Here only the three middle operators will be executed. Use operator characters as stack identifiers with caution!

A program that does not contain a single valid operator is not a valid Kipple program, and should generate a compile-time or run-time error.

The control structure

There is only one control structure in Kipple: the loop.

Syntax: (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. 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 (a>b).

Input and output

Before a Kipple program is executed, all input is pushed onto stack i. That means it's impossible to get input during program execution with pure Kipple code. You have to use an external custom stack if you need that. Input is read as a string of bytes.

When a Kipple program ends the contents of stack o are popped to output. The values are written modulo 256. The following program will write its input to output (i.e. cat): (i>o)

The special stack @ has been removed from the language, but can be manually loaded as a custom stack if needed. In the official distribution an implementation of @ is included, named AlphaStack. To make old programs using the @ stack work, add the following line of code: @:"AlphaStack" (or run the interpreter with the -3 option).

Kipple-ized features

These features are optional, and an implementation may choose to implement some or all of them.

Custom stacks

The most important new feature in Kipple 05 is the ability to load custom stacks as code modules for programs. Custom stacks can be another Kipple source file, a library or written directly into the main Kipple program. As a minimum an implementation should support inline custom stacks. The official interpreter supports custom stacks written in Kipple, C (or anything else that can create a library based on a C header) and Java (Java Interface).

Syntax: StackIdentifier:"stack name" or StackIdentifier:{code}
If the custom stack is loaded from a file, the extension should be excluded from the file name. It is up to the interpreter to choose which type of custom stack to use if there are several with the same name available. The reference interpreter will first look for a native library (.so on linux or .dll on Windows) with that name. If a library of that name is not found, it will look for a Java class. If a Java class is not found, it will append .k to stack name, and try to load it as Kipple code.

Examples:

The following code will load hello.k as custom stack !, and use it to output "Hello World!":
!:"hello"
(!>r)(r>o)

The next example will load bubblesort.k and use it to sort a string of characters:
*:"bubblesort"
"caebd">*
(*>r)(r>o)

Comments

Anything between a # and an End-of-line character is removed before execution. ASCII character #10 is defined as End-of-line in Kipple.

Strings

There are no such things as strings in Kipple. However, the string preprocessor feature translates strings (anything between double quotes) in the code into proper Kipple statements before the code is executed.

Syntax: StackIdentifier<"string" or "string">StackIdentifier
This will cause the ASCII value of each character in the string to be pushed onto the stack.

Example: o<"abc" will be translated into o<97 o<98 o<99. "abc">o however, will be translated into 99>o 98>o 97>o. 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: "Hello World!">o

Debug operators

Implementations may add operators for debugging purposes. The reference implementation has the following debug operators:

Back to the Kipple Home Page


Rune Berge - 2005
The Kipple language is released to the public domain.

Last modified: