Old page wikitext, before the edit (old_wikitext) | ''''MAWP''' is a stack-based [[esoteric programming language]] that was made in 2020.
==Language Overview==
===Version 0.0===
'''MAWP''' works on an integer stack, starting with an initial value of 1. The base operators are:
Any single-digit integer pushes that integer to stack.
M takes top two values of the stack and sums them. [3,2,1] ==> [3,3]
A takes top two values of the stack and subtracts the first from the other. [3,2,1] ==> [3,1]
W takes top two values of the stack and multiplies them. [3,2,1] ==> [3,2]
P takes top two values of the stack and floor divides the second by the other. [3,2,1] ==> [3,2]
% pops top of stack. [3,2,1] ==> [3,2]
! duplicates top of stack. [3,2,1] ==> [3,2,1,1]
: prints top of stack without newline, removing it. [3,2,1] ==> [3,2] (STDOUT:1)
; prints top of stack as ascii char without newline, popping it. [3,2,72]==> [3,2] (STDOUT:H)
. terminates program
[ start of loop
] end of loop. If top of stack doesn't equal to 0, then moves back to start of loop. (inspired by [[brainfuck]])
? conditional. If top of stack doesn't equal to 0, skips next operator.
| reads a character off STDIN and pushes its ascii value. NOTE:integers still get pushed according to ascii value, not actual integer value.
===Version 0.1===
'''MAWP 0.1''' introduces several new features, and changes a couple old ones:
~ reverses stack [3,2,1] ==> [1,2,3]
[ now also jumps to its ] if top of stack equals to 0
( start of inverted [] loop. Jumps to its ) if top of stack doesn't equal to 0
) end of inverted [] loop. Jumps to its ( if top of stack equals to 0
< long conditional. If top of stack doesn't equal to 0, jumps to its >
> end of long conditional
A now gives the absolute value of the difference
| now pushes whole input byte by byte, not only the first one
_ pushes length of stack [3,2,1] ==> [3,2,1,3]
==Interpreter==
Currently, the only online interpreter available for '''MAWP 0.1''' is hosted on [https://8dion8.github.io/ This page]
However, this is an offline script written in python 3.8:
#Ver 0.1
from time import sleep
def buildsquarebracemap(code):
temp_bracestack, bracemap = [], {}
for position, command in enumerate(code):
if command == "[": temp_bracestack.append(position)
if command == "]":
start = temp_bracestack.pop()
bracemap[start] = position
bracemap[position] = start
return bracemap
def buildcurlybracemap(code):
temp_bracestack, bracemap = [], {}
for position, command in enumerate(code):
if command == "(": temp_bracestack.append(position)
if command == ")":
start = temp_bracestack.pop()
bracemap[start] = position
bracemap[position] = start
return bracemap
def buildlongcondmap(code):
temp_bracestack, bracemap = [], {}
for position, command in enumerate(code):
if command == "<": temp_bracestack.append(position)
if command == ">":
start = temp_bracestack.pop()
bracemap[start] = position
bracemap[position] = start
return bracemap
def run_mawp(code,input_,debug=False, delay=0.1):
formatted_input = list(input_)
pos = 0
stack = [1]
squarebracemap = buildsquarebracemap(code)
curlybracemap = buildcurlybracemap(code)
longcondmap = buildlongcondmap(code)
while True:
char = code[pos]
if debug:print(stack, char)
if char == 'M':
top = int(stack[-1])
stack.pop(-1)
sec = int(stack[-1])
stack.pop(-1)
stack.append(top+sec)
elif char == 'A':
top = int(stack[-1])
stack.pop(-1)
sec = int(stack[-1])
stack.pop(-1)
stack.append(abs(sec-top))
elif char == 'W':
top = int(stack[-1])
stack.pop(-1)
sec = int(stack[-1])
stack.pop(-1)
stack.append(top*sec)
elif char == 'P':
top = int(stack[-1])
stack.pop(-1)
sec = int(stack[-1])
stack.pop(-1)
stack.append(int(sec//top))
elif char in ['0','1','2','3','4','5','6','7','8','9']:
stack.append(char)
elif char == '%':
stack.pop(-1)
elif char == '!':
stack.append(stack[-1])
elif char == ':':
top = int(stack[-1])
stack.pop(-1)
print(str(top),end='')
elif char == ';':
top = int(stack[-1])
stack.pop(-1)
print(str(chr(top)),end='')
elif char == '.':
return 0
elif char == ']':
if stack[-1] != 0:
pos = squarebracemap[pos]
elif char == '[':
if stack[-1] == 0:
pos = squarebracemap[pos]
elif char == ')':
if stack[-1] == 0:
pos = curlybracemap[pos]
elif char == '(':
if stack[-1] != 0:
pos = curlybracemap[pos]
elif char == '?':
if stack[-1] != 0:
pos += 1
elif char == '|':
stack.extend(ord(x) for x in formatted_input)
elif char == '~':
stack = list(reversed(stack))
elif char == '<':
if stack[-1] != 0:
pos = longcondmap[pos]
elif char == '_':
stack.append(len(stack))
pos += 1
sleep(delay)
Which is run by calling run_mawp() with code and STDIN passed into it.
==Example Programs==
===Hello, World!===
The following program produces the classic Hello, World!
98W;55W4W1M;93W4W;93W4W;94W1M3W;58W4M;84W;98M5W2M;94W1M3W;99M1M6W;93W4W;55W4W;92M3W;.
===All integers===
This program will output each integer from 1 to infinity in order until it is terminated
1[!:1M]
==Computational class==
MAWP 0.0 is a [[push-down automaton]], as it can be translated from [[BFStack]] (but nothing more powerful):
{| class="wikitable sortable"
! BFStack !! MAWP
|-
| <code>></code> || <code>0</code>
|-
| <code><</code> || <code>%</code>
|-
| <code>.</code> || <code>!;</code>
|-
| <code>,</code> || <code>|</code>
|-
| <code>+</code> || <code>1M</code>
|-
| <code>-</code> || <code>1A</code>
|-
| <code>[</code> || <code>[</code>
|-
| <code>]</code> || <code>]</code>
|}
[[Category:Languages]] [[Category:2020]] [[Category:Stack-based]] [[Category:Implemented]] [[Category:Push-down automata]]' |
New page wikitext, after the edit (new_wikitext) | ''''MAWP''' is a stack-based [[esoteric programming language]] that was made in 2020.
==Language Overview==
===Version 0.0===
'''MAWP''' works on an integer stack, starting with an initial value of 1. The base operators are:
Any single-digit integer pushes that integer to stack.
M takes top two values of the stack and sums them. [3,2,1] ==> [3,3]
A takes top two values of the stack and subtracts the first from the other. [3,2,1] ==> [3,1]
W takes top two values of the stack and multiplies them. [3,2,1] ==> [3,2]
P takes top two values of the stack and floor divides the second by the other. [3,2,1] ==> [3,2]
% pops top of stack. [3,2,1] ==> [3,2]
! duplicates top of stack. [3,2,1] ==> [3,2,1,1]
: prints top of stack without newline, removing it. [3,2,1] ==> [3,2] (STDOUT:1)
; prints top of stack as ascii char without newline, popping it. [3,2,72]==> [3,2] (STDOUT:H)
. terminates program
[ start of loop
] end of loop. If top of stack doesn't equal to 0, then moves back to start of loop. (inspired by [[brainfuck]])
? conditional. If top of stack doesn't equal to 0, skips next operator.
| reads a character off STDIN and pushes its ascii value. NOTE:integers still get pushed according to ascii value, not actual integer value.
===Version 0.1===
'''MAWP 0.1''' introduces several new features, and changes a couple old ones:
~ reverses stack [3,2,1] ==> [1,2,3]
[ now also jumps to its ] if top of stack equals to 0
( start of inverted [] loop. Jumps to its ) if top of stack doesn't equal to 0
) end of inverted [] loop. Jumps to its ( if top of stack equals to 0
< long conditional. If top of stack doesn't equal to 0, jumps to its >
> end of long conditional
A now gives the absolute value of the difference
| now pushes whole input byte by byte, not only the first one
_ pushes length of stack [3,2,1] ==> [3,2,1,3]
==Interpreter==
Currently, the only online interpreter available for '''MAWP 0.1''' is hosted on [https://8dion8.github.io/ This page]
However, this is an offline script written in python 3.8:
#Ver 0.1
from time import sleep
def buildsquarebracemap(code):
temp_bracestack, bracemap = [], {}
for position, command in enumerate(code):
if command == "[": temp_bracestack.append(position)
if command == "]":
start = temp_bracestack.pop()
bracemap[start] = position
bracemap[position] = start
return bracemap
def buildcurlybracemap(code):
temp_bracestack, bracemap = [], {}
for position, command in enumerate(code):
if command == "(": temp_bracestack.append(position)
if command == ")":
start = temp_bracestack.pop()
bracemap[start] = position
bracemap[position] = start
return bracemap
def buildlongcondmap(code):
temp_bracestack, bracemap = [], {}
for position, command in enumerate(code):
if command == "<": temp_bracestack.append(position)
if command == ">":
start = temp_bracestack.pop()
bracemap[start] = position
bracemap[position] = start
return bracemap
def run_mawp(code,input_,debug=False, delay=0.1):
formatted_input = list(input_)
pos = 0
stack = [1]
squarebracemap = buildsquarebracemap(code)
curlybracemap = buildcurlybracemap(code)
longcondmap = buildlongcondmap(code)
while True:
char = code[pos]
if debug:print(stack, char)
if char == 'M':
top = int(stack[-1])
stack.pop(-1)
sec = int(stack[-1])
stack.pop(-1)
stack.append(top+sec)
elif char == 'A':
top = int(stack[-1])
stack.pop(-1)
sec = int(stack[-1])
stack.pop(-1)
stack.append(abs(sec-top))
elif char == 'W':
top = int(stack[-1])
stack.pop(-1)
sec = int(stack[-1])
stack.pop(-1)
stack.append(top*sec)
elif char == 'P':
top = int(stack[-1])
stack.pop(-1)
sec = int(stack[-1])
stack.pop(-1)
stack.append(int(sec//top))
elif char in ['0','1','2','3','4','5','6','7','8','9']:
stack.append(char)
elif char == '%':
stack.pop(-1)
elif char == '!':
stack.append(stack[-1])
elif char == ':':
top = int(stack[-1])
stack.pop(-1)
print(str(top),end='')
elif char == ';':
top = int(stack[-1])
stack.pop(-1)
print(str(chr(top)),end='')
elif char == '.':
return 0
elif char == ']':
if stack[-1] != 0:
pos = squarebracemap[pos]
elif char == '[':
if stack[-1] == 0:
pos = squarebracemap[pos]
elif char == ')':
if stack[-1] == 0:
pos = curlybracemap[pos]
elif char == '(':
if stack[-1] != 0:
pos = curlybracemap[pos]
elif char == '?':
if stack[-1] != 0:
pos += 1
elif char == '|':
stack.extend(ord(x) for x in formatted_input)
elif char == '~':
stack = list(reversed(stack))
elif char == '<':
if stack[-1] != 0:
pos = longcondmap[pos]
elif char == '_':
stack.append(len(stack))
pos += 1
sleep(delay)
Which is run by calling run_mawp() with code and STDIN passed into it.
==Example Programs==
===Hello, World!===
The following program produces the classic Hello, World!
98W;55W4W1M;93W4W;93W4W;94W1M3W;58W4M;84W;98M5W2M;94W1M3W;99M1M6W;93W4W;55W4W;92M3W;.
===All integers===
This program will output each integer from 1 to infinity in order until it is terminated
1[!:1M]
===Truth Machine===
|68WA!~M1A?:?.[!:]
==Computational class==
MAWP 0.0 is a [[push-down automaton]], as it can be translated from [[BFStack]] (but nothing more powerful):
{| class="wikitable sortable"
! BFStack !! MAWP
|-
| <code>></code> || <code>0</code>
|-
| <code><</code> || <code>%</code>
|-
| <code>.</code> || <code>!;</code>
|-
| <code>,</code> || <code>|</code>
|-
| <code>+</code> || <code>1M</code>
|-
| <code>-</code> || <code>1A</code>
|-
| <code>[</code> || <code>[</code>
|-
| <code>]</code> || <code>]</code>
|}
[[Category:Languages]] [[Category:2020]] [[Category:Stack-based]] [[Category:Implemented]] [[Category:Push-down automata]]' |