/* Everything is implicitly treated as a string character, and the strings are printed implicitly after execution Program 1: Hello, World! Hello, World! If you want to perform commands, you must enclose them within {...}. To use {, }, use the escape character \. Or, if you simply wish to use a single command, you use the vertical bar character |. Within this "command set", you can use the following expressions: < push current string to the stack > pop current string for writing + concat top two entries on stack (str,str) add two numbers (num,num) repeat str num times (num,str) * writes str2 at the num index of str1 (overwrites) (str1,str2,num) multiply top two numbers of stack (num,num) concat top two entries on stack in a reverse order $ switch top two entries * reverse the stack v pop stack and write to current string (implicit at the }, suppressed if ` is met) ~ duplicate the top of the stack i read entity of input and push to stack 0-9 push numeric literal / divide top two entries on stack (num,num) writes str2 at the num index of str1 (inserts) (numstr1,str2) - subtract top two entries on stack (num,num) remove last num characters from end of str (str,num) @ reverse current string U sentence case current string Q pushes a newline to the stack R push a random number between 0 and the popped number r apply following regular expression and replace all matches with the top of the stack/nothing. e.g. r\d+/ replaces all digits in the string. there are also extra control sequences: \a uppercase alphabet \A non uppercase alphabet \l lowercase alphabet \L non lowercase alphabet \c alphabetic characters \C non alphabetic characters \p punctuation \P non punctuation l push the length of the top string L push the length of the current string c copy current string to stack s pops an integer (a), top string (s), next string (t) and puts t at every ath index in s (num,str,str) ? pops top byte; if it is truthy, execute next command, otherwise skip it n converts string to number N converts number to string (…) loop until top of stack is zero […] pop n and duplicate inner n times = pushes 1 if top of stack is equal to current string @ takes the index in the word list equivalent to the character code of the byte # performs b action until a newline is met &C saves the current string as variable C ^C pushes C to the stack y r, but nonglobal «…» comment To use shorthand for a word, use the :...:. This will write that sequence to the current string */ function hex(v){ new Hexdump(v,{container:'hexdump',width:'10',ascii:true,byteGrouping:1,html:true,lineNumber:true,style:{lineNumberLeft:'',lineNumberRight: ':',stringLeft:' | ',stringRight:' |',hexLeft:'',hexRight:'',hexNull:'.g',stringNull:' '}}); } function logBase(number,base){ return Math.log(number)/Math.log(base); } function toBaseArr(n,b){ h = Math.ceil(logBase(n,b)); a = new Array(h+1) .fill(0); while(n){ h = Math.floor(logBase(n,b)); n-=Math.pow(b,h); a[h]++; } a.pop(); return a.reverse(); } function fromBaseArr(a,b){ f = 0; a.reverse().map(function(e,i){ return f+=e*Math.pow(b,i); }); return f; } function toBase93(number){ str = "!\"#$%&'()*+,-./0123456789;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}"; return toBaseArr(number,93).map(function(e){return str[e]}).join(""); } function check(a,b){ if(Array.isArray(b)&&b.length>1){ return check(a,b.pop())||check(a,b); } else { if(b==a) return true; return false; } } function fromBase93(a){ str = "!\"#$%&'()*+,-./0123456789;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}"; a=a.split("").map(function(e){ return str.indexOf(e); }); console.log(a); return fromBaseArr(a,93); } function alph(number,str){ str = "\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]_`abcdefghijklmnopqrstuvwxyz{|}~\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF" return toBaseArr(number,str.length).map(function(e){return str[e]}).join(""); } function arcAlph(s,str){ return fromBaseArr(s.split("").map(function(e){ return str.indexOf(e); }),str.length); } function g2ent(word){ } function f2ent(word){ } function byteEnt(word){ var index = (wordList.indexOf(word.toLowerCase())).toString(2); //console.log(index,parseInt(index,2)); index = index.match(/.{1,16}/g); //console.log(index); var s = ""; for(var i=0;i1){ x[i] = ""; } } else if(x[i]=="]"&&(x[i-1]||"")!="\\"){ depth--; if(depth>0){ x[i] = ""; } } } return x.join(""); } function repeat(str,times){ var t = ""; while(times){ times--; t+=str; } return t; } cmd = { "<": function(o){ o.stack.push(o.curStr); o.curStr = ""; }, ">": function(o){ o.curStr += o.stack.pop(); }, "v": function(o){ o.curStr += o.stack.pop(); }, "i": function(o){ o.stack.push(o.input.pop()); }, "+": function(o){ if(o.checkTypes("string","string")){ o.stack.push(o.stack.pop()+o.stack.pop()); } else if(o.checkTypes("number","number")){ o.stack.push(+o.stack.pop()+ +o.stack.pop()); } else if(o.checkTypes("number","string")){ var a = o.stack.pop(); o.stack.push(repeat(o.stack.pop(),a)); } }, "/": function(o){ if(o.checkTypes("number","number")){ var a = o.stack.pop(); var b = o.stack.pop(); o.stack.push(b/a); } else if(o.checkTypes("number","string","string")){ var num = o.stack.pop(); var str2 = o.stack.pop().split(""); var str1 = o.stack.pop().split(""); var st11 = str1.slice(0,num); var st12 = str1.slice(num,str1.length); o.stack.push(st11.concat(str2,st12).join("")); } }, "-": function(o){ if(o.checkTypes("number","number")){ var a = o.stack.pop(); var b = o.stack.pop(); o.stack.push(b-a); } else if(o.checkTypes("number","string")){ var a = o.stack.pop(); o.stack.push(o.stack.pop().slice(0,-a)); } }, "*": function(o){ /* * writes str2 at the num index of str1 (overwrites) (str1,str2,num) multiply top two numbers of stack (num,num) concat top two entries on stack in a reverse order*/ if(o.checkTypes("number","string","string")){ var num = o.stack.pop(); var str2 = o.stack.pop().split(""); var str1 = o.stack.pop().split(""); str1.length += str2.length + num; // populate array for(var i=0;i¿¡]").replace(/\\p/g,"[^.,-\/#!$%\^&\*;:{}=\-_`~()\[\]<>¿¡]").replace(/\\>/g,function(){ return o.stack.pop(); }).replace(/\\¿¡]").replace(/\\p/g,"[^.,-\/#!$%\^&\*;:{}=\-_`~()\[\]<>¿¡]").replace(/\\>/g,function(){ return o.stack.pop(); }).replace(/\\"); } Chaine.prototype.reset = function(){ this.stepNum = 0; this.index = 0; this.mode = 1; this.stack = []; this.input = []; this.curStr = ""; this.command = cmd; this.running = true; } Chaine.prototype.feed = function(input){ input = input.toString().split("\n"); for(var i=0;i=this.code.length){ this.running = false; STDOUT(this.curStr); while(this.stack.length){ STDOUT(this.stack.pop()); } return this; } switch(this.mode){ case 1: // string mode switch(this.code[this.index]){ case "{": o.graveMet = false; this.mode = 2; break; case "|": o.graveMet = true; this.mode = 3; break; case "\\": this.index++; this.curStr += this.code[this.index]; break; case ":": this.mode = 4; break; case "^": this.mode = 5; break; case "#": this.mode = 6; this.t = this.stack.pop()||" "; break; case "@": this.curStr += unByte(this.code[++this.index]+this.code[++this.index]); break; case String.fromCharCode(171): this.mode = 7; break; default: this.curStr += this.code[this.index]; break; } break; case 3: // single command mode this.mode = 1; o.graveMet = true; case 2: // multiline command mode var func = this.code[this.index]; var comm = this.get(func); if(comm){ comm(this); } else { throw new Error(func+" is not a valid command! (index: "+this.index+")"); } //console.log(this.stack); break; case 4: if(this.code[this.index]==":"){ this.mode = 1; this.curStr += fromEntry(this.baseStr); this.baseStr = ""; } else { this.baseStr += this.code[this.index]; } break; case 5: if(this.code[this.index]=="^"){ this.mode = 1; this.curStr += fromEntry(this.baseStr); this.baseStr = ""; } else { this.baseStr += this.code[this.index]; } break; case 6: if(this.code[this.index]=="\n"){ this.mode = 1; this.curStr = this.curStr.split(this.t); this.curStr.pop(); this.curStr = this.curStr.join(this.t); } else { this.curStr += unByte(this.code[this.index]+this.code[++this.index])+this.t; } break; case 7: if(this.code[this.index]==String.fromCharCode(187)) this.mode = 1; break; } this.index++; this.stepNum++; } return this; } function updateByteCount(){ bytes.innerHTML = bS(code.value); } function bS(text, options) { var crlf = /(\r?\n|\r)/g, whitespace = /(\r?\n|\r|\s+)/g; // Set option defaults options = options || {}; options.lineBreaks = options.lineBreaks || 1; options.ignoreWhitespace = options.ignoreWhitespace || false; var length = text.length, nonAscii = length - text.replace(/[\u0100-\uFFFF]/g, '').length, lineBreaks = length - text.replace(crlf, '').length; if (options.ignoreWhitespace) { // Strip whitespace text = text.replace(whitespace, ''); return text.length + nonAscii; } else { return length + nonAscii + Math.max(0, options.lineBreaks * (lineBreaks - 1)); } } // page-specific attributes v var code; var input; var output; var step; var run; var stats; var bytes; var instance; var disp; window.addEventListener("load",function(){ code = document.getElementById("code"); input = document.getElementById("input"); output = document.getElementById("output"); stats = document.getElementById("stats"); step = document.getElementById("step"); run = document.getElementById("run"); bytes = document.getElementById("bytecount"); disp = document.getElementById("disp"); updateByteCount(); code.addEventListener("keyup",updateByteCount); code.addEventListener("change",updateByteCount); q=decodeURIComponent(window.location.href.replace(/\+/g, " "));o={};q=q.slice(q.indexOf("?")+1,q.length).split("||").map(function(e){var f=e.split("=");o[f[0]]=f[1];return o}); if(o.code) code.value = o.code; if(o.input) input.value = o.input; }); function progress(a){ document.getElementById("prog").style.width = Math.floor(100*a.index/a.code.length)+ "%"; /*if(a.code[a.index]=="\n"){ a.offSet++; } else { var q = document.getElementById("e"+(a.index-a.offSet)); if(q) q.style.background = "green"; var r = document.getElementById("e"+(a.index-1-a.offSet)); if(r) r.style.background = "none"; }*/ outStep(); return false; } //var prevSet = 0; function set(){ //if(prevSet) exp(); //prevSet = 1; document.getElementById("prog").style.width = "0%"; output.innerHTML = ""; instance = new Chaine(code.value); /*instance.offSet = 0; var maxWidth = 0; var codeS = code.value.split("\n"); codeS.map(function(e){ maxWidth = Math.max(e.length,maxWidth); }); var table = ""; var tempIndex = 0; var dispIndex = 0; for(var i=0;i<=codeS.length;i++){ table += "" for(var j=0;j"+(code.value[tempIndex]||"")+""; if(code.value[tempIndex]) tempIndex++; if(code.value[dispIndex]) dispIndex++; } } table += "" } table.innerHTML += "
"; disp.innerHTML = table;*/ instance.feed(input.value); stats.innerHTML = "Stack: "+JSON.stringify(instance.stack)+"
Current string: \""+instance.curStr+"\"
Command: --
Grave met: "+instance.graveMet; } function outStep(){ instance.step(); stats.innerHTML = "Stack: "+JSON.stringify(instance.stack)+"
Current string: "+JSON.stringify(instance.curStr)+"
Command: "+instance.code[instance.index-1]+"
Grave met: "+instance.graveMet; } // file:///C:/Users/Conor%20O'Brien/Documents/Programming/~N-Z/Programming%20Languages/Cha%C3%AEne/Cha%C3%AEne.html?code%3DWe%27re%20no%20strangers%20to%20love%0AYou%20know%20the%20rules%20and%20so%20do%20I%0AA%20full%20commitment%27s%20what%20I%27m%20thinking%20of%0AYou%20wouldn%27t%20get%20this%20from%20any%20other%20guy%0AI%20just%20wanna%20tell%20you%20how%20I%27m%20feeling%0AGotta%20make%20you%20understand%0A%0A|%3CNever%20gonna%20give%20you%20up%0ANever%20gonna%20let%20you%20down%0ANever%20gonna%20run%20around%20and%20desert%20you%0ANever%20gonna%20make%20you%20cry%0ANever%20gonna%20say%20goodbye%0ANever%20gonna%20tell%20a%20lie%20and%20hurt%20you{%3C~%3E%26D}%0A%0A{%3C%24%3E~}|%3CWe%27ve%20known%20each%20other%20for%20so%20long%0AYour%20heart%27s%20been%20aching%20but%0AYou%27re%20too%20shy%20to%20say%20it%0AInside%20we%20both%20know%20what%27s%20been%20going%20on{%3C~%3E%26E%3E}%0AWe%20know%20the%20game%20and%20we%27re%20gonna%20play%20it%0AAnd%20if%20you%20ask%20me%20how%20I%27m%20feeling%0ADon%27t%20tell%20me%20you%27re%20too%20blind%20to%20see%0A%0A{~~%3E}|%3C%28Ooh%2C%20give%20you%20up%29{%3C~%3EQ%3E}|%3C%28Ooh%29%0ANever%20gonna%20give%2C%20never%20gonna%20give%0A%28Give%20you%20up%29%0A{%3C~%3E}{%3C*%3E%3E%3E}%0A%0A|^E%0A%0AI%20just%20wanna%20tell%20you%20how%20I%27m%20feeling%0AGotta%20make%20you%20understand%0A%0A{^DQQ^DQQ^DQQ%3C^D%24%3E%24e%24y/%3E%2F%60}||input%3D