123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- <head>
- <!-- Copyright (C) 2020 mn
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
- -->
- <title>quasi 1.1</title>
- <style>
- div {overflow: scroll; font-family: monospace; font-size: 19px; font-weight: bold;}
- textarea {overflow: scroll; font-family: monospace; font-size: 19px; font-weight: bold;}
- </style>
- </head>
- <body>
- <span id="progrun">
- </span>
- <div id="dtop" style="position: absolute; top: 1%; left: 1%; width: 98%; height: 35%;"><br> display window</div>
- <textarea id="dleft" style="position: absolute; top: 38%; left: 1%; width: 32%; height: 58%;">
- # import window
- m = get -1 ; str ; left 1
- p ; for 1 5 1
- hello = date ; mid 2 1
- now = get "u tc" ; split now " "
- now = join now "" ; prints
- m ; prints
- now ; len ; print
- next
- now ; title</textarea>
- <div id="dmid" style="position: absolute; top: 38%; left: 35%; width: 64%; height: 58%;"
- onclick="javascript:runimport();"><br> program editor (not implemented yet)<br><br> click here to run program in import/export window on left<br><br></div>
- <script>dtop.style.background = 'white'; dtop.style.bordercolor = 'black'; dtop.style.border = 'solid';
- dleft.style.background = 'white'; dleft.style.bordercolor = 'black'; dleft.style.border = 'solid';
- // dleft.innerHTML = "<textarea style='width: 100%; height: 100%;'></textarea>";
- dmid.style.background = 'white'; dmid.style.bordercolor = 'black'; dmid.style.border = 'solid';
- function outd(p) {
- dtop.innerHTML += "<span style='color: orange;'>" + p + "</span><br>\n";
- }
- function left(s, l) {
- return s.substring(0, l);
- }
- function right(s, l) {
- return s.substring(s.length-l, s.length);
- }
- var addfuncs = "\n\
- function q_cls(p) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- dtop.innerHTML = \"\";\n\
- }\n\
- \n\
- function q_date(p) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- d = Date().toLocaleString().split(\" \");\n\
- months = {\n\
- 'Jan': '01',\n\
- 'Feb': '02',\n\
- 'Mar': '03',\n\
- 'Apr': '04',\n\
- 'May': '05',\n\
- 'Jun': '06',\n\
- 'Jul': '07',\n\
- 'Aug': '08',\n\
- 'Sep': '09',\n\
- 'Oct': '10',\n\
- 'Nov': '11',\n\
- 'Dec': '12',\n\
- }\n\
- return (months[d[1]] + \"/\" + d[2] + \"/\" + d[3] + \"_\" + d[4] + \"_\" + d[0]).split(\"_\");\n\
- }\n\
- \n\
- function q_end(p) {\n\
- progrun.innerHTML = \"<!-- -->\";\n\
- }\n\
- \n\
- function q_len(p) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- return p.length;\n\
- }\n\
- \n\
- function q_print(p) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- dtop.innerHTML = dtop.innerHTML + p + \"<br>\\n\";\n\
- }\n\
- \n\
- function q_prints(p) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- dtop.innerHTML = dtop.innerHTML + p;\n\
- }\n\
- \n\
- function q_str(p) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- return \"\" + p;\n\
- }\n\
- \n\
- function q_title(p) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- document.title = p;\n\
- }\n\
- \n\
- function q_get(p, s) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- return (s);\n\
- }\n\
- \n\
- function q_left(p, s) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- if (typeof(p) == \"object\") {\n\
- var t = [];\n\
- for(count = 0; count < s; count++) {\n\
- t.push(p[count]);\n\
- }\n\
- }\n\
- else {\n\
- var t = p.substring(0, s);\n\
- }\n\
- return t;\n\
- }\n\
- \n\
- function q_right(p, s) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- if (typeof(p) == \"object\") {\n\
- var t = [];\n\
- for(count = p.length - s; count < p.length; count++) {\n\
- t.push(p[count]);\n\
- }\n\
- }\n\
- else {\n\
- var t = p.substring(p.length - s, p.length);\n\
- }\n\
- return t;\n\
- }\n\
- \n\
- function q_split(p, s, o) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- return s.split(o);\n\
- }\n\
- \n\
- function q_join(p, s, o) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- return s.join(o);\n\
- }\n\
- \n\
- function q_mid(p, s, o) {\n\
- if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
- if (typeof(p) == \"object\") {\n\
- var t = [];\n\
- for(count = s - 1; count < s -1 + o; count++) {\n\
- t.push(p[count]);\n\
- }\n\
- }\n\
- else {\n\
- var t = p.substring(s - 1, s - 1 + o);\n\
- }\n\
- return t;\n\
- }\n\
- \n\
- ";
- eval(addfuncs); q_cls(0);
- cmds = {
- cls: 0,
- date: 0,
- end: 0,
- for: -4,
- function: -1,
- get: 1,
- join: 2,
- left: 1,
- len: 0,
- mid: 2,
- print: 0,
- prints: 0,
- right: 1,
- split: 2,
- str: 0,
- title: 0
- }
- function runimport() {
- parsed = textparse();
- if (parsed != "") {
- dtop.innerHTML = "";
- eval(parsed);
- dtop.innerHTML += "<br>" + parsed.split("\n").join("<br>\n");
- }
- }
- function textparse() {
- vars = { }
- //q_cls();
- progrun.innerHTML = "";
- var p = "";
- var cmdcount = 0;
- var petc = "";
- var getcmd = "";
- var getvar = "";
- var cc = dleft.value + "\n";
- var codeout = "";
- var bu = 0;
- var inquotes = 0;
- var misquotes = 0;
- var commented = 0;
- var tokcount = 0;
- var mainvar = "";
- var mainvarplus = "";
- var prevcmd = "";
- var tokisnum = 0;
- var special = "";
- codeout += "vars = { }\n" + addfuncs;
- for(count = 0; count < cc.length; count++) {
- p = cc.substring(count, count + 1);
- if (commented == 0 && inquotes == 0) {
- if (p == "=" || p == ":" || p == ";") {
- p = " "; // allow optional ; or =
- }
- }
- if (p == "#") {
- commented = 1;
- }
- if (p == "\"") {
- if (inquotes == 1) {
- inquotes = 0;
- }
- else {
- inquotes = 1;
- }
- }
- if (p == String.fromCharCode(8221)) {
- if (misquotes == 1) {
- p = "\"";
- inquotes = 0;
- misquotes = 0;
- }
- }
- if (p == String.fromCharCode(8220)) {
- if (inquotes == 0) {
- p = "\"";
- inquotes = 1;
- misquotes = 1;
- }
- }
- if (commented == 0 && inquotes == 0 && left(petc, 1) != "#") {
- if (p == " " || p == "\n") {
- if (petc.trim() != "") { tokcount += 1 }
- if (p == " ") {
- p = "";
- }
- if (petc != "") {
- tokisnum = 0;
- getcmd = undefined;
- if ("-01234567890".indexOf(petc[0]) > -1 || petc[0] == "\"") {
- tokisnum = 1; getcmd = undefined;
- }
- else {
- eval("getcmd=cmds." + petc + ";");
- }
- if (getcmd != undefined) {
- cmdcount = getcmd;
- mainvarplus = "";
- getcmd = "q_" + petc + "(";
- prevcmd = getcmd;
- if (tokcount > 1) {
- if (cmdcount == 0) {
- codeout += "bu = " + mainvar + "; " + mainvar + " = " + getcmd + mainvar + "); ";
- codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = bu; }\n";
- }
- if (petc == "for") { special = "for"; cmdcount = -4 }
- if (petc == "function") { special = "function"; cmdcount = -1 }
- }
- else {
- codeout += getcmd + "); ";
- }
- }
- else {
- if (petc != "") {
- try {
- getvar = 0 ;
- if (tokisnum == 0) { eval("getvar=vars." + petc + ";"); }
- if (tokcount == 1) {
- if (petc == "prev" || petc == "next") {
- if (petc == "next") {
- codeout += "}\n";
- }
- }
- else {
- mainvar = "vars." + petc;
- codeout += "if (vars." + petc + " == undefined) { vars." + petc + " = 0; }\n";
- }
- }
- else {
- if (cmdcount < -2 && special == "function") {
- codeout += ", " + petc;
- cmdcount -= 1;
- }
- if (cmdcount == -2 && special == "function") {
- codeout += ", " + petc;
- cmdcount -= 1;
- }
- if (cmdcount == -1 && special == "function") {
- codeout += "function f_" + mainvar.split("vars.").join("") + "(" + petc;
- cmdcount -= 1;
- }
- if (cmdcount == -2 && special == "for") {
- codeout += mainvar + "+= " + petc + ") {\n"
- cmdcount += 1; special = "";
- }
- if (cmdcount == -3 && special == "for") {
- codeout += mainvar + " < (" + petc + " + 1); ";
- cmdcount += 1;
- }
- if (cmdcount == -4 && special == "for") {
- codeout += "for(" + mainvar + " = " + petc + "; ";
- cmdcount += 1;
- }
- if (cmdcount == 0) {
- codeout += "bu = " + mainvar + "; " + mainvar + " = " + getcmd + mainvar + mainvarplus + "); ";
- codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = bu; }\n";
- }
- if (cmdcount == 1) {
- if (tokisnum == 0) {
- mainvarplus += ", " + "vars." + petc; cmdcount -= 1; }
- else {
- mainvarplus += ", " + petc; cmdcount -= 1;
- }
- codeout += "bu = " + mainvar + "; " + mainvar + " = " + prevcmd + mainvar + mainvarplus + "); ";
- codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = bu; }\n";
- }
- if (cmdcount > 1) {
- if (tokisnum == 0) {
- mainvarplus += ", " + "vars." + petc; cmdcount -= 1; }
- else {
- mainvarplus += ", " + petc; cmdcount -= 1;
- }
- }
- }
- }
- catch(err) { }
- }
- if (getvar == undefined) { eval("vars." + petc + " = 0;"); }
- }
- petc = "";
- }
- }
- }
- if (p == "\n") {
- tokcount = 0;
- commented = 0;
- inquotes = 0;
- if (special == "function") {
- codeout += ") {";
- }
- special = "";
- if (left(petc, 1) == "#") {
- codeout += "// " + petc + "\n\n";
- }
- else {
- codeout += "\n";
- }
- petc = ""; }
- else {
- if (inquotes == 0 && commented == 0) {
- petc = (petc + p).trim(); }
- else {
- petc = petc + p;
- }
- }
- }
- return codeout;
- }
- dtop.innerHTML = "<br>" + document.title + "<br>Copyright (C) 2020 mn<br><br>This program is free software: you can redistribute it and/or modify it under the terms of the <a href='gpl-3.0.txt'>GNU General Public License</a> as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.<br><br>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.<br><br>You should have received a copy of the GNU General Public License along with this program. If not, see <a href='https://www.gnu.org/licenses/'>https://www.gnu.org/licenses/</a>.";
- </script>
- </body>
|