Underchaos

From Esolang
Jump to navigation Jump to search

Underchaos is a self-modifying, stack-based, string-rewriting esoteric programming language based on Underload.

Execution

Instructions
(...)[...] Push replacement into the stack.
: A > A, A
^ Pop replacement and do it.
a A > ()[A]
* (A)[B], (C)[D] > (AC)[BD]
~ A, B > B, A
` (A)[B] » (B)[A]
Replacement symbols
_ Any string of characters
@ EOF symbol
' Pointer
\ Next symbol is used as outside of the replacement.

The program halts when the pointer goes on EOF.

The replacement (A)[B] is performed by replacing first found instance of A by B, starting at the pointer. Both the pointer and EOF have got special symbols to represent them.

Examples

Pop and discard

Note that there's no instruction for discarding the top of the stack; it's because it can be did using the following code:

a:`*^

It does the following:

A
  • Wraps top of the stack with a replacement:
()[A]
  • Duplicates top of the stack:
()[A] ()[A]
  • Swaps two sides of the top replacement:
()[A] (A)[]
  • Merges two top replacements:
(A)[A]
  • Does the replacement:

If A isn't found in the program, it does nothing. If A is found in the program, it's replaced by itself, so does nothing.