-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpret.php
More file actions
101 lines (88 loc) · 2.44 KB
/
interpret.php
File metadata and controls
101 lines (88 loc) · 2.44 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
<?php
/* KRPL interpreter */
function interpretToJson($in, $out) {
$file = file($in);
$actions = array();
$lnCount = 0;
for ($j = 0, $c = count($file); $j < $c; $j++) {
$line = trim($file[$j]);
$obj = null;
if (strlen($line) > 0 && $line{0} != '#' && $line{0} != '{') {
$obj = new stdClass();
$obj->code = $line;
if ($line{0} == '@') {
$obj->label = str_replace('@', '', $line);
$obj->code = '';
}
}
/* if (strlen($line) > 0) {
$words = explode(' ', $line);
$obj = new stdClass();
// Check for variable assignment
if (count($words) > 1) {
switch ($words[1]) {
case '=':
$obj->action = 'assign';
$obj->name = $words[0];
$obj->value = str_replace($obj->name . ' = ', '', $line);
$obj->operation = '=';
break;
case '*=':
$obj->action = 'assign';
$obj->name = $words[0];
$obj->value = str_replace($obj->name . ' *= ', '', $line);
$obj->operation = '*=';
break;
case '+=':
$obj->action = 'assign';
$obj->name = $words[0];
$obj->value = str_replace($obj->name . ' += ', '', $line);
$obj->operation = '+=';
break;
default:
if ($line{0} == '#' || $line{0} == '{') {
$obj = null;
} else {
$obj->action = 'function';
$obj->name = $words[0];
if (preg_match('/\((.*?)\)/', $line, $p)) {
$params = explode(',', $p[1]);
for ($i = 0, $count = count($params); $i < $count; $i++) {
$params[$i] = trim($params[$i]);
}
$obj->params = $params;
$obj->extra = str_replace($obj->name . ' ' . $p[0] . ' ', '', $line);
} else {
$obj->params = str_replace($obj->name . ' ', '', $line);
}
}
break;
}
} else {
if ($line{0} == '@') {
$obj->action = 'label';
$obj->name = str_replace('@', '', trim($words[0]));
} else if ($line{0} == '#' || $line{0} == '{') {
$obj = null;
} else {
$obj->action = 'function';
$obj->name = $line;
}
}
} */
if (null !== $obj) {
$lnCount++;
$obj->ln = $j;
$actions[] = $obj;
}
}
$out = new stdClass();
$out->code = $actions;
$out->scene = $_GET['id'];
return json_encode($out);
}
$id = $_GET['id'];
while (strlen($id) < 4) {
$id = '0' . $id;
}
echo interpretToJson('./KANON_SE/scenario/SEEN' . $id . '.ke', '');