Zalgo

From Esolang
Jump to navigation Jump to search

Zalgo is a stack-based, esoteric programming language developed by User:Short c1rcuit. The language operates on clusters of combining diacritical marks. The language is named after Zalgo text.

Description

A Zalgo program is made of clusters of characters. A cluster consists of 3 parts:

The centre character

The centre character is the character that the diacritics are put on. The centre characters have no instructions which means that they can be any character not in the Combining Diacritical Marks unicode block. Note: whitespace characters are stripped in parsing so any diacritics placed on them will be treated as part of the previous cluster. If there is no previous cluster then they will be ignored.

The top diacritics

The top diacritics are any character in the Combining Diacritical Marks unicode block that appears above the base character. An important thing to consider when writing Zalgo code is that the top diacritics are added from the inside out. However, the interpreter reads the diacritics from top to bottom. Therefore, all of the top diacritics must be added in reverse order of execution.

The bottom diacritics

The bottom diacritics are any character in the Combining Diacritical Marks unicode block that appears below the base character.

Instructions

Top side instructions

Character Unicode Number Description
◌̀ - ◌̏ U+0300 - U+030F Represents the hex digits `0 - F`.
◌̐ U+0310 Pushes the hex value to the stack. If no hex value is given, it will push 0.
◌̑ U+0311 Pops the top value off the stack.

The interpreter treats hex digits that are next to each other as one single hex number.

Bottom side instructions

Program flow
Character Unicode Number Description
◌̥ U+0325 Pops a value off the stack, if it's 0, skip the next cluster.
◌͍ U+034D Pops a value off the stack and jumps to the nth cluster (0 indexed).

This will immediately cause the program to jump and thus any remaining instructions in the cluster will be ignored.

IO
Character Unicode Number Description
◌̝ U+031D Pops a value off the stack and prints its Unicode value.
◌̞ U+031E Takes the first character from the input buffer and pushes it to the stack

Input works with a buffer. If the buffer is empty, the user is prompted to input something to set the buffer to before the process continues. All inputs have a null byte added to the end.

Arithmatic
Character Unicode Number Description
◌̟ U+031F Pops a value off the stack X and another Y, push X+Y.
◌̠ U+0320 Pops a value off the stack X and another Y, push the absolute difference of X and Y.
◌͓ U+0353 Pops a value off the stack X and another Y, push X*Y.
◌̡ U+0321 Pops a value off the stack X and another Y, push Y/X (rounded down).
◌̢ U+0322 Pops a value off the stack X and another Y, push Y%X.
Bitwise operations
Character Unicode Number Description
◌̭ U+032D Pops a value off the stack X and another Y, push X∧Y.
◌̬ U+032C Pops a value off the stack X and another Y, push X∨Y.
◌͉ U+0349 Pops a value off the stack X and inverts the significant bits.
◌̜ U+031C Pops a value off the stack X and another Y, push Y << X.
◌̹ U+0339 Pops a value off the stack X and another Y, push Y >> X.
Comparisons
Character Unicode Number Description
◌̳ U+0333 Pops a value off the stack X and another Y. Push 1 if X == Y or 0 otherwise.
◌͕ U+0355 Pops a value off the stack X and another Y. Push 1 if Y > X or 0 otherwise.
◌͔ U+0354 Pops a value off the stack X and another Y. Push 1 if Y < X or 0 otherwise.
Misc
Character Unicode Number Description
◌͈ U+0348 Duplicates the top value of the stack.
◌̙ U+0319 Pops a value off the stack X and another Y. Cycle the top Y elements of the stack up by X
◌̘ U+0318 Pops a value off the stack X and another Y. Cycle the top Y elements of the stack down by X

Examples

Hello, world!

A̝̝̝̝̝̝̝̝̝̝̝̝̝̐̈̄̐̅̆̐̌̆̐̌̆̐̏̆̐̌̂̐̀̂̐̇̇̐̏̆̐̂̇̐̌̆̐̄̆̐́̂

Actually visible version

Top set:
◌̐◌̈◌̄◌̐◌̅◌̆◌̐◌̌◌̆◌̐◌̌◌̆◌̐◌̏◌̆◌̐◌̌◌̂◌̐◌̀◌̂◌̐◌̇◌̇◌̐◌̏◌̆◌̐◌̂◌̇◌̐◌̌◌̆◌̐◌̄◌̆◌̐◌́◌̂

Bottom set:
◌̝◌̝◌̝◌̝◌̝◌̝◌̝◌̝◌̝◌̝◌̝◌̝◌̝

Pushes the characters onto the stack in reverse order then prints them all.

Cat

C̞͈̥a͍̐̃t͍̐̅P̝r͍̐

Equivalent to:

input, duplicate, if
3, push, jump
5, push, jump
print
push, jump

String to Number

S̐t̞͈̥r͍̐̄T͍̐̈o̠̐̀̃N̙̐́̐̂u͓̟̐̊m͍̐́#̝̑

Takes in a string representation of a number and outputs it's unicode representation.

Equivalent to:

push
input, duplicate, if
4, push, jump
8, push, jump
48, push, sub
2, push, 1, push, cycle up
10, push, multiply, add
1, push, jump
pop, push

Number to String

#̞̐́N͈u̢̐̊m̟̐̀̃b̙̐́̐̃e̡͈̥̐̊r͍̐̈T͍̐̌o̙̐́̐̂S̟̐́t̙̐́̐̂r͍̐́ȋn̙̐́̐̂g̝#̠͈̥̐́#͍̐̍

Takes a character as an input and outputs the unicode number of the character

Equivalent to:

1, push, input
dup
10, push, mod
48, push, add
3, push, 1, push, cycle up
10, push, div, dup, if
8, push, jump
12, push, jump
2, push, 1, push, cycle up
1, push, add
2, push, 1, push, cycle up
1, push, jump
pop
2, push, 1, push, cycle up
print
1, push, sub, dup, if
13, push, jump

External resources