ESON

From Esolang
Jump to navigation Jump to search

ESON is an Esoteric Knowledge Representation Format designed to be so easy to parse it melts Nazis' faces and burns out their eyes. The acronym "ESON" actually isn't an acronym, because it doesn't stand for anything. The language features Reverse Polish Notation and numeric literals in many bases.

Design

ESON is a stack-based language for encoding a generalization of JSON-like data in a simple way. It allows for Lists, Sets, Tuples, Maps, Ordered Maps, Symmetric Maps, Binary Trees, General Trees, and optionally graphs. Being a stack-based language, the commands are almost entirely procedural. It is not Turing-complete, nor is Turing completeness even applicable to it, the same way TCness is inapplicable to XML.

Lexing and Parsing

Lexing ESON can be done by simply splitting it by spaces. Parsing is done with a FOR loop iterating through the commands and executing them.

Commands

Command Meaning
/[0-9_]+/ Push an integer (_ meaningless, can be used to separate digit groups)
/0b[01_]+/ Push an integer encoded in binary (_ meaningless, can be used to separate digit groups)
/0q[0-3_]+/ Push an integer encoded in quaternary (_ meaningless, can be used to separate digit groups)
/0o[0-7_]+/ Push an integer encoded in octal (_ meaningless, can be used to separate digit groups)
/0x[0-9a-fA-F_]+/ Push an integer encoded in hexadecimal (_ meaningless, can be used to separate digit groups)
/[0-9](\.[0-9]+)? Push a float
/"[^\s]*/ Push a string delimited by the " and a space. Spaces encoded with %20, newlines with %0A, tabs with %09, vertical tabs with %0B and percent signs with %25.
/\(,*\)/ Create a tuple with len(com)+1 items by popping those items from the stack.
[] POP an integer n, POP n items, PUSH the list composed of those items in the order they were popped.
{} POP an integer n, POP n items, PUSH the set of those items
{:} POP an integer n, POP n 2-tuples, PUSH a dict mapping each first item in a 2-tuple to its second item
[:] POP an integer n, POP n 2-tuples, PUSH an ordered dict mapping each first item in a 2-tuple to its second item
{<=>} POP an integer n, POP n 2-tuples, PUSH a symmetric dict mapping each item in the pairs to their partner in a symmetric dict
_ PUSH a binary tree with no nodes.
.. POP an item, POP a 2-tuple of binary trees, PUSH a binary tree with the item at the root, with the trees as the left and right subtree respectively.
... POP an item, POP a list of ordered trees, PUSH an ordered tree with the item at the root, leading to the other trees as subtrees.
*:* POP a list of 2-tuples where the first part of the tuple is an item and the second is a set of integers, PUSH a directed graph, where each vertex contains an item, and points to the vertices whose list indices were contained in the corresponding set.
*<=>* POP a list of 2-tuples of items and sets of integers, PUSH an undirected graph, where each vertex contains an item, and joins to the vertices whose list indices were contained in the corresponding set.

See also