quasi11.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <head>
  2. <!-- Copyright (C) 2020 mn
  3. 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.
  4. 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.
  5. You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
  6. -->
  7. <title>quasi 1.1</title>
  8. <style>
  9. div {overflow: scroll; font-family: monospace; font-size: 19px; font-weight: bold;}
  10. textarea {overflow: scroll; font-family: monospace; font-size: 19px; font-weight: bold;}
  11. </style>
  12. </head>
  13. <body>
  14. <span id="progrun">
  15. </span>
  16. <div id="dtop" style="position: absolute; top: 1%; left: 1%; width: 98%; height: 35%;"><br>&nbsp;display window</div>
  17. <textarea id="dleft" style="position: absolute; top: 38%; left: 1%; width: 32%; height: 58%;">
  18. # import window
  19. m = get -1 ; str ; left 1
  20. p ; for 1 5 1
  21. hello = date ; mid 2 1
  22. now = get "u tc" ; split now " "
  23. now = join now "" ; prints
  24. m ; prints
  25. now ; len ; print
  26. next
  27. now ; title</textarea>
  28. <div id="dmid" style="position: absolute; top: 38%; left: 35%; width: 64%; height: 58%;"
  29. onclick="javascript:runimport();"><br>&nbsp;program editor (not implemented yet)<br><br>&nbsp;click here to run program in import/export window on left<br><br></div>
  30. <script>dtop.style.background = 'white'; dtop.style.bordercolor = 'black'; dtop.style.border = 'solid';
  31. dleft.style.background = 'white'; dleft.style.bordercolor = 'black'; dleft.style.border = 'solid';
  32. // dleft.innerHTML = "<textarea style='width: 100%; height: 100%;'></textarea>";
  33. dmid.style.background = 'white'; dmid.style.bordercolor = 'black'; dmid.style.border = 'solid';
  34. function outd(p) {
  35. dtop.innerHTML += "<span style='color: orange;'>" + p + "</span><br>\n";
  36. }
  37. function left(s, l) {
  38. return s.substring(0, l);
  39. }
  40. function right(s, l) {
  41. return s.substring(s.length-l, s.length);
  42. }
  43. var addfuncs = "\n\
  44. function q_cls(p) {\n\
  45. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  46. dtop.innerHTML = \"\";\n\
  47. }\n\
  48. \n\
  49. function q_date(p) {\n\
  50. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  51. d = Date().toLocaleString().split(\" \");\n\
  52. months = {\n\
  53. 'Jan': '01',\n\
  54. 'Feb': '02',\n\
  55. 'Mar': '03',\n\
  56. 'Apr': '04',\n\
  57. 'May': '05',\n\
  58. 'Jun': '06',\n\
  59. 'Jul': '07',\n\
  60. 'Aug': '08',\n\
  61. 'Sep': '09',\n\
  62. 'Oct': '10',\n\
  63. 'Nov': '11',\n\
  64. 'Dec': '12',\n\
  65. }\n\
  66. return (months[d[1]] + \"/\" + d[2] + \"/\" + d[3] + \"_\" + d[4] + \"_\" + d[0]).split(\"_\");\n\
  67. }\n\
  68. \n\
  69. function q_end(p) {\n\
  70. progrun.innerHTML = \"<!-- -->\";\n\
  71. }\n\
  72. \n\
  73. function q_len(p) {\n\
  74. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  75. return p.length;\n\
  76. }\n\
  77. \n\
  78. function q_print(p) {\n\
  79. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  80. dtop.innerHTML = dtop.innerHTML + p + \"<br>\\n\";\n\
  81. }\n\
  82. \n\
  83. function q_prints(p) {\n\
  84. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  85. dtop.innerHTML = dtop.innerHTML + p;\n\
  86. }\n\
  87. \n\
  88. function q_str(p) {\n\
  89. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  90. return \"\" + p;\n\
  91. }\n\
  92. \n\
  93. function q_title(p) {\n\
  94. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  95. document.title = p;\n\
  96. }\n\
  97. \n\
  98. function q_get(p, s) {\n\
  99. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  100. return (s);\n\
  101. }\n\
  102. \n\
  103. function q_left(p, s) {\n\
  104. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  105. if (typeof(p) == \"object\") {\n\
  106. var t = [];\n\
  107. for(count = 0; count < s; count++) {\n\
  108. t.push(p[count]);\n\
  109. }\n\
  110. }\n\
  111. else {\n\
  112. var t = p.substring(0, s);\n\
  113. }\n\
  114. return t;\n\
  115. }\n\
  116. \n\
  117. function q_right(p, s) {\n\
  118. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  119. if (typeof(p) == \"object\") {\n\
  120. var t = [];\n\
  121. for(count = p.length - s; count < p.length; count++) {\n\
  122. t.push(p[count]);\n\
  123. }\n\
  124. }\n\
  125. else {\n\
  126. var t = p.substring(p.length - s, p.length);\n\
  127. }\n\
  128. return t;\n\
  129. }\n\
  130. \n\
  131. function q_split(p, s, o) {\n\
  132. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  133. return s.split(o);\n\
  134. }\n\
  135. \n\
  136. function q_join(p, s, o) {\n\
  137. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  138. return s.join(o);\n\
  139. }\n\
  140. \n\
  141. function q_mid(p, s, o) {\n\
  142. if (progrun.innerHTML == \"<!-- -->\") { return 0; }\n\
  143. if (typeof(p) == \"object\") {\n\
  144. var t = [];\n\
  145. for(count = s - 1; count < s -1 + o; count++) {\n\
  146. t.push(p[count]);\n\
  147. }\n\
  148. }\n\
  149. else {\n\
  150. var t = p.substring(s - 1, s - 1 + o);\n\
  151. }\n\
  152. return t;\n\
  153. }\n\
  154. \n\
  155. ";
  156. eval(addfuncs); q_cls(0);
  157. cmds = {
  158. cls: 0,
  159. date: 0,
  160. end: 0,
  161. for: -4,
  162. function: -1,
  163. get: 1,
  164. join: 2,
  165. left: 1,
  166. len: 0,
  167. mid: 2,
  168. print: 0,
  169. prints: 0,
  170. right: 1,
  171. split: 2,
  172. str: 0,
  173. title: 0
  174. }
  175. function runimport() {
  176. parsed = textparse();
  177. if (parsed != "") {
  178. dtop.innerHTML = "";
  179. eval(parsed);
  180. dtop.innerHTML += "<br>" + parsed.split("\n").join("<br>\n");
  181. }
  182. }
  183. function textparse() {
  184. vars = { }
  185. //q_cls();
  186. progrun.innerHTML = "";
  187. var p = "";
  188. var cmdcount = 0;
  189. var petc = "";
  190. var getcmd = "";
  191. var getvar = "";
  192. var cc = dleft.value + "\n";
  193. var codeout = "";
  194. var bu = 0;
  195. var inquotes = 0;
  196. var misquotes = 0;
  197. var commented = 0;
  198. var tokcount = 0;
  199. var mainvar = "";
  200. var mainvarplus = "";
  201. var prevcmd = "";
  202. var tokisnum = 0;
  203. var special = "";
  204. codeout += "vars = { }\n" + addfuncs;
  205. for(count = 0; count < cc.length; count++) {
  206. p = cc.substring(count, count + 1);
  207. if (commented == 0 && inquotes == 0) {
  208. if (p == "=" || p == ":" || p == ";") {
  209. p = " "; // allow optional ; or =
  210. }
  211. }
  212. if (p == "#") {
  213. commented = 1;
  214. }
  215. if (p == "\"") {
  216. if (inquotes == 1) {
  217. inquotes = 0;
  218. }
  219. else {
  220. inquotes = 1;
  221. }
  222. }
  223. if (p == String.fromCharCode(8221)) {
  224. if (misquotes == 1) {
  225. p = "\"";
  226. inquotes = 0;
  227. misquotes = 0;
  228. }
  229. }
  230. if (p == String.fromCharCode(8220)) {
  231. if (inquotes == 0) {
  232. p = "\"";
  233. inquotes = 1;
  234. misquotes = 1;
  235. }
  236. }
  237. if (commented == 0 && inquotes == 0 && left(petc, 1) != "#") {
  238. if (p == " " || p == "\n") {
  239. if (petc.trim() != "") { tokcount += 1 }
  240. if (p == " ") {
  241. p = "";
  242. }
  243. if (petc != "") {
  244. tokisnum = 0;
  245. getcmd = undefined;
  246. if ("-01234567890".indexOf(petc[0]) > -1 || petc[0] == "\"") {
  247. tokisnum = 1; getcmd = undefined;
  248. }
  249. else {
  250. eval("getcmd=cmds." + petc + ";");
  251. }
  252. if (getcmd != undefined) {
  253. cmdcount = getcmd;
  254. mainvarplus = "";
  255. getcmd = "q_" + petc + "(";
  256. prevcmd = getcmd;
  257. if (tokcount > 1) {
  258. if (cmdcount == 0) {
  259. codeout += "bu = " + mainvar + "; " + mainvar + " = " + getcmd + mainvar + "); ";
  260. codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = bu; }\n";
  261. }
  262. if (petc == "for") { special = "for"; cmdcount = -4 }
  263. if (petc == "function") { special = "function"; cmdcount = -1 }
  264. }
  265. else {
  266. codeout += getcmd + "); ";
  267. }
  268. }
  269. else {
  270. if (petc != "") {
  271. try {
  272. getvar = 0 ;
  273. if (tokisnum == 0) { eval("getvar=vars." + petc + ";"); }
  274. if (tokcount == 1) {
  275. if (petc == "prev" || petc == "next") {
  276. if (petc == "next") {
  277. codeout += "}\n";
  278. }
  279. }
  280. else {
  281. mainvar = "vars." + petc;
  282. codeout += "if (vars." + petc + " == undefined) { vars." + petc + " = 0; }\n";
  283. }
  284. }
  285. else {
  286. if (cmdcount < -2 && special == "function") {
  287. codeout += ", " + petc;
  288. cmdcount -= 1;
  289. }
  290. if (cmdcount == -2 && special == "function") {
  291. codeout += ", " + petc;
  292. cmdcount -= 1;
  293. }
  294. if (cmdcount == -1 && special == "function") {
  295. codeout += "function f_" + mainvar.split("vars.").join("") + "(" + petc;
  296. cmdcount -= 1;
  297. }
  298. if (cmdcount == -2 && special == "for") {
  299. codeout += mainvar + "+= " + petc + ") {\n"
  300. cmdcount += 1; special = "";
  301. }
  302. if (cmdcount == -3 && special == "for") {
  303. codeout += mainvar + " < (" + petc + " + 1); ";
  304. cmdcount += 1;
  305. }
  306. if (cmdcount == -4 && special == "for") {
  307. codeout += "for(" + mainvar + " = " + petc + "; ";
  308. cmdcount += 1;
  309. }
  310. if (cmdcount == 0) {
  311. codeout += "bu = " + mainvar + "; " + mainvar + " = " + getcmd + mainvar + mainvarplus + "); ";
  312. codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = bu; }\n";
  313. }
  314. if (cmdcount == 1) {
  315. if (tokisnum == 0) {
  316. mainvarplus += ", " + "vars." + petc; cmdcount -= 1; }
  317. else {
  318. mainvarplus += ", " + petc; cmdcount -= 1;
  319. }
  320. codeout += "bu = " + mainvar + "; " + mainvar + " = " + prevcmd + mainvar + mainvarplus + "); ";
  321. codeout += "if (" + mainvar + " == undefined) { " + mainvar + " = bu; }\n";
  322. }
  323. if (cmdcount > 1) {
  324. if (tokisnum == 0) {
  325. mainvarplus += ", " + "vars." + petc; cmdcount -= 1; }
  326. else {
  327. mainvarplus += ", " + petc; cmdcount -= 1;
  328. }
  329. }
  330. }
  331. }
  332. catch(err) { }
  333. }
  334. if (getvar == undefined) { eval("vars." + petc + " = 0;"); }
  335. }
  336. petc = "";
  337. }
  338. }
  339. }
  340. if (p == "\n") {
  341. tokcount = 0;
  342. commented = 0;
  343. inquotes = 0;
  344. if (special == "function") {
  345. codeout += ") {";
  346. }
  347. special = "";
  348. if (left(petc, 1) == "#") {
  349. codeout += "// " + petc + "\n\n";
  350. }
  351. else {
  352. codeout += "\n";
  353. }
  354. petc = ""; }
  355. else {
  356. if (inquotes == 0 && commented == 0) {
  357. petc = (petc + p).trim(); }
  358. else {
  359. petc = petc + p;
  360. }
  361. }
  362. }
  363. return codeout;
  364. }
  365. 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>.";
  366. </script>
  367. </body>