Switchy

From Esolang
Jump to: navigation, search

Switchy is an esoteric programming language created by User:Poolala, which changes an instruction's operation every program cycle.

The program stack is also reversed every cycle.

There is a binary variable called flip, which starts out at 0, and flips its value every cycle.

Instructions

Instruction Description
(foo) Creates a label called foo (doesn't trigger a cycle)
[foo] Jumps to the label foo if the top stack element is nonzero if flip is 0, else jump if zero (doesn't trigger a cycle)
# Adds the top two stack elements, pops them, and pushes the sum if flip is 0, else subtract if flip is 1
* Pushes a 1 onto the stack if flip is 0, else pop a value from the stack
' Inputs a character and pushes it onto the stack if flip is 0, else output the top stack value

Finite State Automaton

Switchy is not Turing complete and acts as a Finite-state automaton.

State Flip State After * State After ' Description
Empty 0 A B Stack is empty(This is also the starting point)
A 1 Empty Empty(Output 1) Stack contains a single 1
B 1 Empty Empty(Output the input from ') Stack contains a single character

Note: because none of the states result in a stack of size two or more, a # can not be used.

Implementation

An implementation in Ruby by User:OriginalOldMan can be found on Talk:Switchy.