We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Symmetry

From Esolang
Jump to navigation Jump to search

Symmetry is an esoteric programming language designed under the observation that most traditional languages use Hashmaps to store data, but that this practice is more for programmer's convenience than for necessity (see: any other esolang ever, where the data model is anything but a hashmap).

Idea

Most traditional languages use hashmaps to store data; that is, a key→value pair. Symmetry, on the other hand, uses a Wikipedia:Bidirectional map, or hashbag, to store its data; that is, key↔key pairs. This means, essentially, that bm[k]=v↔bm[v]=k (the arrow there being "iff" in this case, not the earlier-used key↔key syntax). This leads to a few interesting properties; for example, that the assignment expression x=y is logically equivalent to y=x.

Syntax

The syntax of Symmetry is fairly trivial; it looks quite like a normal language (as one of the common reasons esolangs look abnormal is that they're dealing with a strange data model, which we are not here). Note that all syntax is tentative; none of it will necessarily stay for long, until the author feels it is complete.

Tokenization

Regex Tag Feature name
^[\s]+ NULL Whitespace is ignored.
^"[^"\\]*(?:\\.[^"\\]*)*" STR Strings are enclosed in double quotes, but may have double quotes inside them backslash-escaped
^[0-9]+(\.[0-9]+)? NUM Numbers are both floating-point and integers; they are of the most traditional of syntaxes
^= ASSGN Assignment: One of the must integral parts of languages, especially symmetry
^(\+|\*|-|/|%|&|\||^|<=|>=|<|>|==) OP Operators are useful. Arithmetic (including modulus), boolean, relational.
^[{}()[\]] BRACK Curly brackets close of blocks, parentheses group expressions, and square brackets are reserved in case I ever feel like using them
^[a-zA-Z_][a-zA-Z0-9_]* NAME Identifiers. Really just used for functions; can't be used in assignment.
^, NAME
^IF IF Conditionals
^ELSE ELSE Failure conditionals
^WHILE WHILE Loop-de-loop

Grammar

value  ::= STR | NUM ;
pexp   ::= "(" exp ")" ;
fexp   ::= NAME "(" [{exp ","} exp] ")"
exp    ::= fexp | pexp | value OP value ;

ifthen ::= "IF" exp "{" {stmt} "}" {"ELSE" ifthen} ["ELSE" "{" {stmt} "}"] ;
while  ::= "WHILE" Exp "{" {stmt} "}" ;
stmt = while | ifthen | exp