SideStacks
Jump to navigation
Jump to search
SideStacks is a Stack-Based programming language made by User:Myoitzi housing two stacks and two 8-bit registers.
Instruction set
SideStacks uses a multitude of Single-character instructions, similar to brainfuck. A list of instructions is provided below:
Command | Description |
---|---|
^
|
Increment the "A" register. |
v
|
Decrement the "A" register. |
<
|
Push the value of the "A" register to the selected stack and set "A" to 0. |
>
|
Pop the topmost value of the selected stack to "A". |
+
|
Pop the topmost value of the selected stack and add it to "A". |
-
|
Pop the topmost value of the selected stack and subtract it from "A". |
s
|
Swap the values of the "A" register with the "B" register and vice versa. |
b
|
Duplicate the value of the "A" register and store it into the "B" register. |
.
|
Print the "A" register as a decimal number. |
@
|
Print the "A" register as an ASCII character. |
;
|
Take an integer input and store it into "A". |
:
|
Take an ASCII input and store it's corresponding value into "A". |
0
|
Set "A" to 0. |
(
|
Jump past corresponding parentheses if "A" is 0 (similar to [ in brainfuck).
|
)
|
Jump back to the corresponding parentheses if "A" is nonzero (similar to ] in brainfuck).
|
[
|
Jump past corresponding parentheses if the "A" is nonzero. |
]
|
Jump back to the corresponding parentheses if "A" is 0. |
{
|
Jump past corresponding parentheses if the "A" is equal to "B". |
}
|
Jump back to the corresponding parentheses if "A" is not equal to "B". |
f
|
Flip selected stack. |
Any character not in this table will be ignored
Examples
Hello World!:
^^^^b<s+b<s+b<sb<sb<s+++^^^^^^^^@b<s<^^^b<s+^b<s+b<s+^+@^^^^^^^@ @^^^@0^^^^b<s+b<s+b<s+@0^^^^b<s+b<s+v+@<^^^^b<s+b<sb<s+++@^^^@vv vvvv@vvvvvvvv@0^^^^b<s+b<s+b<s+^@
Cat:
:@
Truth Machine: (Note: will repeat for any nonzero value)
;(.).
99 Bottles of Beer
^^^^^^^^^^^b<sb<s++b<sb<s++f<f^^^^^^^^b<s+b<s+b<sb<s++<f>(.<f>b<s^^@>b<s<^^^^^^^^b<s+v+@^^^^^@@>b<s<^^^^^^^^^^^^+@vvvvv vv@<^^^^^^^b<s++@0^^^^^^^^b<s+b<s+@>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@^^^@@<^ ^^^b<sb<s+++^@0^^^^^^^^b<s+b<s+@>b<s<^^^^^^^^b<s+v+@v@0^^^^^^^^b<s+b<s+@>b<s<^^^^^b<s+b<s++@vvvvvvvvvvvv@vvv@0^^^^^^^^b <s+b<s+@>b<s<^^^^^^^b<sb<s+++^^@>b<s^@v<^^^^b<sb<s+++@@0^^^^^^^^b<s+b<s+^@0^^^^^b<s+@0^^^^^b<s+@f>)
Implementation
Python 3:
stack = [] stack2 = [] a = 0 b = 0 sp = 1 ins = ':@' i = 0 debug = False while i < len(ins): if ins[i] == 'd': if debug == False: debug = True else: debug = False elif ins[i] == '^': a += 1 if debug == True: print(f'\na = {a}') elif ins[i] == 'v': a -= 1 if debug == True: print(f'\na = {a}') elif ins[i] == '<': if sp == 1: stack.append(a) else: stack2.append(a) a = 0 if debug == True: print(f'\nStack: {stack}') print(f'\nStack2: {stack2}') elif ins[i] == '>': if sp == 1: a = stack.pop() else: a = stack2.pop() if debug == True: print(f'\na = {a}') print(f'\nStack: {stack}') print(f'\nStack2: {stack2}') elif ins[i] == '+': if sp == 1: a += stack.pop() else: a += stack2.pop() if debug == True: print(f'\na = {a}') print(f'\nStack: {stack}') print(f'\nStack2: {stack2}') elif ins[i] == '-': if sp == 1: a -= stack.pop() else: a -= stack2.pop() if debug == True: print(f'\na = {a}') print(f'\nStack: {stack}') print(f'\nStack2: {stack2}') elif ins[i] == '.': print(a, end=' ') elif ins[i] == '@': print(chr(a), end="") elif ins[i] == 'b': b = a elif ins[i] == 's': stack.append(a) a = b b = stack.pop() elif ins[i] == ';': print() a = int(input('> ')) elif ins[i] == ':': print() a = ord(input('> ')) elif ins[i] == '0': a = 0 elif ins[i] == ')': if a != 0: i -= 1 loop = 1 while loop > 0: if ins[i] == ')' or ins[i] == ']' or ins[i] == '}': loop += 1 i -= 1 elif ins[i] == '(' or ins[i] == '[' or ins[i] == '{': loop -= 1 if loop != 0: i -= 1 else: i -=1 elif ins[i] == ']': if a == 0: i -= 1 loop = 1 while loop > 0: if ins[i] == ')' or ins[i] == ']' or ins[i] == '}': loop += 1 i -= 1 elif ins[i] == '(' or ins[i] == '[' or ins[i] == '{': loop -= 1 if loop != 0: i -= 1 else: i -=1 elif ins[i] == '}': if a != b: i -= 1 loop = 1 while loop > 0: if ins[i] == ')' or ins[i] == ']' or ins[i] == '}': loop += 1 i -= 1 elif ins[i] == '(' or ins[i] == '[' or ins[i] == '{': loop -= 1 if loop != 0: i -= 1 else: i -=1 elif ins[i] == '(': if a == 0: i += 1 loop = 1 while loop > 0: if ins[i] == '(' or ins[i] == '[' or ins[i] == '{': loop += 1 i += 1 elif ins[i] == ')' or ins[i] == ']' or ins[i] == '}': loop -= 1 if loop != 0: i += 1 else: i +=1 elif ins[i] == '[': if a != 0: i += 1 loop = 1 while loop > 0: if ins[i] == '(' or ins[i] == '[' or ins[i] == '{': loop += 1 i += 1 elif ins[i] == ')' or ins[i] == ']' or ins[i] == '}': loop -= 1 if loop != 0: i += 1 else: i -=1 elif ins[i] == '{': if a == b: i += 1 loop = 1 while loop > 0: if ins[i] == '(' or ins[i] == '[' or ins[i] == '{': loop += 1 i += 1 elif ins[i] == ')' or ins[i] == ']' or ins[i] == '}': loop -= 1 if loop != 0: i += 1 else: i +=1 elif ins[i] == 'f': if sp == 1: sp = 2 else: sp = 1 while a > 255 or a < 0: if a >= 256: a %= 256 elif a < 0: a = (a % 256)+256 i += 1