FAKE

FAKE is a stack-based esoteric programming language, inspired by FALSE and Forth. It is designed to be portable, usable, though hard to write programs in. Name is a reference to FALSE programming language and also means something that is not true.
==Virtual FAKE machine==
FAKE programs are executed by virtual machine, which has two stacks and data space. One stack is used for keeping numbers during computation and passing parameters to subroutines ("data stack" or just "the stack"), another is for keeping return addressess while calling subroutines ("return stack"). Data space is a random-access array of machine words.
==Syntax==
FAKE program is a stream of printable ASCII characters, which are interpreted as single char commands. Literals are represented by consecutive decimal digits, which execution result in pushing a corresponding number on the stack. Literals can be delimited by any non-digit character. Characters which are neither digits nor commands are ignored.
===Commands===
Forth-like stack diagrams for groups of commands are provided (n is for number, ? is for boolean: 0 is false, -1 is true).
* + - * / ( n1 n2 -- n3 ) - take two numbers from top of data stack, perform corresponding arithmetic operation and push result back on the stack
* _ ( n1 -- n2 ) - sign inversion, changes sign of topmost item on the stack
* & | ^ ( n1 n2 -- n3) - binary bitwise operations: AND OR XOR
* ~ ( n1 -- n2 ) - bitwise NOT
* < = > ( n1 n2 -- ? ) - comparison operations: less than, equal to, greater than
* $ ( n -- n n ) - DUPlicate topmost item on the stack
* \ ( n1 n2 -- n2 n1 ) - SWAP two items on top of the stack
* @ ( n1 n2 n3 -- n2 n3 n1 ) - ROTate three items on top of the stack clockwise
* % ( n -- ) - DROP item from top of the stack
* [ ( -- n ) - define of a subroutine: skip symbols to the corresponding ']' and push number identifying the new subroutine on the stack, continue execution after ']'
* ] ( -- ) - return from subroutine
* ! ( n -- ) - execute subroutine identified by item on top of the stack
* ? ( ? n1 n2 -- ) - conditional operator; if 3rd item on top of the stack is non-zero execute subroutine from n1, else execute subroutine n2
* # ( n1 n2 -- ) - loop operator; execute subroutine 'n1'; if it leaves non-zero item on top of the stack, execute subroutine 'n2'; repeat
* ` ( ... n -- ... ) - system call; execute system-dependent function identified by number on top of the stack, other stack effects depend on function called
* . ( n -- ) - print out topmost item of the stack as a signed decimal integer followed by a blank
* , ( -- n ) - read character from input stream and push its code on the stack (-1 is EOF)
* ' ( n -- ) - EMIT character with code 'n' to output stream
* " ( -- ) - print string till the next double quotes
* : ( n1 n2 -- ) - store number 'n1' to data space cell 'n2'
* ; ( n1 -- n2 ) - fetch number from data space cell 'n1' and push it to the stack
==Examples==
Copy input to output
 [,$1_=~][']#%
Print first 25 Fibonacci numbers
 25 0 1[@$][1-@@$.$@+]#%%%
Print all "8 queens" puzzle solutions
 [$@@16;![$7=[%17;!][1+18;!]?][%]?]10:
 [15;!12;!@@15;!13;!@@14;!||]11:
 [;\;=]12:
 [15;!;@\-\;@\-=]13:
 [15;!;@+\;@+=]14:
 [\$@$@\]15:
 [$8::0 9:0[9;8;<][8;9;11;!|9;1+9:]#0=]16:
 [0[$8<][$;.1+]#%10']17:
 [0[$8<][15;!\10;!1+]#%%]18:
 0 18;!
Category:Languages
Category:Stack-based
Category:Low-level
Category:Unimplemented