このファイル: /home/web6047/www/cgi-bin/prj/20180320-javascript/ソースブロック解析/javascript.html
1
<!DOCTYPE html>
2
<head>
3
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
4
<title>untitled canvas</title>
5
<script src="block.js"></script>
6
<script>
7
console.log( "=============== script ==============" );
8
9
function $( id ) { return document.getElementById( id ); }
10
var HereDocument = /\/\*\s*([^]*?)\s*\*\//;
11
12
13
14
15
16
17
18
19
20
21
22
var script = ( function() {
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
} ).toString().match( HereDocument )[ 1 ];
42
43
function onloadx() {
44
topBlock = script2block( "top", null, null, null, script );
45
46
47
currentBlock = topBlock;
48
console.log( "=== debugprint1 ===" );
49
debugprint1( currentBlock, "" );
50
console.log( "=== /debugprint1 ===" );
51
timerID = setInterval( run, 1000 );
52
}
53
54
function run() {
55
while( 1 ) {
56
57
if( currentBlock.programcounter == currentBlock.children.length ) {
58
switch( currentBlock.ctrltype ) {
59
case "top":
60
clearInterval( timerID );
61
console.log( "ok." );
62
return;
63
case "for":
64
eval( currentBlock.ctrlcalc );
65
case "while":
66
if( eval( currentBlock.ctrlcond ) ) {
67
currentBlock.programcounter = 0;
68
break;
69
}
70
case "if":
71
case "else if":
72
case "else":
73
currentBlock = currentBlock.returnBlock;
74
currentBlock.programcounter ++;
75
continue;
76
}
77
}
78
79
with( currentBlock ) {
80
console.log( ctrltype, ctrlcond, programcounter );
81
}
82
83
84
85
var child = currentBlock.children[ currentBlock.programcounter ];
86
if( typeof child === "object" ) {
87
console.log( "object:", child.ctrltype );
88
var doEnterBlock = false;
89
if( child.ctrltype == "if" ||
90
currentBlock.doRelay && child.ctrltype == "else if" ) {
91
92
if( eval( child.ctrlcond ) )
93
doEnterBlock = true;
94
else
95
currentBlock.doRelay = true;
96
97
} else if( currentBlock.doRelay && child.ctrltype == "else"
98
|| child.ctrltype == "while" && eval( child.ctrlcond ) )
99
doEnterBlock = true;
100
else if( child.ctrltype == "for" ) {
101
eval( child.ctrlinit );
102
if( eval( child.ctrlcond ) ) doEnterBlock = true;
103
}
104
105
if( doEnterBlock ) {
106
currentBlock.doRelay = false;
107
child.returnBlock = currentBlock;
108
currentBlock = child;
109
currentBlock.programcounter = 0;
110
} else
111
currentBlock.programcounter ++;
112
113
} else {
114
console.log( child );
115
eval( child );
116
currentBlock.programcounter ++;
117
return;
118
}
119
}
120
}
121
122
</script>
123
<style>
124
</style>
125
</head>
126
<body onload="onloadx();" style="">
127
JavaScriptの実行をブラウザにまかせるのではなく、JavaScriptを解析して、自分でif文、while文、for文などを制御して実行するというものです。<BR>
128
1行1行自分で制御することができれば、RPGのイベントスクリプトとしてJavaScriptを採用できるようになります。<BR>
129
また、JavaScript自体をアニメ制御として使用することもできるようになります。<BR>
130
開発途中で、結果は主にJavaScriptコンソールに表示していますが、何をやっているのかはわかりづらいと思います。<BR>
131
<BR>
132
d_kawakawa
133
</body>
134
</html>