esolangs/quiner.bqn

61 lines
2.8 KiB
BQN
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env cbqn
# Quiner interpreter (https://esolangs.org/wiki/Quiner)
# run with ./BQN quiner.bqn <flags>
# or cbqn quiner.bqn <flags>
"ERROR: No arguments given. Use -h for help." ! 0•args
input {
"-h": •Out " -h displays this help
-f '<file>' run a file
-c '<code>' run some code"
•Exit@;
"-f": "ERROR: No file given"!1<•args
•FChars 1•args;
"-c": "ERROR: No code given"!1<•args
1•args;
"ERROR: Invalid flag given. Use -h for help."!0
}•args
nl @+10
Split (-˜+`׬)=
stdin ""
stdout ""
{
𝕊 code, data, i, j:
idata {
𝕊 inddata: # execute a single command.
p ind+´"*,.></+"˜indcode
nl (0(10×+˜´))'0'-˜(`('0''9'))/pcode
# For Debug:
#•Show code‿((-l+1)↑(p+1)↑code)‿data‿ind‿j
nl{
00 𝕊 '+': 21 𝕊 '+';
00 𝕊 𝕩 : 11 𝕊 𝕩;
nl 𝕊 '*': j 0n-˜data, p+1, (-n)data;
nl 𝕊 ',': stdin {nl˜𝕩•GetLine@} •_while_ {n>𝕩} , ap nstdin, stdin˜n, p+1, dataap;
nl 𝕊 '.':
•Out (-n)data
p+1, (-n)data;
nl 𝕊 '>': (code)p+n+1, data {(n𝕩)𝕩}(p+1)code;
nl 𝕊 '<': p+1, data(-(p-l)n)(p-l)code;
nl 𝕊 '/': {'/'=(p+1)code ? (code)p+2+n, data; p+1, data};
nl 𝕊 '+': p+1, ((-n)data)@+256|0+´@-˜(-n)data;
("ERROR: Expected command character"nlcodenl(p+1)'^')! 0
}pcode
} •_while_ {inddata: ind<code} idata
data, code, j, i
} •_while_ {incoij: i<in} input, "", 0, 0
•Out stdout
# a* Remove the last a characters from the end of the data deque. If the data queue's instruction pointer now points to nothing, move it back to the end of the data deque.
# a, Input a characters from standard input and append them to the end of the data deque.
# a. Remove the last a characters from the end of the data deque and print them to standard output.
# a> Append the following a characters to the end of the data deque and skip their execution.
# a< Append the previous a characters to the end of the data deque (not counting a as part of the characters).
# a/? If ? is the / character, skip the execution of the next a characters (not counting / as part of the characters). Otherwise, do nothing (and do not execute the ? character).
# a+ Remove the last a characters from the end of the data deque, add their ascii values together (overflowing at 256), and append the resulting sum as an ascii character to the data deque. The default value for a is 2.
#2>9/ ,4>@@@>5+ 99> 1>0.99// 1>1.004<4<4<
#13>Hello, World!13.