C@++

From Esolang
Jump to navigation Jump to search

C@++ is an extension of C@ by User:BoundedBeans, made for simple text algorithms.

Commands

:  duplicate
/  swap
$  discard
.  print
#  rot
%  over
&  tuck (what does this mean?)
]  Makes the next command operate on the stack as groups of two.
   This can be stacked, for example, ]: is like forth's 2DUP, while ]]:
   would be like a 3DUP
@  Pop digits to make a base-10 number n until the top of the stack is not a digit (don't pop the non-digit),
   roll the top element n places down
~c Push the character c to the stack, ignoring its meaning
[  push the stack depth to the stack as decimal digits
+  A command disambiguator
+| Reserved for extensions, can be another disambiguator or just take stuff from the stack to determine what to do
+@ Like @, but pops an additional character before rolling, so that a digit can be rolled
+[ Push (the stack depth) - 1 to the stack as decimal digits (to work with +@ for rolling the entire stack)
+A Pop two series of digits a and b, each terminated by an underscore, pushes a number of a similar format representing a + b
+B like +A but pushes a - b
+C like +A but pushes a * b
+D like +A but pushes a / b
+E like +A but pushes a modulo b
+_ Pops a series of digits x, terminated by an underscore. Breaks out of the x innermost loops currently executing.
Anything else: push to the stack.

Loops are also supported to run as long as the top of the stack is not a certain character. This syntax is XCLX, where L is the loop contents, C is the character to check against, and X's are the loop brackets. Loop brackets with inside depth of n are encoded as Unicode character #(8239 + n), and cannot be greater than #8286, so the loop brackets, from outermost to innermost, are:

‰ ‱ ′ ″ ‴ ‵ ‶ ‷ ‸ ‹ › ※ ‼ ‽ ‾ ‿ ⁀ ⁁ ⁂ ⁃ ⁄ ⁅ ⁆ ⁇ ⁈ ⁉ ⁊ ⁋ ⁌ ⁍ ⁎ ⁏ ⁐ ⁑ ⁒ ⁓ ⁔ ⁕ ⁖ ⁗ ⁘ ⁙ ⁚ ⁛ ⁜ ⁝ ⁞

Prefixing the loop brackets with +. inverts the condition so they run as long as the top of the stack is a certain character.

Examples

Hello, world!

H.e.l:..o.,. .w.o.r.l.d.!.

Technically doesn't save any bytes over the following but is cooler for showing off duplication.

H.e.l.l.o.,. .w.o.r.l.d.!.

Truth-machine

Since C@++ only takes in a string of input, it can't be interactive, therefore the input string should be 1 or 0.

+.‰1:.+.‰+.‰0._1+_+.‰

Interpreter

code=`input co+.⁅de here.....⁅........`
input=`input input here`

l='‰‱′″‴‵‶‷‸‹›※‼‽‾‿⁀⁁⁂⁃⁄⁅⁆⁇⁈⁉⁊⁋⁌⁍⁎⁏⁐⁑⁒⁓⁔⁕⁖⁗⁘⁙⁚⁛⁜⁝⁞';Q=0;let T,I;input=[...input].reverse()
t=(function*a(r){let b=[...r];let t=b.pop();yield*b;Q=1;while(1)yield t})(code,'>>>##>>>>>');
C=`let t,t1,t2,t3,t4,t5,t6;st=[];pop=c=>c.length?c.pop():input.length?input.pop():"␀";function pdd(_){st.push('_');st.push([...(_+'')].reverse())}`
;SS=[]
while(!Q){let Z=t.next().value;switch(Z){
case':':C+='t=pop(st);st.push(t);st.push(t);';break;
case'/':C+='t=pop(st);t1=pop(st);st.push(t);st.push(t1);';break;
case'#':C+='t=pop(st);t1=pop(st);t2=pop(st);st.push(t);st.push(t2);st.push(t1);';break;
case'%':C+='t=pop(st);t1=pop(st);st.push(t1);st.push(t);st.push(t1);';break;
case'$':C+='pop(st);';break;
case'.':C+='process.stdout.write(pop(st));';break;
case'&':C+='st.push("&")';break;//what does tuck mean?
case']':C+='throw `"]" is useless`';break;
case'@':C+=`t=0;while(~'0123456789'.indexOf(t1=pop(st))t=t*10+ +t1;
t2=[];while(t--)t2.push(st.pop());t2=t2.reverse();st.push(t1);st=st.concat(t2);`;break;
case'~':T=t.next().value();C+=`t2.push("\U${T.codePointAt().toString(16).padStart(8,0)}")`;break;
case'[':C+=`pdd(st.length);`;break;

case'‰':T=t.next().value;C+=SS['‰']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‰']=!SS['‰'];I=0;break;
case'‱':T=t.next().value;C+=SS['‱']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‱']=!SS['‱'];I=0;break;
case'′':T=t.next().value;C+=SS['′']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['′']=!SS['′'];I=0;break;
case'″':T=t.next().value;C+=SS['″']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['″']=!SS['″'];I=0;break;
case'‴':T=t.next().value;C+=SS['‴']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‴']=!SS['‴'];I=0;break;
case'‵':T=t.next().value;C+=SS['‵']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‵']=!SS['‵'];I=0;break;
case'‶':T=t.next().value;C+=SS['‶']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‶']=!SS['‶'];I=0;break;
case'‷':T=t.next().value;C+=SS['‷']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‷']=!SS['‷'];I=0;break;
case'‸':T=t.next().value;C+=SS['‸']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‸']=!SS['‸'];I=0;break;
case'‹':T=t.next().value;C+=SS['‹']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‹']=!SS['‹'];I=0;break;
case'›':T=t.next().value;C+=SS['›']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['›']=!SS['›'];I=0;break;
case'※':T=t.next().value;C+=SS['※']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['※']=!SS['※'];I=0;break;
case'‼':T=t.next().value;C+=SS['‼']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‼']=!SS['‼'];I=0;break;
case'‽':T=t.next().value;C+=SS['‽']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‽']=!SS['‽'];I=0;break;
case'‾':T=t.next().value;C+=SS['‾']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‾']=!SS['‾'];I=0;break;
case'‿':T=t.next().value;C+=SS['‿']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['‿']=!SS['‿'];I=0;break;
case'⁀':T=t.next().value;C+=SS['⁀']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁀']=!SS['⁀'];I=0;break;
case'⁁':T=t.next().value;C+=SS['⁁']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁁']=!SS['⁁'];I=0;break;
case'⁂':T=t.next().value;C+=SS['⁂']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁂']=!SS['⁂'];I=0;break;
case'⁃':T=t.next().value;C+=SS['⁃']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁃']=!SS['⁃'];I=0;break;
case'⁄':T=t.next().value;C+=SS['⁄']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁄']=!SS['⁄'];I=0;break;
case'⁅':T=t.next().value;C+=SS['⁅']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁅']=!SS['⁅'];I=0;break;
case'⁆':T=t.next().value;C+=SS['⁆']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁆']=!SS['⁆'];I=0;break;
case'⁇':T=t.next().value;C+=SS['⁇']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁇']=!SS['⁇'];I=0;break;
case'⁈':T=t.next().value;C+=SS['⁈']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁈']=!SS['⁈'];I=0;break;
case'⁉':T=t.next().value;C+=SS['⁉']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁉']=!SS['⁉'];I=0;break;
case'⁊':T=t.next().value;C+=SS['⁊']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁊']=!SS['⁊'];I=0;break;
case'⁋':T=t.next().value;C+=SS['⁋']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁋']=!SS['⁋'];I=0;break;
case'⁌':T=t.next().value;C+=SS['⁌']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁌']=!SS['⁌'];I=0;break;
case'⁍':T=t.next().value;C+=SS['⁍']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁍']=!SS['⁍'];I=0;break;
case'⁎':T=t.next().value;C+=SS['⁎']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁎']=!SS['⁎'];I=0;break;
case'⁏':T=t.next().value;C+=SS['⁏']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁏']=!SS['⁏'];I=0;break;
case'⁐':T=t.next().value;C+=SS['⁐']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁐']=!SS['⁐'];I=0;break;
case'⁑':T=t.next().value;C+=SS['⁑']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁑']=!SS['⁑'];I=0;break;
case'⁒':T=t.next().value;C+=SS['⁒']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁒']=!SS['⁒'];I=0;break;
case'⁓':T=t.next().value;C+=SS['⁓']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁓']=!SS['⁓'];I=0;break;
case'⁔':T=t.next().value;C+=SS['⁔']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁔']=!SS['⁔'];I=0;break;
case'⁕':T=t.next().value;C+=SS['⁕']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁕']=!SS['⁕'];I=0;break;
case'⁖':T=t.next().value;C+=SS['⁖']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁖']=!SS['⁖'];I=0;break;
case'⁗':T=t.next().value;C+=SS['⁗']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁗']=!SS['⁗'];I=0;break;
case'⁘':T=t.next().value;C+=SS['⁘']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁘']=!SS['⁘'];I=0;break;
case'⁙':T=t.next().value;C+=SS['⁙']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁙']=!SS['⁙'];I=0;break;
case'⁚':T=t.next().value;C+=SS['⁚']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁚']=!SS['⁚'];I=0;break;
case'⁛':T=t.next().value;C+=SS['⁛']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁛']=!SS['⁛'];I=0;break;
case'⁜':T=t.next().value;C+=SS['⁜']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁜']=!SS['⁜'];I=0;break;
case'⁝':T=t.next().value;C+=SS['⁝']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁝']=!SS['⁝'];I=0;break;
case'⁞':T=t.next().value;C+=SS['⁞']?'}':"while(String.fromCodePoint("+T.codePointAt()+")"+(I?'=':'!')+"=st[st.length()-1]){";SS['⁞']=!SS['⁞'];I=0;break;

case'+':T=t.next().value;switch(T){
case'[':C+=`pdd(st.length-1);`;break;
case'@':C+=`t=0;while(~'0123456789'.indexOf(t1=pop(st))t=t*10+ +t1;t1=pop(st);
t2=[];while(t--)t2.push(st.pop());t2=t2.reverse();st.push(t1);st=st.concat(t2);`;break;
case'A':C+=`t=0n;while(~'0123456789'.indexOf(t1=pop(st))t=t*10n+BigInt(t1);
t2=0n;while(~'0123456789'.indexOf(t1=pop(st))t2=t2*10n+BigInt(t1);
pdd(t2+t);`;break;
case'B':C+=`t=0n;while(~'0123456789'.indexOf(t1=pop(st))t=t*10n+BigInt(t1);
t2=0n;while(~'0123456789'.indexOf(t1=pop(st))t2=t2*10n+BigInt(t1);
pdd(t2-t);`;break;
case'C':C+=`t=0n;while(~'0123456789'.indexOf(t1=pop(st))t=t*10n+BigInt(t1);
t2=0n;while(~'0123456789'.indexOf(t1=pop(st))t2=t2*10n+BigInt(t1);
pdd(t2*t);`;break;
case'D':C+=`t=0n;while(~'0123456789'.indexOf(t1=pop(st))t=t*10n+BigInt(t1);
t2=0n;while(~'0123456789'.indexOf(t1=pop(st))t2=t2*10n+BigInt(t1);
pdd(t2/t);`;break;
case'E':C+=`t=0n;while(~'0123456789'.indexOf(t1=pop(st))t=t*10n+BigInt(t1);
t2=0n;while(~'0123456789'.indexOf(t1=pop(st))t2=t2*10n+BigInt(t1);
pdd(t2%t);`;break;
case'.':I^=1;break;
};break;
default: C+="st.push(String.fromCodePoint("+Z.codePointAt()+"));"
}}
if(1)eval(C)
else console.log(C)

This interpreter doesn't support ] and +_ and +. but it's the best I can do