1 | #include "../BasicCompiler_Common/common.h"
|
---|
2 |
|
---|
3 | CONSTINFO *GetNewConstHash(char *name){
|
---|
4 | extern int cp;
|
---|
5 | CONSTINFO *pci;
|
---|
6 |
|
---|
7 | int key;
|
---|
8 | key=hash_default(name);
|
---|
9 |
|
---|
10 | extern CONSTINFO **ppConstHash;
|
---|
11 | if(ppConstHash[key]){
|
---|
12 | pci=ppConstHash[key];
|
---|
13 | while(1){
|
---|
14 | if(lstrcmp(pci->name,name)==0){
|
---|
15 | //重複エラー
|
---|
16 | SetError(15,name,cp);
|
---|
17 | return 0;
|
---|
18 | }
|
---|
19 |
|
---|
20 | if(pci->pNextData==0){
|
---|
21 | pci->pNextData=(CONSTINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(CONSTINFO));
|
---|
22 | break;
|
---|
23 | }
|
---|
24 | pci=pci->pNextData;
|
---|
25 | }
|
---|
26 | pci=pci->pNextData;
|
---|
27 | }
|
---|
28 | else{
|
---|
29 | ppConstHash[key]=(CONSTINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(CONSTINFO));
|
---|
30 | pci=ppConstHash[key];
|
---|
31 | }
|
---|
32 |
|
---|
33 | return pci;
|
---|
34 | }
|
---|
35 |
|
---|
36 | // マクロ定数を追加するための関数
|
---|
37 | void AddConstData(char *Command){
|
---|
38 | extern HANDLE hHeap;
|
---|
39 | extern int cp;
|
---|
40 | int i,i2;
|
---|
41 | char temporary[VN_SIZE];
|
---|
42 |
|
---|
43 | for(i=0;;i++){
|
---|
44 | if(Command[i]=='\0'){
|
---|
45 | SetError(10,"Const",cp);
|
---|
46 | return;
|
---|
47 | }
|
---|
48 | if(Command[i]=='=' || Command[i] == 1 && Command[i+1] == ESC_AS ){
|
---|
49 | //定数定義は新しいクラスモジュール(CDBConst)へ移行
|
---|
50 | // ※この関数はマクロ定数のみを扱う
|
---|
51 | return;
|
---|
52 | }
|
---|
53 | if(Command[i]=='('){
|
---|
54 | temporary[i]=0;
|
---|
55 | break;
|
---|
56 | }
|
---|
57 | temporary[i]=Command[i];
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | /////////////////////////////////
|
---|
62 | // 格納位置を計算してpciにセット
|
---|
63 | /////////////////////////////////
|
---|
64 |
|
---|
65 | CONSTINFO *pci;
|
---|
66 | pci=GetNewConstHash(temporary);
|
---|
67 | if(!pci) return;
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | ////////////////////
|
---|
72 | // 定数情報を取得
|
---|
73 | ////////////////////
|
---|
74 |
|
---|
75 | //定数名
|
---|
76 | pci->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
|
---|
77 | lstrcpy(pci->name,temporary);
|
---|
78 |
|
---|
79 | if(Command[i]=='('){
|
---|
80 | pci->ppParm=(char **)HeapAlloc(hHeap,0,1);
|
---|
81 | pci->ParmNum=0;
|
---|
82 | for(i++,i2=0;;i++,i2++){
|
---|
83 | if(Command[i]=='\0'){
|
---|
84 | SetError(1,NULL,cp);
|
---|
85 | return;
|
---|
86 | }
|
---|
87 | if(Command[i]==','||Command[i]==')'){
|
---|
88 | temporary[i2]=0;
|
---|
89 | pci->ppParm=(char **)HeapReAlloc(hHeap,0,pci->ppParm,(pci->ParmNum+1)*sizeof(char *));
|
---|
90 | pci->ppParm[pci->ParmNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
|
---|
91 | lstrcpy(pci->ppParm[pci->ParmNum],temporary);
|
---|
92 | pci->ParmNum++;
|
---|
93 | if(Command[i]==')'){
|
---|
94 | i++;
|
---|
95 | if(Command[i]!='='){
|
---|
96 | SetError(1,NULL,cp);
|
---|
97 | return;
|
---|
98 | }
|
---|
99 | break;
|
---|
100 | }
|
---|
101 |
|
---|
102 | i2=-1;
|
---|
103 | continue;
|
---|
104 | }
|
---|
105 | temporary[i2]=Command[i];
|
---|
106 | }
|
---|
107 | }
|
---|
108 | else pci->ParmNum=0;
|
---|
109 |
|
---|
110 | //データ
|
---|
111 | lstrcpy(temporary,Command+i+1);
|
---|
112 | if(pci->ParmNum){
|
---|
113 | pci->StrValue=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
|
---|
114 | lstrcpy(pci->StrValue,temporary);
|
---|
115 | }
|
---|
116 | else if(temporary[0]=='\"'){
|
---|
117 | //文字列定数
|
---|
118 | RemoveStringQuotes(temporary);
|
---|
119 | i2=lstrlen(temporary);
|
---|
120 |
|
---|
121 | pci->StrValue=(char *)HeapAlloc(hHeap,0,i2+1);
|
---|
122 | memcpy(pci->StrValue,temporary,i2);
|
---|
123 | pci->StrValue[i2]=0;
|
---|
124 |
|
---|
125 | pci->DblValue=(double)i2;
|
---|
126 |
|
---|
127 | pci->type=DEF_STRING;
|
---|
128 | pci->lpIndex=-1;
|
---|
129 | }
|
---|
130 | else if((temporary[0]=='e'||temporary[0]=='E')&&
|
---|
131 | (temporary[1]=='x'||temporary[1]=='X')&&
|
---|
132 | temporary[2]=='\"'){
|
---|
133 | //文字列定数
|
---|
134 | RemoveStringQuotes(temporary+2);
|
---|
135 | i2=FormatString_EscapeSequence(temporary+2);
|
---|
136 | pci->StrValue=(char *)HeapAlloc(hHeap,0,i2+1);
|
---|
137 | memcpy(pci->StrValue,temporary+2,i2);
|
---|
138 | pci->StrValue[i2]=0;
|
---|
139 |
|
---|
140 | pci->DblValue=(double)i2;
|
---|
141 |
|
---|
142 | pci->type=DEF_STRING;
|
---|
143 | pci->lpIndex=-1;
|
---|
144 | }
|
---|
145 | else{
|
---|
146 | //数値定数
|
---|
147 | _int64 i64data;
|
---|
148 | Type resultType;
|
---|
149 | StaticCalculation(true, temporary,0,&i64data,resultType);
|
---|
150 | pci->type=resultType.GetBasicType();
|
---|
151 | if(IsRealNumberType(pci->type)){
|
---|
152 | //実数型
|
---|
153 | memcpy(&pci->DblValue,&i64data,sizeof(double));
|
---|
154 | }
|
---|
155 | else if(Is64Type(pci->type)){
|
---|
156 | //64ビット型
|
---|
157 | pci->i64Value=i64data;
|
---|
158 | }
|
---|
159 | else if(IsWholeNumberType(pci->type)){
|
---|
160 | //その他整数型
|
---|
161 | pci->DblValue=(double)i64data;
|
---|
162 | }
|
---|
163 |
|
---|
164 | pci->StrValue=0;
|
---|
165 | }
|
---|
166 | }
|
---|
167 | void AddConstEnum(char *buffer){
|
---|
168 | extern int cp;
|
---|
169 | int i=0,i2;
|
---|
170 |
|
---|
171 | if(!(buffer[i]==1&&buffer[i+1]==ESC_ENUM)) return;
|
---|
172 | i+=2;
|
---|
173 |
|
---|
174 | //列挙体の名前を取得
|
---|
175 | char temporary[VN_SIZE];
|
---|
176 | for(i2=0;;i++,i2++){
|
---|
177 | if(IsCommandDelimitation(buffer[i])){
|
---|
178 | temporary[i2]=0;
|
---|
179 | break;
|
---|
180 | }
|
---|
181 | if(!IsVariableChar(buffer[i])){
|
---|
182 | SetError(1,NULL,i);
|
---|
183 | break;
|
---|
184 | }
|
---|
185 | temporary[i2]=buffer[i];
|
---|
186 | }
|
---|
187 |
|
---|
188 | if(buffer[i]=='\0'){
|
---|
189 | SetError(22,"Enum",cp);
|
---|
190 | return;
|
---|
191 | }
|
---|
192 |
|
---|
193 | int NextValue=0;
|
---|
194 | while(1){
|
---|
195 | i++;
|
---|
196 |
|
---|
197 | if(buffer[i]==1&&buffer[i+1]==ESC_ENDENUM) break;
|
---|
198 |
|
---|
199 | for(i2=0;;i2++,i++){
|
---|
200 | if(IsCommandDelimitation(buffer[i])){
|
---|
201 | temporary[i2]=0;
|
---|
202 | break;
|
---|
203 | }
|
---|
204 | if(buffer[i]=='='){
|
---|
205 | temporary[i2]=0;
|
---|
206 | break;
|
---|
207 | }
|
---|
208 | temporary[i2]=buffer[i];
|
---|
209 | }
|
---|
210 | if(temporary[0]=='\0'){
|
---|
211 | if(buffer[i]=='\0'){
|
---|
212 | SetError(22,"Enum",cp);
|
---|
213 | break;
|
---|
214 | }
|
---|
215 | continue;
|
---|
216 | }
|
---|
217 |
|
---|
218 | if(buffer[i]!='='){
|
---|
219 | NextValue++;
|
---|
220 | }
|
---|
221 | else{
|
---|
222 | char temp2[VN_SIZE];
|
---|
223 | for(i++,i2=0;;i2++,i++){
|
---|
224 | if(IsCommandDelimitation(buffer[i])){
|
---|
225 | temp2[i2]=0;
|
---|
226 | break;
|
---|
227 | }
|
---|
228 | temp2[i2]=buffer[i];
|
---|
229 | }
|
---|
230 |
|
---|
231 | _int64 i64data;
|
---|
232 | StaticCalculation(true, temp2,DEF_LONG,&i64data,Type());
|
---|
233 | NextValue=(int)i64data;
|
---|
234 | }
|
---|
235 |
|
---|
236 | //定数を追加
|
---|
237 | CDBConst::obj.AddConst(temporary, NextValue);
|
---|
238 | }
|
---|
239 | }
|
---|
240 | bool GetConstInfo(void){
|
---|
241 | ////////////////////////////////////////////
|
---|
242 | // Const命令の情報を取得
|
---|
243 | ////////////////////////////////////////////
|
---|
244 |
|
---|
245 | int i,i2;
|
---|
246 | char temporary[1024];
|
---|
247 |
|
---|
248 | //定数に関する情報
|
---|
249 | extern CONSTINFO **ppConstHash;
|
---|
250 | ppConstHash=(CONSTINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(CONSTINFO *));
|
---|
251 |
|
---|
252 | extern char *basbuf;
|
---|
253 | for(i=0;;i++){
|
---|
254 | if( basbuf[i] == '\0' ) break;
|
---|
255 | if( basbuf[i] == 1 ){
|
---|
256 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CONST){
|
---|
257 | i+=2;
|
---|
258 |
|
---|
259 | extern int cp;
|
---|
260 | cp=i; //エラー用
|
---|
261 |
|
---|
262 |
|
---|
263 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENUM){
|
---|
264 | AddConstEnum(basbuf+i);
|
---|
265 | continue;
|
---|
266 | }
|
---|
267 |
|
---|
268 | for(i2=0;;i++,i2++){
|
---|
269 | if(basbuf[i]=='\"'){
|
---|
270 | temporary[i2]=basbuf[i];
|
---|
271 | for(i++,i2++;;i++,i2++){
|
---|
272 | temporary[i2]=basbuf[i];
|
---|
273 | if(basbuf[i]=='\"') break;
|
---|
274 | }
|
---|
275 | continue;
|
---|
276 | }
|
---|
277 | if(IsCommandDelimitation(basbuf[i])){
|
---|
278 | temporary[i2]=0;
|
---|
279 | break;
|
---|
280 | }
|
---|
281 | temporary[i2]=basbuf[i];
|
---|
282 | }
|
---|
283 | CDBConst::obj.Add(temporary);
|
---|
284 | if(basbuf[i]=='\0') break;
|
---|
285 | }
|
---|
286 | else{
|
---|
287 | int result = JumpStatement( basbuf, i );
|
---|
288 | if( result == -1 ){
|
---|
289 | //エラー
|
---|
290 | return false;
|
---|
291 | }
|
---|
292 | else if( result == 1 ){
|
---|
293 | //ジャンプした場合
|
---|
294 | i--;
|
---|
295 | }
|
---|
296 | }
|
---|
297 | }
|
---|
298 | }
|
---|
299 | return true;
|
---|
300 | }
|
---|
301 |
|
---|
302 | char ConstructorDestructorSchedule[MAX_PATH];
|
---|
303 | void MakeConstructorAndDestructor(char *buffer,int nowLine,char *ClassName){
|
---|
304 | int i,i2;
|
---|
305 | char temporary[MAX_PATH],*pTemp;
|
---|
306 | BOOL bConstructor,bDestructor;
|
---|
307 |
|
---|
308 | ConstructorDestructorSchedule[0]=0;
|
---|
309 | bConstructor=0;
|
---|
310 | bDestructor=0;
|
---|
311 |
|
---|
312 | for(i=nowLine;;i++){
|
---|
313 | if(buffer[i]=='\0') break;
|
---|
314 | if(buffer[i]==1&&buffer[i+1]==ESC_ENDCLASS){
|
---|
315 | if((!bConstructor)||(!bDestructor)){
|
---|
316 | pTemp=ConstructorDestructorSchedule;
|
---|
317 |
|
---|
318 | lstrcpy(pTemp,"Public:");
|
---|
319 |
|
---|
320 | if(!bConstructor){
|
---|
321 | //コンストラクタが無いときは生成する
|
---|
322 | sprintf(pTemp+lstrlen(pTemp),"%c%c%s():%c%c:",
|
---|
323 | 1,ESC_SUB,
|
---|
324 | ClassName,
|
---|
325 | 1,ESC_ENDSUB);
|
---|
326 | }
|
---|
327 |
|
---|
328 | if(!bDestructor){
|
---|
329 | //デストラクタが無いときは生成する
|
---|
330 | sprintf(pTemp+lstrlen(pTemp),"%c%c~%s():%c%c:",
|
---|
331 | 1,ESC_SUB,
|
---|
332 | ClassName,
|
---|
333 | 1,ESC_ENDSUB);
|
---|
334 | }
|
---|
335 | }
|
---|
336 | break;
|
---|
337 | }
|
---|
338 |
|
---|
339 | if(buffer[i]==1&&(buffer[i+1]==ESC_SUB||buffer[i+1]==ESC_FUNCTION)){
|
---|
340 | i+=2;
|
---|
341 | while(IsBlank(buffer[i])) i++;
|
---|
342 | if(buffer[i]=='~'){
|
---|
343 | //デストラクタ
|
---|
344 | bDestructor=1;
|
---|
345 | }
|
---|
346 | else{
|
---|
347 | //コンストラクタかどうかをチェック
|
---|
348 | for(i2=0;;i++,i2++){
|
---|
349 | if(!IsVariableChar(buffer[i])){
|
---|
350 | temporary[i2]=0;
|
---|
351 | break;
|
---|
352 | }
|
---|
353 | temporary[i2]=buffer[i];
|
---|
354 | }
|
---|
355 | if(lstrcmp(temporary,ClassName)==0) bConstructor=1;
|
---|
356 | }
|
---|
357 | }
|
---|
358 | }
|
---|
359 | }
|
---|
360 | void ChangeCommand(char *buffer,int nowLine,char *Command){
|
---|
361 | int i,i2,IsStr;
|
---|
362 | unsigned _int16 ComNum;
|
---|
363 | char com[8192],pam[8192];
|
---|
364 |
|
---|
365 | static int nCountOfNonGlobalScope = 0;
|
---|
366 |
|
---|
367 | if(Command[0]==1){
|
---|
368 | switch(Command[1]){
|
---|
369 | case ESC_SELECTCASE:
|
---|
370 | case ESC_CASE:
|
---|
371 | KillStringSpaces(Command+2);
|
---|
372 | break;
|
---|
373 | case ESC_WITH:
|
---|
374 | KillStringSpaces(Command+2);
|
---|
375 | break;
|
---|
376 | case ESC_TYPEDEF:
|
---|
377 | KillStringSpaces(Command+2);
|
---|
378 | break;
|
---|
379 | case ESC_DECLARE:
|
---|
380 | KillStringSpaces(Command+2);
|
---|
381 | break;
|
---|
382 | case ESC_IF:
|
---|
383 | KillStringSpaces(Command+2);
|
---|
384 | break;
|
---|
385 |
|
---|
386 | case ESC_CLASS:
|
---|
387 | KillStringSpaces(Command+2);
|
---|
388 |
|
---|
389 | //コンストラクタ、デストラクタを暗黙的に生成
|
---|
390 | MakeConstructorAndDestructor(buffer,nowLine,Command+2);
|
---|
391 | break;
|
---|
392 | case ESC_INTERFACE:
|
---|
393 | KillStringSpaces(Command+2);
|
---|
394 | break;
|
---|
395 | case ESC_ENDCLASS:
|
---|
396 | if(ConstructorDestructorSchedule[0]){
|
---|
397 | //生成されたコンストラクタ、デストラクタを挿入
|
---|
398 | sprintf(Command,"%s%c%c",ConstructorDestructorSchedule,1,ESC_ENDCLASS);
|
---|
399 | }
|
---|
400 | break;
|
---|
401 |
|
---|
402 | case ESC_TYPE:
|
---|
403 | KillStringSpaces(Command+2);
|
---|
404 | break;
|
---|
405 |
|
---|
406 | case ESC_CONST:
|
---|
407 | KillStringSpaces(Command+2);
|
---|
408 | if( Command[2] == 1 && Command[3] == ESC_ENUM ){
|
---|
409 | nCountOfNonGlobalScope++;
|
---|
410 | }
|
---|
411 | break;
|
---|
412 |
|
---|
413 | case ESC_ENUM:
|
---|
414 | nCountOfNonGlobalScope++;
|
---|
415 | KillStringSpaces(Command+2);
|
---|
416 | break;
|
---|
417 |
|
---|
418 | case ESC_ENDENUM:
|
---|
419 | nCountOfNonGlobalScope--;
|
---|
420 | break;
|
---|
421 |
|
---|
422 | case ESC_INHERITS:
|
---|
423 | case ESC_VIRTUAL:
|
---|
424 | case ESC_OVERRIDE:
|
---|
425 | case ESC_ABSTRACT:
|
---|
426 | case ESC_SUB:
|
---|
427 | case ESC_FUNCTION:
|
---|
428 | case ESC_MACRO:
|
---|
429 | case ESC_STATIC:
|
---|
430 | KillStringSpaces(Command+2);
|
---|
431 | break;
|
---|
432 | }
|
---|
433 | return;
|
---|
434 | }
|
---|
435 |
|
---|
436 | bool isPare = false;
|
---|
437 | for(i=0;;i++){
|
---|
438 | if(Command[i]==' '||Command[i]=='\t'||Command[i]=='('||Command[i]=='\"'||Command[i]=='@'||Command[i]=='-'){
|
---|
439 | com[i]=0;
|
---|
440 | while(Command[i]==' '||Command[i]=='\t') i++;
|
---|
441 | if( Command[i] == '(' ) isPare = true;
|
---|
442 | break;
|
---|
443 | }
|
---|
444 | if(Command[i]=='='){
|
---|
445 | KillStringSpaces(Command);
|
---|
446 | return;
|
---|
447 | }
|
---|
448 | com[i]=Command[i];
|
---|
449 | if(Command[i]=='\0') break;
|
---|
450 | }
|
---|
451 |
|
---|
452 | //マクロによるコマンド
|
---|
453 | i2=1;
|
---|
454 | if( nCountOfNonGlobalScope == 0 ){
|
---|
455 | //グローバル
|
---|
456 | if(lstrcmpi(com,"Open")==0) ComOpen(Command+i,pam,nowLine);
|
---|
457 | else if(lstrcmpi(com,"Close")==0) ComClose(Command+i,pam);
|
---|
458 | else if(lstrcmpi(com,"Field")==0||
|
---|
459 | lstrcmpi(com,"Get")==0||
|
---|
460 | lstrcmpi(com,"Put")==0) ComField(Command+i,pam);
|
---|
461 | else if(lstrcmpi(com,"Line")==0) ComLine(Command+i,pam,nowLine);
|
---|
462 | else if(lstrcmpi(com,"Circle")==0) ComCircle(Command+i,pam,nowLine);
|
---|
463 | else if(lstrcmpi(com,"PSet")==0) ComPSet(Command+i,pam,nowLine);
|
---|
464 | else if(lstrcmpi(com,"Paint")==0) ComPaint(Command+i,pam,nowLine);
|
---|
465 |
|
---|
466 | else if(
|
---|
467 | lstrcmpi(com,"EXEC")==0||
|
---|
468 | lstrcmpi(com,"INPUT")==0||
|
---|
469 | lstrcmpi(com,"PRINT")==0||
|
---|
470 | lstrcmpi(com,"RANDOMIZE")==0||
|
---|
471 | ( lstrcmpi(com,"WRITE")==0 && isPare == false )||
|
---|
472 | lstrcmpi(com,"MSGBOX")==0||
|
---|
473 | lstrcmpi(com,"WINDOW")==0||
|
---|
474 | lstrcmpi(com,"DELWND")==0||
|
---|
475 | lstrcmpi(com,"INSMENU")==0||
|
---|
476 | lstrcmpi(com,"CHDIR")==0||
|
---|
477 | lstrcmpi(com,"MKDIR")==0||
|
---|
478 | lstrcmpi(com,"KILL")==0||
|
---|
479 | lstrcmpi(com,"CLS")==0||
|
---|
480 | lstrcmpi(com,"COLOR")==0||
|
---|
481 | lstrcmpi(com,"LOCATE")==0
|
---|
482 | ){
|
---|
483 | KillSpaces(Command+i,pam);
|
---|
484 |
|
---|
485 | //大文字に変換
|
---|
486 | CharUpper(com);
|
---|
487 |
|
---|
488 | sprintf(Command,"%s(%s)",com,pam);
|
---|
489 | return;
|
---|
490 | }
|
---|
491 |
|
---|
492 | else i2=0;
|
---|
493 | }
|
---|
494 | else i2=0;
|
---|
495 | if(i2){
|
---|
496 | //大文字に変換
|
---|
497 | CharUpper(com);
|
---|
498 |
|
---|
499 | sprintf(Command,"%s(%s)",com,pam);
|
---|
500 | return;
|
---|
501 | }
|
---|
502 |
|
---|
503 |
|
---|
504 |
|
---|
505 | //コンパイラに搭載されるコマンド
|
---|
506 | if(lstrcmpi(com,"Do")==0){
|
---|
507 | KillSpaces(Command+i,pam);
|
---|
508 | ComNum=COM_DO;
|
---|
509 | }
|
---|
510 | else if(lstrcmpi(com,"goto")==0){
|
---|
511 | KillSpaces(Command+i,pam);
|
---|
512 | ComNum=COM_GOTO;
|
---|
513 | }
|
---|
514 | else if(lstrcmpi(com,"gosub")==0){
|
---|
515 | KillSpaces(Command+i,pam);
|
---|
516 | ComNum=COM_GOSUB;
|
---|
517 | }
|
---|
518 | else if(lstrcmpi(com,"Loop")==0){
|
---|
519 | if((Command[i]=='w'||Command[i]=='W')&&(Command[i+1]=='h'||Command[i+1]=='H')&&(Command[i+2]=='i'||Command[i+2]=='I')&&(Command[i+3]=='l'||Command[i+3]=='L')&&(Command[i+4]=='e'||Command[i+4]=='E')){
|
---|
520 | lstrcpy(pam,"0,");
|
---|
521 | KillSpaces(Command+i+5,pam+2);
|
---|
522 | }
|
---|
523 | else if((Command[i]=='u'||Command[i]=='U')&&(Command[i+1]=='n'||Command[i+1]=='N')&&(Command[i+2]=='t'||Command[i+2]=='T')&&(Command[i+3]=='i'||Command[i+3]=='I')&&(Command[i+4]=='l'||Command[i+4]=='L')){
|
---|
524 | lstrcpy(pam,"1,");
|
---|
525 | KillSpaces(Command+i+5,pam+2);
|
---|
526 | }
|
---|
527 | else pam[0]=0;
|
---|
528 | ComNum=COM_LOOP;
|
---|
529 | }
|
---|
530 | else if(lstrcmpi(com,"For")==0){
|
---|
531 | for(i2=0,IsStr=0;;i++,i2++){
|
---|
532 | while(Command[i]==' '||Command[i]=='\t') i++;
|
---|
533 | if(Command[i]=='\"') IsStr^=1;
|
---|
534 | if((Command[i-1]==' '||Command[i-1]=='\t')&&(Command[i]=='t'||Command[i]=='T')&&(Command[i+1]=='o'||Command[i+1]=='O')&&(Command[i+2]==' '||Command[i+2]=='\t')&&IsStr==0){
|
---|
535 | pam[i2]=',';
|
---|
536 | break;
|
---|
537 | }
|
---|
538 | pam[i2]=Command[i];
|
---|
539 | if(Command[i]=='\0') break;
|
---|
540 | }
|
---|
541 | if(Command[i]){
|
---|
542 | for(i+=3,i2++,IsStr=0;;i++,i2++){
|
---|
543 | while(Command[i]==' '||Command[i]=='\t') i++;
|
---|
544 | if((Command[i-1]==' '||Command[i-1]=='\t')&&(Command[i]=='s'||Command[i]=='S')&&(Command[i+1]=='t'||Command[i+1]=='T')&&(Command[i+2]=='e'||Command[i+2]=='E')&&(Command[i+3]=='p'||Command[i+3]=='P')&&(Command[i+4]==' '||Command[i+4]=='\t')){
|
---|
545 | pam[i2]=',';
|
---|
546 | i+=4;
|
---|
547 | continue;
|
---|
548 | }
|
---|
549 | pam[i2]=Command[i];
|
---|
550 | if(Command[i]=='\0') break;
|
---|
551 | }
|
---|
552 | }
|
---|
553 | ComNum=COM_FOR;
|
---|
554 | }
|
---|
555 | else if(lstrcmpi(com,"Next")==0){
|
---|
556 | KillSpaces(Command+i,pam);
|
---|
557 | ComNum=COM_NEXT;
|
---|
558 | }
|
---|
559 | else if(lstrcmpi(com,"Return")==0){
|
---|
560 | KillSpaces(Command+i,pam);
|
---|
561 | ComNum=COM_RETURN;
|
---|
562 | }
|
---|
563 | else if(lstrcmpi(com,"While")==0){
|
---|
564 | KillSpaces(Command+i,pam);
|
---|
565 | ComNum=COM_WHILE;
|
---|
566 | }
|
---|
567 | else if(lstrcmpi(com,"Wend")==0){
|
---|
568 | pam[0]=0;
|
---|
569 | ComNum=COM_WEND;
|
---|
570 | }
|
---|
571 |
|
---|
572 | //変数、データ操作
|
---|
573 | else if(lstrcmpi(com,"dim")==0){
|
---|
574 | KillSpaces(Command+i,pam);
|
---|
575 | ComNum=COM_DIM;
|
---|
576 | }
|
---|
577 | else if(lstrcmpi(com,"Delete")==0){
|
---|
578 | KillSpaces(Command+i,pam);
|
---|
579 | ComNum=COM_DELETE;
|
---|
580 | }
|
---|
581 | else if( lstrcmpi( com, "_System_SweepingDelete" ) == 0 ){
|
---|
582 | KillSpaces(Command+i,pam);
|
---|
583 | ComNum=COM_SWEEPINGDELETE;
|
---|
584 | }
|
---|
585 |
|
---|
586 | //その他
|
---|
587 | else if(lstrcmpi(com,"Debug")==0){
|
---|
588 | pam[0]=0;
|
---|
589 | ComNum=COM_DEBUG;
|
---|
590 | }
|
---|
591 | else if(lstrcmpi(com,"let")==0){
|
---|
592 | KillSpaces(Command+i,pam);
|
---|
593 | ComNum=COM_LET;
|
---|
594 | }
|
---|
595 | else if(lstrcmpi(com,"rem")==0){
|
---|
596 | Command[0]=0;
|
---|
597 | return;
|
---|
598 | }
|
---|
599 |
|
---|
600 | //ポインタ
|
---|
601 | else if(lstrcmpi(com,"SetDouble")==0){
|
---|
602 | KillSpaces(Command+i,pam);
|
---|
603 | ComNum=COM_SETDOUBLE;
|
---|
604 | }
|
---|
605 | else if(lstrcmpi(com,"SetSingle")==0){
|
---|
606 | KillSpaces(Command+i,pam);
|
---|
607 | ComNum=COM_SETSINGLE;
|
---|
608 | }
|
---|
609 | else if(lstrcmpi(com,"SetQWord")==0){
|
---|
610 | KillSpaces(Command+i,pam);
|
---|
611 | ComNum=COM_SETQWORD;
|
---|
612 | }
|
---|
613 | else if(lstrcmpi(com,"SetDWord")==0){
|
---|
614 | KillSpaces(Command+i,pam);
|
---|
615 | ComNum=COM_SETDWORD;
|
---|
616 | }
|
---|
617 | else if(lstrcmpi(com,"SetWord")==0){
|
---|
618 | KillSpaces(Command+i,pam);
|
---|
619 | ComNum=COM_SETWORD;
|
---|
620 | }
|
---|
621 | else if(lstrcmpi(com,"SetByte")==0){
|
---|
622 | KillSpaces(Command+i,pam);
|
---|
623 | ComNum=COM_SETBYTE;
|
---|
624 | }
|
---|
625 |
|
---|
626 | else{
|
---|
627 | //その他のコマンド(一般コード)
|
---|
628 | lstrcpy(com,Command);
|
---|
629 | KillSpaces(com,Command);
|
---|
630 | return;
|
---|
631 | }
|
---|
632 |
|
---|
633 | i=lstrlen(pam);
|
---|
634 | while(pam[i-1]==' '||pam[i-1]=='\t') i--;
|
---|
635 | pam[i]=0;
|
---|
636 | if(pam[0]) sprintf(Command,"%c%c%s",HIBYTE(ComNum),LOBYTE(ComNum),pam);
|
---|
637 | else sprintf(Command,"%c%c",HIBYTE(ComNum),LOBYTE(ComNum));
|
---|
638 |
|
---|
639 | return;
|
---|
640 | }
|
---|
641 |
|
---|
642 | void ChangeCommandToCode(char *buffer){
|
---|
643 | extern HANDLE hHeap;
|
---|
644 | int i,i2,i3,IsStr,CommandBufferSize;
|
---|
645 | char *temporary,*tempBase,temp2[VN_SIZE],*lpCommand;
|
---|
646 |
|
---|
647 | tempBase=(char *)HeapAlloc(hHeap,0,(lstrlen(buffer)+1)*2+8192);
|
---|
648 | temporary=tempBase+1;
|
---|
649 | temporary[0]=0;
|
---|
650 | i=0;
|
---|
651 | i3=0;
|
---|
652 |
|
---|
653 | CommandBufferSize=512;
|
---|
654 | lpCommand=(char *)HeapAlloc(hHeap,0,CommandBufferSize);
|
---|
655 |
|
---|
656 | while(1){
|
---|
657 | i2=0;
|
---|
658 | while(buffer[i]==' '||buffer[i]=='\t') i++;
|
---|
659 | while(buffer[i]>='0'&&buffer[i]<='9'){
|
---|
660 | temp2[i2]=buffer[i];
|
---|
661 | i++;
|
---|
662 | i2++;
|
---|
663 | }
|
---|
664 | temp2[i2]=0;
|
---|
665 | while(buffer[i]==' '||buffer[i]=='\t') i++;
|
---|
666 | for(i2=0,IsStr=0;;i++,i2++){
|
---|
667 | if(i2>=CommandBufferSize){ //バッファ領域が足りなくなった場合はバッファを増量する
|
---|
668 | CommandBufferSize+=512;
|
---|
669 | lpCommand=(char *)HeapReAlloc(hHeap,0,lpCommand,CommandBufferSize);
|
---|
670 | }
|
---|
671 | if(buffer[i]=='\"') IsStr^=1;
|
---|
672 | if(buffer[i]=='\n'||(buffer[i]==':'&&IsStr==0)||buffer[i]=='\0'){
|
---|
673 | lpCommand[i2]=0;
|
---|
674 |
|
---|
675 | if(temp2[0]){
|
---|
676 | //行番号ラベル
|
---|
677 | sprintf(temporary+i3,"%c%c%s,",1,ESC_LINENUM,temp2);
|
---|
678 | i3+=lstrlen(temporary+i3);
|
---|
679 |
|
---|
680 | temp2[0]=0;
|
---|
681 | }
|
---|
682 |
|
---|
683 | //命令コードへ変換
|
---|
684 | if(i2){
|
---|
685 | //エラー用
|
---|
686 | extern int cp;
|
---|
687 | cp=i;
|
---|
688 |
|
---|
689 | ChangeCommand(buffer,i,lpCommand);
|
---|
690 |
|
---|
691 | lstrcpy(temporary+i3,lpCommand);
|
---|
692 | i3+=lstrlen(temporary+i3);
|
---|
693 | }
|
---|
694 |
|
---|
695 | if(!(lpCommand[0]=='\0'&&buffer[i]==':')){
|
---|
696 | temporary[i3++]=buffer[i];
|
---|
697 | temporary[i3]=0;
|
---|
698 | }
|
---|
699 |
|
---|
700 | if(buffer[i]=='\n'){
|
---|
701 | i++;
|
---|
702 | break;
|
---|
703 | }
|
---|
704 | else if(buffer[i]==':'){
|
---|
705 | while(buffer[i+1]==' '||buffer[i+1]=='\t') i++;
|
---|
706 | }
|
---|
707 | if(buffer[i]=='\0') break;
|
---|
708 | i2=-1;
|
---|
709 | continue;
|
---|
710 | }
|
---|
711 | lpCommand[i2]=buffer[i];
|
---|
712 | }
|
---|
713 | if(buffer[i]=='\0') break;
|
---|
714 | }
|
---|
715 | HeapDefaultFree(lpCommand);
|
---|
716 | lstrcpy(buffer,temporary);
|
---|
717 |
|
---|
718 | HeapDefaultFree(tempBase);
|
---|
719 | }
|
---|