Eval

From Esolang
Jump to navigation Jump to search

Eval is a stack-based esolang by User:PythonshellDebugwindow.

Memory

Eval uses two stacks, the left stack and the right stack, as well as a stack pointer, which can point to either of the stacks at any one time. The stacks can hold strings and integers.

Syntax

Eval programs are made up of characters, each one representing a command, except in stringmode and charmode, where characters are pushed to the current stack until another " is reached.

Commands

Normal mode commands (pop/push X means pop/push X from the current stack):

Command Meaning
~ Switch the stack pointed to by the stack pointer
` Push 1 if the stack pointer is pointing to the left stack, else push 0
^ Pop A, push A, push A again
0 Push 0
+ Pop A, push A + 1
- Pop A, push A - 1
* Reverse the current stack
? Pop A, skip the next instruction if A is falsy (0 or the empty string)
! Pop A, evaluate A as Eval code
" Toggle stringmode
' Same as ", but double quotes are prepended and appended to the resultant string
. Pop A, output A
; Pop A
= Pop A, push A to the non-current stack

In stringmode, a string variable res is initialized to the empty string. Then for each character c, the ` backquote character appends the " double quote character to res, the " double quote character exits stringmode, and all other characters append themselves to res. When stringmode is exited (or on EOF if stringmode is not ended), res is pushed to the current stack.

Examples

Hello, World!

"Hello, World!".

Infinite loop

"^!"^!

Truth-machine

Replace the second 0 (bolded) with 0+ for input 1.

"0+.^!"^0?!0.

Implementations

A Python interpreter by User:Bangyen.