untitled





The 0x29A Programming Language

0x29A is a purely functional imperative programming language. You may be thinking, "WTF? How can a purely functional programming language also adhere to the imperative pragramming language paradigm?" Actually, it doesn't, but instead occupies its own programming paradigm: dysfunctional programming.

0x29A uses one (1) register, which can store one byte (initially zero), two (2) variables, a and b, each of which can store one function, and one (1) stack (initially empty), which may contain any number of functions. The elementary functions are s, k, ., ,, +, and -. All other functions are of the form (xy) (x applied to y), where x and y are functions.

All instructions are executed in order from left to right. After each instruction is executed, the interpreter checks to see if the top of the stack needs to be evaluated. If it does, it evaluates the top of the stack. It then repeats this until the function on top of the stack no longer needs to be evaluated.

Instruction Set:
The following characters are instructions. Any other character is a comment, not an error.
s = Push the s function to the top of the stack.
k = Push the k function to the top of the stack.
. =
Push the . function to the top of the stack.
, = Push the , function to the top of the stack.
+ = Push the + function to the top of the stack.
- = Push the - function to the top of the stack.
[ = If the register's value is 0, go forward to the corresponding ]. If there is no corresponding ], end the program.
] = If the value of the register is not equal to 0, go back to the corresponding [. If there is no corresponding, go to the first character in the source file.
% =
Pop the stack once and store the function popped off the stack in a. Then pop the stack again and store the function popped off the stack in b. Then push a, then b, to the top of the stack. Popping an empty stack always returns ((sk)s), the identity function.
~ = Pop the stack once and store the function popped off the stack in a. Then pop the stack again and store the function popped off the stack in b. Then push (ba) to the top of the stack. Popping an empty stack always returns ((sk)s), the identity function.

Evaluating Functions:
X, y, and z here refer to three not-necessarily-different functions.
Functions are evaluated as follows:
If the top of the stack is (((sx)y)z), pop the stack and push ((xz)(yz)).
If the top of the stack is ((kx)y), pop the stack and push x.
If the top of the stack is ((.x)y), pop the stack and push x. Then output the value of the register as an ascii character and set the register's value equal to 0.
If the top of the stack is ((,x)y), pop the stack and push x. Then get one character of input and replace the register's value with that character's ascii value.
If the top of the stack is ((+x)y), pop the stack and push x. Then increment the register.
If the top of the stack is ((-x)y), pop the stack and push x. Then decrement the register.

All other functions remain on the stack without being evaluated.

Implementations:
Writing an implementation of 0x29A is left as a challenge to the reader.
This Website Built and Hosted for Free at Bravenet.com

Web Hosting · Blog · Guestbooks · Message Forums · Mailing Lists
Allwebco Web Templates · Build your own toolbar · Accept Credit Cards · Audio, Fonts, Clipart
powered by a free webtools company bravenet.com