MailBox

MailBox is a language based around e-mail filters. A program consists of a series of numbered mailboxes. Each box contains rules. Each rule is associated with a list of actions. When a message is received in a mailbox, the rules are evaluated and if they evaluate to true, the actions are applied.

The syntax for a mailbox is: box NUMBER (rule) actions (rule) actions (rule) actions etc (you can have as many rule/action pairs as you want, but there must be at least one even if it does nothing) NUMBER should be replaced with the mailbox number, which must be a non-negative integer.

Rules
(RULE denotes another rule. INT denotes an integer and STR denotes a "-delimited string)

Rules may evaluate to true even when no message is being received. (eg  or  ) All rules that evaluate to true at the beginning of execution will be processed in the order they are in the source file. If a rule evaluates to true at any other time, it is undefined when the associated actions will be run.

Order of evaluation
Any rules that evaluate to true at the beginning of execution (before any messages were sent) are evaluated in the order they are defined in the source file. Any rules that evaluate to true at any other point in time, except when processing a message, will be executed at an undefined time.

Messages are processed in the order they are sent. For each message, all rules from all mailboxes are evaluated in the order they are defined in the source file and their actions executed if applicable. The number of messages in a mailbox is incremented immediately before the first rule in the mailbox is evaluated.

Control constructs
Infinite loop: box 0 (once) send "loop" to 1 (contains "output") output without "output" box 1 (contains "loop") send "outputHello, world!" to 0 forward to 1

Examples
Hello world: box 0 (once) send "outputHello, world!" to 0 (contains "output") output without "output"

Fibonacci sequence: box 0 // initialisation and code (once) send "empty" to 1 send "empty" to 2 send "add" to 1 send "add" to 2 send "again" to 0 (contains "again") send "empty" to 3 send "read" to 1 send "read" to 2 send "m2ove" to 3 box 1 // 2nd to last (contains "empty") empty (contains "read") delete send count "add" to 3 box 2 // last (contains "empty") empty (contains "read") delete send count "add" to 3 (contains "move") delete send count "add" to 1 empty box 3 // next (contains "move") delete send "empty" to 1 send "move" to 2 send "empty" to 2 send count "add" to 2 output count send "again" to 0 (contains "empty") empty (contains "m2ove") delete send "move" to 3 box 4 // output (contains "1" and not contains "s") output count 1 delete (contains "2" and not contains "s") output count 2 delete (contains "3" and not contains "s") output count 3 delete (contains "s") output without "s" delete

Cat: box 0 (once) send input to 1 box 1 (from 0) output