|
| 1 | +//상수, constants |
| 2 | +cheossori = new Array("ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"); |
| 3 | +holsori = new Array("ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"); |
| 4 | +batchim = new Array(" ", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"); |
| 5 | +batchim_hoek = new Array(0, 2, 4, 4, 2, 5, 5, 3, 5, 7, 9, 9, 7, 9, 9, 8, 4, 4, 6, 2, 4, 1, 3, 4, 3, 4, 4, 3); |
| 6 | +required_elem = new Array(0, 0, 2, 2, 2, 2, 1, 0, 1, 0, 1, 0, 2, 0, 1, 0, 2, 2, 0); |
| 7 | + |
| 8 | +//변수, variables |
| 9 | +var code_gonggan = new Array; //codespace |
| 10 | +var stack = new Array(28); |
| 11 | +var stack_index = new Number; |
| 12 | + |
| 13 | +var x = new Number; |
| 14 | +var y = new Number; |
| 15 | +var dx = new Number; |
| 16 | +var dy = new Number; |
| 17 | +var timer = new Number; |
| 18 | +var debug = new Boolean(true); |
| 19 | +var meomchum = new Boolean(true); //is_stopped |
| 20 | +var input_buffer = new String; |
| 21 | + |
| 22 | +//함수, functions |
| 23 | + |
| 24 | +function haechae(c){ //disassembles a Hangul character into parts |
| 25 | + if(c < 0xAC00 || c > 0xD7A3) return ""; |
| 26 | + c -= 0xAC00; |
| 27 | + return new Array(Math.floor(c/28/21), Math.floor(c/28) % 21, c % 28); |
| 28 | +} |
| 29 | + |
| 30 | +function push(i, n){ |
| 31 | + switch(i){ |
| 32 | + case 27: break; //ㅎ |
| 33 | + default: stack[i].push(parseInt(n)); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +function pop(i){ |
| 38 | + switch(i){ |
| 39 | + case 21: return parseInt(stack[i].shift()); //ㅇ |
| 40 | + case 27: break; //ㅎ |
| 41 | + default: return parseInt(stack[i].pop()); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +function output(obj){ |
| 46 | + document.forms[0].output.value += obj; |
| 47 | +} |
| 48 | + |
| 49 | +function debug_sseo(){ //write debug info |
| 50 | + str = msg_coordinate + "(" + x + ", " + y + ")" + '\n' + msg_character + code_gonggan[y].charAt(x) + '\n'; |
| 51 | + for(i=0; i<28; i++){ |
| 52 | + if(i == stack_index) str += '>'; |
| 53 | + stack[i].reverse(); |
| 54 | + str += String.fromCharCode(0xc544 + i) + ": " + stack[i] + '\n'; |
| 55 | + stack[i].reverse(); |
| 56 | + } |
| 57 | + document.forms[0].dumps.value = str; |
| 58 | +} |
| 59 | + |
| 60 | +function chogi(){ //initialize |
| 61 | + meomchum = true; |
| 62 | + clearTimeout(timer); |
| 63 | + |
| 64 | + input_buffer = ""; |
| 65 | + |
| 66 | + x = 0; dx = 0; |
| 67 | + y = 0; dx = 0; |
| 68 | + code_gonggan = document.forms[0].aheui.value.split('\n'); |
| 69 | + |
| 70 | + stack_index = 0; |
| 71 | + for(i=0; i<28; i++) stack[i] = new Array; |
| 72 | + |
| 73 | + document.forms[0].output.value = ""; |
| 74 | + document.forms[0].dumps.value = ""; |
| 75 | +} |
| 76 | + |
| 77 | +function cursor_omgyeo(){ //move cursor |
| 78 | + x+=dx; y+=dy; |
| 79 | + |
| 80 | + if(y<0) y = code_gonggan.length-1; |
| 81 | + if(y>=code_gonggan.length) y = 0; |
| 82 | + |
| 83 | + if(x<0) x = code_gonggan[y].length-1; |
| 84 | + if(x>=code_gonggan[y].length && dx!=0) x = 0; |
| 85 | +} |
| 86 | + |
| 87 | +function dan_gye(han_beon){ //step; han_beon means whether it executes a single step |
| 88 | + if(!han_beon){ |
| 89 | + if(meomchum){ clearTimeout(timer); return; } |
| 90 | + if(timer) clearTimeout(timer); |
| 91 | + } |
| 92 | + |
| 93 | + code_gonggan = document.forms[0].aheui.value.split('\n'); |
| 94 | + |
| 95 | + k = han_beon ? 1 : 100; |
| 96 | + while(k-- > 0){ |
| 97 | + if(!han_beon && meomchum) break; |
| 98 | + |
| 99 | + if(x >= code_gonggan[y].length){ |
| 100 | + cursor_omgyeo(); |
| 101 | + continue; |
| 102 | + } |
| 103 | + c = code_gonggan[y].charCodeAt(x); |
| 104 | + if(c < 0xac00 || c > 0xd7a3){ |
| 105 | + cursor_omgyeo(); |
| 106 | + continue; |
| 107 | + } |
| 108 | + ch = haechae(c); |
| 109 | + |
| 110 | + switch(ch[1]){ |
| 111 | + case 0: dx=1; dy=0; break; //ㅏ |
| 112 | + case 2: dx=2; dy=0; break; //ㅑ |
| 113 | + case 4: dx=-1; dy=0; break; //ㅓ |
| 114 | + case 6: dx=-2; dy=0; break; //ㅕ |
| 115 | + case 8: dx=0; dy=-1; break; //ㅗ |
| 116 | + case 12: dx=0; dy=-2; break; //ㅛ |
| 117 | + case 13: dx=0; dy=1; break; //ㅜ |
| 118 | + case 17: dx=0; dy=2; break; //ㅠ |
| 119 | + |
| 120 | + case 18: dy=-dy; break; //ㅡ |
| 121 | + case 19: dx=-dx; dy=-dy; break; //ㅢ |
| 122 | + case 20: dx=-dx; break; //ㅣ |
| 123 | + |
| 124 | + case 1: //ㅐ |
| 125 | + case 3: //ㅒ |
| 126 | + case 5: //ㅔ |
| 127 | + case 7: //ㅖ |
| 128 | + case 9: //ㅘ |
| 129 | + case 10: //ㅙ |
| 130 | + case 11: //ㅚ |
| 131 | + case 14: //ㅝ |
| 132 | + case 15: //ㅞ |
| 133 | + case 16: //ㅟ |
| 134 | + default: |
| 135 | + } |
| 136 | + |
| 137 | + if(stack[stack_index].length < required_elem[ch[0]]){ dx=-dx; dy=-dy; } |
| 138 | + else switch(ch[0]){ |
| 139 | + case 2: a = pop(stack_index); b = pop(stack_index); push(stack_index, b/a); break; //ㄴ |
| 140 | + case 3: a = pop(stack_index); b = pop(stack_index); push(stack_index, b+a); break; //ㄷ |
| 141 | + case 4: a = pop(stack_index); b = pop(stack_index); push(stack_index, b*a); break; //ㄸ |
| 142 | + case 5: a = pop(stack_index); b = pop(stack_index); push(stack_index, b%a); break; //ㄹ |
| 143 | + case 6: //ㅁ |
| 144 | + switch(ch[2]){ |
| 145 | + case 21: output(pop(stack_index)); break; //ㅇ |
| 146 | + case 27: output(String.fromCharCode(pop(stack_index))); break; //ㅎ |
| 147 | + default: pop(stack_index); |
| 148 | + } |
| 149 | + break; |
| 150 | + case 7: //ㅂ |
| 151 | + switch(ch[2]){ |
| 152 | + case 21: |
| 153 | + k = prompt(msg_input_number); |
| 154 | + if(k == "!!!"){ meomchum=true; return; } |
| 155 | + push(stack_index, k); break; //ㅇ |
| 156 | + case 27: |
| 157 | + while(!input_buffer){ |
| 158 | + input_buffer = prompt(msg_input_character); |
| 159 | + if(input_buffer == "!!!"){ meomchum=true; return; } |
| 160 | + } |
| 161 | + push(stack_index, input_buffer.charCodeAt(0)); |
| 162 | + input_buffer = input_buffer.substring(1); break; //ㅎ |
| 163 | + default: push(stack_index, batchim_hoek[ch[2]]); break; |
| 164 | + } |
| 165 | + break; |
| 166 | + case 8: //ㅃ |
| 167 | + switch(stack_index){ |
| 168 | + case 21: stack[21].unshift(stack[21][0]); break; //ㅇ |
| 169 | + case 27: break; //ㅎ |
| 170 | + default: stack[stack_index].push(stack[stack_index][stack[stack_index].length-1]); |
| 171 | + } |
| 172 | + break; |
| 173 | + case 9: stack_index = ch[2]; break; //ㅅ |
| 174 | + case 10: push(ch[2], pop(stack_index)); break; //ㅆ |
| 175 | + case 12: a = pop(stack_index); b = pop(stack_index); push(stack_index, (b>=a) ? 1:0); break; //ㅈ |
| 176 | + case 14: if(pop(stack_index) == 0){ dx=-dx; dy=-dy; } break; //ㅊ |
| 177 | + case 16: a = pop(stack_index); b = pop(stack_index); push(stack_index, b-a); break; //ㅌ |
| 178 | + case 17: //ㅍ |
| 179 | + switch(stack_index){ |
| 180 | + case 21: a = stack[21][0]; stack[21][0] = stack[21][1]; stack[21][1] = a; break; //ㅇ |
| 181 | + case 27: break; //ㅎ |
| 182 | + default: a = pop(stack_index); b = pop(stack_index); push(stack_index, a); push(stack_index, b); |
| 183 | + } |
| 184 | + break; //ㅍ |
| 185 | + case 18: meomchum = true; break; //ㅎ |
| 186 | + |
| 187 | + case 0: //ㄱ |
| 188 | + case 1: //ㄲ |
| 189 | + case 11: //ㅇ |
| 190 | + case 13: //ㅉ |
| 191 | + case 15: //ㅋ |
| 192 | + default: |
| 193 | + } |
| 194 | + |
| 195 | + if(document.forms[0].debug.checked) debug_sseo(); |
| 196 | + cursor_omgyeo(); |
| 197 | + } |
| 198 | + |
| 199 | + if(!han_beon && !meomchum) timer = setTimeout('dan_gye(false)', 0); |
| 200 | +} |
| 201 | + |
| 202 | +function silhaeng(){ //execute |
| 203 | + chogi(); |
| 204 | + |
| 205 | + meomchum = false; |
| 206 | + dan_gye(false); |
| 207 | +} |
0 commit comments