--yay
--yay is a stack-based esoteric programming language created with the goal of creating an esoteric programming language (I know, very impressive, especially for an esoteric programming language). It was made to be an easier-to-use, stack-based version of brainfuck.
Concepts
There are two forms of data storage in --yay. The stack and the register:
The stack
The stack is a standard stack, a last-in, first-out data structure that can only store numbers.
The register
The register is a spot that can store a single number. The most important commands operate on the register, so it is a key component of the language.
Commands/Instructions
--yay has 15 instructions in total. These are:
- +: increments the top of the stack
- -: decrements the top of the stack
- p (lowercase letter p): pushes the value stored in the register onto the stack.
- P (uppercase letter P): pops a value off the stack and stores it in the register.
- J (uppercase letter J): pops x off the stack and jumps to location x (zero-indexed) of the code
- # (octothorpe): starts a literal
- ; (semicolon): ends a literal
- 0-f: Contribute to the literal a.k.a #41; (inspired by HTML escape sequences) will store the value 65 into the register
- ?: checks the value stored in register. If it's zero, the program will skip execution of the next command
- : (colon): duplicates the value at the top of the stack
- . (dot): same as brainfuck, but operating on the top of the stack
- , (comma): same as brainfuck, but operating on the top of the stack
- o (lowercase letter o): pops the top of the stack and outputs it as a number
- i: gets input as a number and stores it into the register
- q: halts the program
Examples
Hello, world!
This gets the ASCII values for the characters Hello world! into the register, pushes them onto the stack and prints them out. The l in Hello is pushed onto the stack, duplicated, and printed out twice.
#48;p. #65;p. #6c;p:.. #6f;p. #20;p. #77;p. #6f;p. #72;p. #6c;p. #64;p. #21;p.
truth-machine
This program skips the jump instruction if the input is not zero (I cannot remember how it works, I am just copying the description from my notes)
#12;pi ?J #0; poq #1;po #12;pJ
Implementations
Feel free to add more implementations if you wish!
Python (original implementation)
import sys def makeLiteral(): global index global register global char index += 1 char = code[index] number = char while (index := index + 1) < len(code): char = code[index] if char == ';': break number += char register = int(number, 16) with open(sys.argv[1], 'r') as f: code = f.read() stack = [] register = None index = -1 while (index := index + 1) < len(code): char = code[index] if char == '+': stack[-1] += 1 elif char == '-': stack[-1] -= 1 elif char == 'p': stack.append(register) elif char == 'P': register = stack.pop() elif char == '#': makeLiteral() elif char == '?': if register == 0: index += 1 elif char == ':': stack.append(stack[-1]) elif char == '.': print(chr(stack.pop()), end='') elif char == ',': i = sys.stdin.read(1) register = ord(i) elif char == 'o': print(stack.pop(), end='') elif char == 'i': register = int(input()) elif char == 'J': x = stack.pop() index = x - 1 elif char == 'q': exit()