-
Notifications
You must be signed in to change notification settings - Fork 0
/
behave.js
48 lines (35 loc) · 1.28 KB
/
behave.js
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
// sbul: simple-basic-uniform-language
var local_variables = {}
function line_part_eval(line_parts, index) {
var line_part = line_parts[index]
line_part = line_part.replace(/\+/g, " ")
if (line_part == ".comment") return
if (line_part[0] == ".") {
if (line_part == ".array_count:1") {
return line_part_eval(line_parts, index + 1).length
}
if (line_part == ".append:2") {
local_variables[line_part_eval(line_parts, index + 1)] += line_part_eval(line_parts, index + 2)
}
if (line_part == ".console_log:1") {
var text = line_part_eval(line_parts, index + 1)
console.log(text)
stdout.textContent += text
}
if (line_part == ".local_variable_set:2") {
local_variables[line_part_eval(line_parts, index + 1)] = line_part_eval(line_parts, index + 2)
}
if (line_part == ".local_variable_get:1") {
return local_variables[line_part_eval(line_parts, index + 1)]
}
} else {
var json = JSON.parse(line_part)
return json
}
}
function execute_program(program) {
for (var line of program.trim().split("\n")) {
var line_parts = line.trim().split(" ")
line_part_eval(line_parts, 0)
}
}