Skin:
[NORMAL]
[BLUE] [DOS] [LIGHT]  / コピーするための表示 / 実行
このファイル: /home/web6047/www/cgi-bin/prj/20180320-javascript/ソースブロック解析/javascript.html
1 <!DOCTYPE html><!--ESCAPEPROCESS-->
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 // usage: var txt = ( function() { /*multiTXT*/ } ).toString().match( HereDocument )[ 1 ];
12
13 /* このプログラムの構造
14 onloadx() -> js/script2block()
15 onloadx() -> js/debugprint1()
16 タイマ割込 -> run()
17 データ script
18 [explain]
19 開発途中です。
20 */
21
22 var script = ( function() { /*
23 a = 0;
24 if( a == 0 ) {
25 console.log( "123" );
26 } else if( a == 1 ) {
27 console.log( "321" );
28 } else
29 console.log( "111" );
30 if( a == 2 ) alert(1);
31 else {
32 alert(2);
33 }
34 test = 0;
35 while( test < 3 ) test++;
36 if( a == 3 ) console.log( 222 );
37 else console.log( 333 );
38 for( i = 0; i < 2; i++ ) {
39 console.log( i );
40 }
41 */ } ).toString().match( HereDocument )[ 1 ];
42
43 function onloadx() {
44 topBlock = script2block( "top", null, null, null, script );
45 //check( block, "" );
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 //check. ブロックの終了時
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 //10 0
83 //01 10
84 //00 11
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 }//while
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>