Eve

From Esolang
Jump to navigation Jump to search

Eve is an event oriented language, which uses a stack for its computations. The only method of control flow is starting events. Events are kept in a queue, and events are run in the order in which they are popped out. Note that any new events will have to wait for all previous events to be run. Execution stops when the event queue is empty. All instructions in Eve are one character long, and any arguments to an instruction must follow it directly.

Instructions

Instruction Arguments Effect
0-9 None Push the number onto the stack.
: Name of event Defines an event with the given name. Note that event names are one character long.
; None Ends an event definition.
+ None Adds the top two stack elements together, and pushes the result.
- None Subtracts the top two stack elements, and pushes the result.
* None Multiplies the top two stack elements together, and pushes the result.
/ None Divides the top two stack elements, and pushes the result.
% None Mods the top two stack elements, and pushes the result.
& None ANDs the top two stack elements together, and pushes the result.
| None ORs the top two stack elements together, and pushes the result.
! None NOTs the top element of the stack.
= None Pushes true or false depending on whether or not the top two stack elements are equal.
> None Pushes true or false depending on whether or not the first value popped is greater than the second.
< None Pushes true or false depending on whether or not the first value popped is less than the second.
I None Pushes the ASCII code of the next char of input.
O None Pops a stack element, and prints it as a char.
$ None Duplicates the top stack element.
@ Name of event to queue Enqueues the event given.
? Two events Pops from the stack. Enqueues the first event if the value is true, the second if the value is false.

Examples

Cat

:LI$01-=?ELO;:E;@L

Or, printed nicely

:L I $ 01- = ?EL O ;
:E ;
@L

Explanation

:L

Define an event named 'L' (it stands for Loop).

I

Get a char of input. Stack: <char>

$

Duplicate it; One copy to maybe be printed, one copy to compare with EOF. Stack: <char> <char>

01-

Stack: <char> <char> -1 Push EOF (-1). There are no negative numbers in Eve, so we have to subtract from zero.

=

Compare the char with EOF. Stack: <char> <char == -1?>

?EL

Queue up the event E (for End) if the char equals EOF, requeue L otherwise. Note that this is not a branch! Flow continues to the end of the event. Stack: <char>

O

Print the character. Stack: (empty)

;

End the definition of 'L'.

:E ;

Define an event named 'E' that does nothing. This will be queued up as an exit to the program.

@L

To start, queue up 'L'.