Klaus

From Esolang
Jump to navigation Jump to search

Klaus is an esoteric programming language made by Areallycoolusername. It was made to be highly capable, with control flow, variables, and 3 instructions, in order to make a small interpreter for it in Motorola 68000 Assembler, and to induce highly condense programs. Believe it or not, this language was inspired by the inner workings of a shotgun.

Instructions

Instruction Function
O Outputs value
I Inputs value
LO Loads value into register

Specifics

Klaus programs are in the form of "tracks". A track is a subroutine consisting of 2 or less lines. There can be many of them in one program. They are called tracks since they will be repeated indefinitely unless given a conditional return value.Semicolons are used to separate statements on the same line, in order to eliminate the need for spaces. However, spaces are allowed. A track has this syntax:

TrackName:statements;condition;Bool:R:INT!

Where the TrackName is the name of the track, statements are the statements used in this track, condition is the condition that the track will return an integer value. Bool can be either true or false, R: means "return". In this track, R: is used to return an INTeger value. The exclamation point ends the track. Take this as an example:

track1:LOq,2O;Oq;??equ:q,20;1:R,0!

We can break this down into parts.

track1:

is the name of our track. It includes a colon in order to separate it from the track itself, and to improve clarity. A track name must always precede a track, or it will return an error.

LOq,20;

is our use of the LO command. It loads the integer value 20, into the register, "q". The LO instruction has this syntax:

LO registername,value;

Where registername is the name of our register (registers can be either letters A-Z or a-z, nothing else), and value is the interpreter value placed in the register.

Oq;

is our use of the "O" instruction. This is where we print the value held in register "q". The instruction is followed by a semi-colon.

??equ:q,20

is our use of the if statement. This is initialized by a double question mark (if statements contained in other if statements are initialized by a singular question mark).The condition is ended by a semi-colon.

1:R,0!

is the body of the if statement. It's initialized by the boolean, 1, which means true. On the other hand, the boolean, 0, means false, and is the equivalent to the else statement in other languages. This boolean is ended by a colon, which initializes the rest of the body. R, as said before, means return, and it returns the integer value 0. The entire track is ended with an exclamation point. This program prints the integer, 20.

Loops

Loops in this language are simple. Here is the syntax for a while loop.

~condition: statements;^

The Tilde initializes the loop, and is followed by a condition to check for. The statements are executed while the condition is true, and halted, when false.The "^" ends the loop. Here is the syntax of a for loop.

#var,condition,action; statements;^

Where var, is a value stored in a register temporarily (temporarily, since the register will be cleared once the loop is done. Followed by the condition to check for, and the action to take if true. This action can be the incrementation of the variable or its decrementation. Here is an example of a while and for loop

WhileLoop:LOa,1;~equ:a,1;Oa;a++;^??equ:a,2;1:R,1!

ForLoop:#LOb,0,less:b,3,b++;Ob;b++;^??equ:b,3;1:R,0!

The while loop should output 1, while the for loop should output 0,1, and 2. These examples feature some keywords and actions not covered before. These are the "less" key word and the incrementation and decrement signs. The less keyword checks if the first argument is less than the second. Similarly, the more keyword checks if the first argument is more than the second. The increment and decrement sign, "++" and "--", lowers or raises the value by 1. It must always be used next to a variable, and must be ended by a semi-colon.

Hello World Program

HelloWorld:LOh,2;O'H';O'e';O'l';O'l';O'o';O',';O' ';O'w';O'o';O'r';O'l';O'd';O'!';??equ:h,2;
1:R,69!

Computational class

It is Turing-complete, as it can compile to 3-celled brainfuck without I/O. x here represents any register.

+       : x++
-       : x--
< and > : Switch around the currently-operating registers
[...]   : ~more:x,0;commands;^