CYOA

From Esolang
Jump to navigation Jump to search

Overview

CYOA is a stack based semi-2d esolang. Operates on two stacks of bits, the first initialized with input (or empty if no input is given), the second starting empty. Popping an empty stack halts.

Instructions

stack:

1: push a 1

0: pop a bit

%: flip the top bit

$: pop and print a bit

#: switch stacks

control flow:

_: (branch) if the top of the stack is 0, move the pointer down to the next line instead of to the next instruction. program flow continues either left or right based on which direction continues to have stack instructions. if neither or both do, its a syntax error and the program does not run. having a _ directly below another _ is also a syntax error

space/newline/eof: if the stack is empty, halt. otherwise, while the top of the stack is 1, pop a bit and return to the previous _. once the top of the stack is no longer 1, take the opposite path on the branch from what was taken last time (i.e. if you went down that branch, continue horizontally, but if you went horizontally, go downward). if there is still a 1 on top of the stack upon reaching the first _, pop it, move to the start of the program, and resume normal execution.

anything else: comment, replaced with a space at runtime

interpreter that may or may not be shit

https://replit.com/@thejonymyster/cyoa#index.js