-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalibasic.html
More file actions
208 lines (204 loc) · 4.38 KB
/
Copy pathalibasic.html
File metadata and controls
208 lines (204 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<html>
<head>
<script>
var Program = [];
var Binary = [];
var Vars = [];
var Value;
var VarId;
var log;
var Element = 0;
var Running = -1;
var Monitor;
var Input;
var Watcher = Meeting;
var Hue = "#FFF", Ink = "#000";
function Wait() {
document.getElementById("Monitor" + Element).addEventListener(
"keyup", function() {
if(13 == event.keyCode) {
Vars[VarId] = this.value;
this.disabled = "disabled";
Exec();
}
}
);
document.getElementById("Monitor" + Element).focus();
Element ++;
}
function Exec() {
var op = Binary.shift(), cont = Exec, id, tmp;
if(op)
switch(op.cmd) {
case "CLS":
Monitor.innerHTML = "";
Element = 0;
break;
case "ASK":
Input.innerHTML = "";
Input.focus();
VarId = op.exp;
cont = false;
Watcher = Exec;
break;
case "AT":
if(op.exp in Vars)
Running = Vars[op.exp] - 1;
else
Running = Math.floor(parseInt(op.exp, 10) / 10) - 101;
Binary = [];
break;
case "DEF":
Vars[op.exp] = Running;
break;
case "HEY":
if(op.exp == "")
Monitor.innerHTML += "<br />";
else
if(op.exp == "_")
Monitor.innerHTML += "<hr />";
else {
tmp = "<span style='color:" + Ink + "; background-color:" + Hue + "'>";
if(op.exp in Vars)
tmp += Vars[op.exp];
else
tmp += op.exp.replace(/"([^"]*)"/, "$1");
Monitor.innerHTML += tmp + "</span>";
}
break;
case "HUE":
Hue = "#" + op.exp;
break;
case "IF":
Value = op.exp in Vars ? Vars[op.exp] : op.exp.replace(/"([^"]*)"/, "$1");
break;
case "IS":
if(op.exp in Vars) {
if(Value != Vars[op.exp])
Binary.shift();
} else
if(Value != op.exp.replace(/"([^"]*)"/, "$1"))
Binary.shift();
break;
case "INK":
Ink = "#" + op.exp;
break;
case "RUN":
Running = 0;
op = true;
break;
case "END":
Watcher = Meeting;
Binary = [];
Monitor.innerHTML += "<hr />OK:<br />";
break;
case "LIST":
log = [];
id = 1000;
Program.forEach
(function(all) {
var s = [], row = all.slice();
while(row.length) {
s.push(row[0][0] + (row[0][1] == "" ? "" : " " + row[0][1]));
row.shift();
}
log.push(id + " " + s.join(":"));
id += 10;
});
log.push("");
Monitor.innerHTML = log.join("<br />");
break;
}
else
Watcher = Meeting;
if(Running >= 0 && Binary.length == 0)
ParseRow(Program[++ Running], -1);
if(cont && op)
setTimeout(cont, 1);
}
function ParseRow(commands, part) {
var cmds = commands.slice(), cmd, i = 1;
while(cmds.length) {
cmd = cmds.shift();
if(cmd) {
if(!isFinite(part) || part < 0 || part == i)
Binary.push({cmd: cmd[0].toUpperCase(), exp: cmd[1]});
++ i;
} else
break;
}
}
function Meeting(elem) {
var cns = elem.textContent.split(/\r?\n/);
var id, idd, expr;
log = [];
cns.forEach
(function(row) {
var cmd = row.match(/([0-9]+\s?)?(.*)/);
var cmds = [], tmp;
if(cmd) {
while(cmd[2]) {
expr = cmd[2].match(/(:*[A-Z_][0-9_A-Z]*)(\s*)("[^"]*"|[^:]*)*/i);//.exec(cmd[2]);
if(expr) {
tmp = [expr[1], expr[2] || "", expr[3] || ""];
cmd[2] = cmd[2].substr(tmp.join("").length);
if(":" == tmp[0].charAt(0))
tmp[0] = tmp[0].replace(/^:+/, "");
cmds.push([tmp[0], tmp[2]]);
} else
break;
}
if(cmd[1]) {
id = parseInt(cmd[1], 10);
idd = (id - id % 10) / 10 - 100;
if(id < 1000)
Program.unshift(cmds);
else
if(id % 10)
if(cmd[1])
Program.splice(idd, 0, cmds);
else
Program.splice(idd, 1);
else
if(cmds)
Program[idd] = cmds;
else
Program.splice(idd, 1);
} else
ParseRow(cmds, -1);
}
});
// document.getElementById("Logs").innerHTML = log.join("<br />");
Exec();
}
window.onload = function() {
Input = document.getElementById("Input");
Monitor = document.getElementById("Monitor");
Input.addEventListener(
"keydown", function() {
if(13 == event.keyCode) {
Monitor.innerHTML += this.textContent;
Vars[VarId] = this.textContent;
Watcher(this);
window.event.returnValue = false;
this.textContent = "";
return false;
}
}
);
Input.focus();
}</script>
</head>
<body>
<pre><span id=Monitor></span><pre id=Input contenteditable=true>
1000 ..Copyright (C) 2018 by Alikberov..
1010 CLS:HEY "Hello, World!":HEY _
1020 DEF Ask:HUE FE8:HEY "Your Name?"
1030 ASK N$:HEY:IF N$:IS "":AT Ask:INK 37D
1040 HEY "I'm glad to see You, "
1050 HEY N$
1060 END
RUN</pre>
</pre>
<pre id=Logs></pre>
</body>