source: dev/BasicCompiler_Common/Intermediate_Step1.cpp@ 29

Last change on this file since 29 was 4, checked in by dai_9181, 18 years ago
File size: 27.4 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2
3void ChangeReturnCode(char *buffer){
4 //改行コードのCRLFをLFに変換
5 int i,i2;
6 for(i=0,i2=0;;i++,i2++){
7 if(buffer[i]=='\r'&&buffer[i+1]=='\n') i++;
8 buffer[i2]=buffer[i];
9 if(buffer[i]=='\0') break;
10 }
11}
12void DeleteComment(char *buffer){ //注釈「'」の取り除き
13 int i,i2,i3,IsStr;
14 char *temporary;
15 temporary=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(buffer)+1);
16 for(i=0,i2=0,i3=0,IsStr=0;;i++,i2++){
17 if(buffer[i]=='\"') IsStr^=1;
18 if(buffer[i]=='\n'||buffer[i]=='\0'){
19 i2--;
20 while(temporary[i2]==' '||temporary[i2]=='\t') i2--;
21 i2++;
22
23 if(i3){
24 //複数行に渡る注釈文の中に改行が存在するとき
25 memset(temporary+i2,'\n',i3);
26 i2+=i3;
27 i3=0;
28 }
29 }
30 if(buffer[i]=='\''&&IsStr==0){
31 //注釈文
32 i2--;
33 while(temporary[i2]==' '||temporary[i2]=='\t') i2--;
34 i2++;
35 while(buffer[i]!='\n'&&buffer[i]!='\0') i++;
36 }
37 if(buffer[i]=='/'&&buffer[i+1]=='*'&&IsStr==0){
38 //注釈文(複数行)
39 i+=2;
40 i3=0;
41 while(!(buffer[i]=='*'&&buffer[i+1]=='/')){
42 if(buffer[i]=='\n') i3++;
43 if(buffer[i]=='\0') break;
44 i++;
45 }
46 if(buffer[i]){
47 i+=2;
48 }
49 i--;
50 i2--;
51 continue;
52 }
53 temporary[i2]=buffer[i];
54 if(buffer[i]=='\0') break;
55 }
56 lstrcpy(buffer,temporary);
57 GlobalFree(temporary);
58}
59int KillReturnCode_InParameter(char *buffer,int *pRnum,char cBeginPare,char cEndPare){
60 int i,i2,i3,IsStr;
61
62 //カッコ'('直下の改行
63 while(buffer[0]=='\n'){
64 SlideString(buffer+1,-1);
65 (*pRnum)++;
66 }
67
68 for(i=0,IsStr=0;;i++){
69 if(IsDBCSLeadByte(buffer[i])&&buffer[i+1]){
70 i++;
71 continue;
72 }
73
74 if(buffer[i]=='\"') IsStr^=1;
75
76 if(buffer[i]=='\0') break; //エラー
77 if(buffer[i]=='\n'){
78 i2=0;
79 i3=0;
80 while(buffer[i+i2]=='\n'){
81 i2++;
82 i3++;
83 while(buffer[i+i2]==' '||buffer[i+i2]=='\t') i2++;
84 }
85 while(buffer[i+i2]==' '||buffer[i+i2]=='\t') i2++;
86
87 if(buffer[i+i2]==cEndPare){
88 SlideString(buffer+i+i2,-i2);
89 (*pRnum)+=i3;
90 break;
91 }
92
93 //エラー
94 break;
95 }
96
97 if(buffer[i]==cBeginPare&&IsStr==0){
98 i++;
99 i2=KillReturnCode_InParameter(buffer+i,pRnum,cBeginPare,cEndPare);
100 i+=i2;
101 if(buffer[i]!=cEndPare) break;
102 continue;
103 }
104 if(buffer[i]==cEndPare&&IsStr==0) break;
105
106 if(buffer[i]==','&&buffer[i+1]=='\n'&&IsStr==0){
107 i++;
108 while(buffer[i]=='\n'){
109 SlideString(buffer+i+1,-1);
110 (*pRnum)++;
111 }
112 i--;
113 }
114 }
115 return i;
116}
117void KillReturnCode(char *buffer){
118 int i,i2;
119
120 //アンダーバーによる改行
121 for(i=0;;i++){
122 i2=0;
123 while(buffer[i]=='_'&&buffer[i+1]=='\n'){
124 i2++;
125 SlideString(buffer+i+2,-2);
126 while(buffer[i]=='\n'){
127 SlideString(buffer+i+1,-1);
128 i2++;
129 }
130 for(;;i++){
131 if(buffer[i]=='_'&&buffer[i+1]=='\n') break;
132 if(buffer[i]=='\n'||buffer[i]=='\0'){
133 SlideString(buffer+i,i2);
134 memset(buffer+i,'\n',i2);
135 break;
136 }
137 }
138 }
139 if(buffer[i]=='\0') break;
140 }
141
142 //カッコ内パラメータの改行
143 int IsStr,rnum;
144 for(i=0,IsStr=0,rnum=0;;i++){
145 if(IsDBCSLeadByte(buffer[i])&&buffer[i+1]){
146 i++;
147 continue;
148 }
149 if(buffer[i]=='\0') break;
150 if(buffer[i]=='\n'){
151 if(rnum){
152 SlideString(buffer+i+1,rnum);
153 memset(buffer+i+1,'\n',rnum);
154 rnum=0;
155 }
156 }
157 if(buffer[i]=='\"') IsStr^=1;
158 if(buffer[i]=='('&&IsStr==0){
159 i++;
160 i2=KillReturnCode_InParameter(buffer+i,&rnum,'(',')');
161 i+=i2;
162 if(buffer[i]!=')') break;
163 }
164 if(buffer[i]=='['&&IsStr==0){
165 i++;
166 i2=KillReturnCode_InParameter(buffer+i,&rnum,'[',']');
167 i+=i2;
168 if(buffer[i]!=']') break;
169 }
170 }
171}
172void CheckParenthesis(char *buffer){
173 int i,IsStr,PareNum,sw;
174 _int8 bracket[1024];
175
176 for(i=0,IsStr=0,PareNum=0,sw=0;;i++){
177 if(buffer[i]=='\"'){
178 IsStr^=1;
179 continue;
180 }
181
182 else if(buffer[i]=='('&&IsStr==0){
183 bracket[PareNum]=0;
184 PareNum++;
185 }
186 else if(buffer[i]=='['&&IsStr==0){
187 bracket[PareNum]=1;
188 PareNum++;
189 }
190
191 else if(buffer[i]==')'&&IsStr==0){
192 PareNum--;
193 if(bracket[PareNum]!=0||PareNum<0){
194 //"カッコ \'( )\'"
195 SetError(4,STRING_PARENTHESIS,i);
196 return;
197 }
198 }
199 else if(buffer[i]==']'&&IsStr==0){
200 PareNum--;
201 if(bracket[PareNum]!=1||PareNum<0){
202 //"カッコ \'( )\'"
203 SetError(4,STRING_PARENTHESIS,i);
204 return;
205 }
206 }
207
208 else if(buffer[i]=='\n'||buffer[i]=='\0'){
209
210 //"カッコ \'( )\'"
211 if(PareNum!=0) SetError(4,STRING_PARENTHESIS,i);
212
213 if(IsStr!=0) SetError(5,NULL,i);
214 if(buffer[i]=='\0') break;
215 PareNum=0;
216 IsStr=0;
217
218 sw=0;
219 }
220
221 else if((IsDBCSLeadByte(buffer[i])||buffer[i]==1)&&IsStr==0){
222 //不正な文字コード
223 if(sw==0){
224 //全角スペース
225 if(buffer[i]==(char)0x81&&buffer[i+1]==(char)0x40)
226 SetError(20,NULL,i);
227
228 //その他の全角文字
229 else SetError(8,NULL,i);
230 sw=1;
231 }
232 }
233 }
234}
235BOOL CheckParenthesis2(char *buffer){
236 int i,IsStr,PareNum,sw;
237 _int8 bracket[1024];
238
239 for(i=0,IsStr=0,PareNum=0,sw=0;;i++){
240 if(buffer[i]=='\"'){
241 IsStr^=1;
242 continue;
243 }
244
245 else if(buffer[i]=='('&&IsStr==0){
246 bracket[PareNum]=0;
247 PareNum++;
248 }
249 else if(buffer[i]=='['&&IsStr==0){
250 bracket[PareNum]=1;
251 PareNum++;
252 }
253
254 else if(buffer[i]==')'&&IsStr==0){
255 PareNum--;
256 if(bracket[PareNum]!=0||PareNum<0){
257 //"カッコ \'( )\'"
258 return 0;
259 }
260 }
261 else if(buffer[i]==']'&&IsStr==0){
262 PareNum--;
263 if(bracket[PareNum]!=1||PareNum<0){
264 //"カッコ \'( )\'"
265 return 0;
266 }
267 }
268
269 else if(buffer[i]=='\n'||buffer[i]=='\0'){
270
271 //"カッコ \'( )\'"
272 if(PareNum!=0){
273 return 0;
274 }
275
276 if(IsStr!=0){
277 return 0;
278 }
279 if(buffer[i]=='\0') break;
280 PareNum=0;
281 IsStr=0;
282
283 sw=0;
284 }
285
286 else if((IsDBCSLeadByte(buffer[i])||buffer[i]==1)&&IsStr==0){
287 //不正な文字コード
288 if(sw==0){
289 //全角スペース
290 if(buffer[i]==(char)0x81&&buffer[i+1]==(char)0x40){
291 return 0;
292 }
293
294 //その他の全角文字
295 else return 0;
296 sw=1;
297 }
298 }
299 }
300 return 1;
301}
302void DirectiveCheck(void){
303 extern char *basbuf;
304 extern char BasicCurDir[MAX_PATH];
305 int i,i2,i3;
306 char temporary[VN_SIZE];
307
308 extern BOOL bStrict;
309 bStrict=0;
310
311 for(i=0;;i++){
312 if(basbuf[i]=='\0') break;
313 if(((basbuf[i-2]==0&&basbuf[i-1]==-1)||basbuf[i-1]=='\n')&&
314 basbuf[i]=='#'){
315 for(i2=i+1,i3=0;;i2++,i3++){
316 if(!IsVariableChar(basbuf[i2])){
317 temporary[i3]=0;
318 break;
319 }
320 temporary[i3]=basbuf[i2];
321 }
322 if(lstrcmpi(temporary,"noprompt")==0){
323 //#noprompt
324 //旧機能なので、無視
325 for(;;i2++){
326 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
327 }
328 SlideString(basbuf+i2,i-i2);
329 }
330 else if(lstrcmpi(temporary,"strict")==0){
331 //#strict
332 for(;;i2++){
333 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
334 }
335 SlideString(basbuf+i2,i-i2);
336
337 //型チェックを厳密に行う
338 bStrict=1;
339 }
340 else if(lstrcmpi(temporary,"struct")==0){
341 //#struct code
342 //旧機能なので、無視
343 for(;;i2++){
344 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
345 }
346 SlideString(basbuf+i2,i-i2);
347 }
348 else if(lstrcmpi(temporary,"resource")==0){
349 //#resource
350 while(basbuf[i2]==' '||basbuf[i2]=='\t') i2++;
351 if(basbuf[i2]!='\"'){
352 SetError(1,NULL,i2);
353 return;
354 }
355 for(i3=0,i2++;;i2++,i3++){
356 if(basbuf[i2]=='\"'){
357 temporary[i3]=0;
358 break;
359 }
360 temporary[i3]=basbuf[i2];
361 }
362 GetFullPath(temporary,BasicCurDir);
363
364 extern char ResourceFileName[MAX_PATH];
365 lstrcpy(ResourceFileName,temporary);
366
367 for(;;i2++){
368 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
369 }
370 SlideString(basbuf+i2,i-i2);
371 }
372 }
373 }
374}
375void NextCommandFormat(char *buffer){
376 int i,i2,i3;
377 char temporary[255];
378
379 //Next命令語のフォーマット
380 for(i=0;;i++){
381 if(buffer[i]=='\n'||buffer[i]==':'||i==0){
382 if(buffer[i]=='\n'||buffer[i]==':') i++;
383 while(buffer[i]==' '||buffer[i]=='\t') i++;
384 while(buffer[i]>='0'&&buffer[i]<='9') i++;
385 while(buffer[i]==' '||buffer[i]=='\t') i++;
386 if((buffer[i]=='n'||buffer[i]=='N')&&(buffer[i+1]=='e'||buffer[i+1]=='E')&&(buffer[i+2]=='x'||buffer[i+2]=='X')&&(buffer[i+3]=='t'||buffer[i+3]=='T')&&
387 (buffer[i+4]==' '||buffer[i+4]=='\t')){
388 i2=i+5;
389 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
390 if(buffer[i2]!='\n'){
391 lstrcpy(temporary,"NEXT");
392 for(i3=0;;i2++){
393 if(buffer[i2]=='\n'||buffer[i2]==':'||buffer[i2]=='\0') break;
394 if(buffer[i2]==','){
395 lstrcat(temporary,":NEXT");
396 i3=1;
397 }
398 }
399 if(i3){
400 i3=lstrlen(temporary);
401 SlideString(buffer+i2,i-i2+i3);
402 memcpy(buffer+i,temporary,i3);
403 }
404 }
405 }
406 }
407 if(buffer[i]=='\0') break;
408 }
409}
410void SetEscapeSequenceFormat(char *buffer){
411 /*「MOD」「AND」「OR」
412 その他制御文字をエスケープシーケンスを使用した記号へ変換 */
413 int i,i2,i3,i4,i5,i6,sw1,IsStr;
414 char *temporary,temp2[VN_SIZE];
415
416 temporary=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(buffer)*2);
417 for(i=0,i2=0,IsStr=0;;i++,i2++){
418 if(buffer[i]=='\"') IsStr^=1;
419 if(buffer[i]=='-'&&buffer[i+1]=='>'&&IsStr==0){
420 buffer[i]=1;
421 buffer[i+1]=ESC_PSMEM;
422 }
423 if(IsVariableChar(buffer[i])&&IsStr==0){
424 i3=i2;
425 for(;;i++,i2++){
426 if(!IsVariableChar(buffer[i])){
427 temporary[i2]=0;
428 break;
429 }
430 temporary[i2]=buffer[i];
431 }
432 if(lstrcmpi(temporary+i3,"End")==0) i6=1;
433 else if(lstrcmpi(temporary+i3,"Exit")==0) i6=2;
434 else if(lstrcmpi(temporary+i3,"Select")==0) i6=3;
435 else if(lstrcmpi(temporary+i3,"Case")==0) i6=4;
436 else if(lstrcmpi(temporary+i3,"Else")==0) i6=5;
437 else i6=0;
438 if(i6){
439 i4=i;
440 while(buffer[i4]==' '||buffer[i4]=='\t') i4++;
441 for(i5=0;;i4++,i5++){
442 if(!IsVariableChar(buffer[i4])){
443 temp2[i5]=0;
444 break;
445 }
446 temp2[i5]=buffer[i4];
447 }
448 sw1=0;
449 if(i6==3){
450 //Select~
451 if(lstrcmpi(temp2,"Case")==0) sw1=1;
452 }
453 else if(i6==4){
454 //Case~
455 if(lstrcmpi(temp2,"Else")==0) sw1=1;
456 }
457 else if(i6==5){
458 //Else If
459 if(lstrcmpi(temp2,"If")==0) sw1=1;
460 }
461 else if(i6==1){
462 //End~
463 switch(temp2[0]){
464 case 'c':
465 case 'C':
466 if(lstrcmpi(temp2,"Class")==0) sw1=1;
467 break;
468 case 'e':
469 case 'E':
470 if(lstrcmpi(temp2,"Enum")==0) sw1=1;
471 break;
472 case 'i':
473 case 'I':
474 if(lstrcmpi(temp2,"If")==0) sw1=1;
475 else if(lstrcmpi(temp2,"Interface")==0) sw1=1;
476 break;
477 case 'f':
478 case 'F':
479 if(lstrcmpi(temp2,"Function")==0) sw1=1;
480 break;
481 case 'm':
482 case 'M':
483 if(lstrcmpi(temp2,"Macro")==0) sw1=1;
484 break;
485 case 's':
486 case 'S':
487 if(lstrcmpi(temp2,"Sub")==0) sw1=1;
488 else if(lstrcmpi(temp2,"Select")==0) sw1=1;
489 break;
490 case 't':
491 case 'T':
492 if(lstrcmpi(temp2,"Type")==0) sw1=1;
493 break;
494 case 'w':
495 case 'W':
496 if(lstrcmpi(temp2,"With")==0) sw1=1;
497 break;
498 }
499 }
500 else if(i6==2){
501 //Exit~
502 if(
503 lstrcmpi(temp2,"For")==0||
504 lstrcmpi(temp2,"While")==0||
505 lstrcmpi(temp2,"Do")==0||
506 lstrcmpi(temp2,"Function")==0||
507 lstrcmpi(temp2,"Sub")==0||
508 lstrcmpi(temp2,"Macro")==0
509 ) sw1=1;
510 }
511
512 if(sw1){
513 i=i4;
514 memcpy(temporary+i2,temp2,i5);
515 i2+=i5;
516 temporary[i2]=0;
517 }
518 }
519 i--;
520 i2--;
521
522 switch(temporary[i3]){
523 case 'a':
524 case 'A':
525 if(lstrcmpi(temporary+i3,"And")==0){
526 i2=i3;
527 temporary[i2++]=1;
528 temporary[i2]=ESC_AND;
529 }
530 else if(lstrcmpi(temporary+i3,"Abstract")==0){
531 i2=i3;
532 temporary[i2++]=1;
533 temporary[i2]=ESC_ABSTRACT;
534 }
535 else if(lstrcmpi(temporary+i3,"As")==0){
536 i2=i3;
537 temporary[i2++]=1;
538 temporary[i2]=ESC_AS;
539 }
540 break;
541 case 'b':
542 case 'B':
543 if(lstrcmpi(temporary+i3,"ByVal")==0){
544 i2=i3;
545 temporary[i2++]=1;
546 temporary[i2]=ESC_BYVAL;
547 }
548 else if(lstrcmpi(temporary+i3,"ByRef")==0){
549 i2=i3;
550 temporary[i2++]=1;
551 temporary[i2]=ESC_BYREF;
552 }
553 break;
554 case 'c':
555 case 'C':
556 if(lstrcmpi(temporary+i3,"Catch")==0){
557 i2=i3;
558 temporary[i2++]=1;
559 temporary[i2]=ESC_CATCH;
560 }
561 else if(lstrcmpi(temporary+i3,"Continue")==0){
562 i2=i3;
563 temporary[i2++]=1;
564 temporary[i2]=ESC_CONTINUE;
565 }
566 else if(lstrcmpi(temporary+i3,"cdecl")==0){
567 i2=i3;
568 temporary[i2++]=1;
569 temporary[i2]=ESC_CDECL;
570 }
571 else if(lstrcmpi(temporary+i3,"Case")==0){
572 i2=i3;
573 temporary[i2++]=1;
574 temporary[i2]=ESC_CASE;
575 }
576 else if(lstrcmpi(temporary+i3,"CaseElse")==0){
577 i2=i3;
578 temporary[i2++]=1;
579 temporary[i2]=ESC_CASEELSE;
580 }
581 else if(lstrcmpi(temporary+i3,"Const")==0){
582 i2=i3;
583 temporary[i2++]=1;
584 temporary[i2]=ESC_CONST;
585 }
586 else if(lstrcmpi(temporary+i3,"Class")==0){
587 i2=i3;
588 temporary[i2++]=1;
589 temporary[i2]=ESC_CLASS;
590 }
591 break;
592 case 'd':
593 case 'D':
594 if(lstrcmpi(temporary+i3,"Declare")==0){
595 i2=i3;
596 temporary[i2]=1;
597 temporary[++i2]=ESC_DECLARE;
598 i++;
599 while(buffer[i]==' '||buffer[i]=='\t') i++;
600 for(i4=0;;i++,i4++){
601 if(!IsVariableChar(buffer[i])){
602 temp2[i4]=0;
603 break;
604 }
605 temp2[i4]=buffer[i];
606 }
607 if(lstrcmpi(temp2,"Sub")==0) temporary[++i2]=ESC_SUB;
608 else if(lstrcmpi(temp2,"Function")==0) temporary[++i2]=ESC_FUNCTION;
609 while(buffer[i]==' '||buffer[i]=='\t') i++;
610 for(i2++;;i++,i2++){
611 if(!IsVariableChar(buffer[i])){
612 i2--;
613 break;
614 }
615 temporary[i2]=buffer[i];
616 }
617 while(buffer[i]==' '||buffer[i]=='\t') i++;
618 for(i4=0;;i++,i4++){
619 if(!IsVariableChar(buffer[i])){
620 temp2[i4]=0;
621 break;
622 }
623 temp2[i4]=buffer[i];
624 }
625 if(lstrcmpi(temp2,"cdecl")==0){
626 temporary[++i2]=1;
627 temporary[++i2]=ESC_CDECL;
628
629 while(buffer[i]==' '||buffer[i]=='\t') i++;
630 for(i4=0;;i++,i4++){
631 if(!IsVariableChar(buffer[i])){
632 temp2[i4]=0;
633 break;
634 }
635 temp2[i4]=buffer[i];
636 }
637 }
638 if(lstrcmpi(temp2,"Lib")==0) temporary[++i2]=',';
639 while(buffer[i]==' '||buffer[i]=='\t') i++;
640 if(buffer[i]=='\"'){
641 temporary[++i2]=buffer[i];
642 for(i++,i2++;;i++,i2++){
643 temporary[i2]=buffer[i];
644 if(buffer[i]=='\"'){
645 i++;
646 break;
647 }
648 if(buffer[i]=='\0') break;
649 }
650 }
651 while(buffer[i]==' '||buffer[i]=='\t') i++;
652 for(i4=0;;i++,i4++){
653 if(!IsVariableChar(buffer[i])){
654 temp2[i4]=0;
655 break;
656 }
657 temp2[i4]=buffer[i];
658 }
659 if(lstrcmpi(temp2,"Alias")==0)
660 temporary[++i2]=',';
661 i--;
662 }
663 else if(lstrcmpi(temporary+i3,"Def")==0){
664 i2=i3;
665 temporary[i2++]=1;
666 temporary[i2]=ESC_DEF;
667 }
668 break;
669 case 'e':
670 case 'E':
671 if(lstrcmpi(temporary+i3,"ElseIf")==0){
672 i2=i3;
673 temporary[i2++]=1;
674 temporary[i2]=ESC_ELSEIF;
675 }
676 else if(lstrcmpi(temporary+i3,"Else")==0){
677 i2=i3;
678 temporary[i2++]=1;
679 temporary[i2]=ESC_ELSE;
680 }
681 else if(lstrcmpi(temporary+i3,"Export")==0){
682 i2=i3;
683 temporary[i2++]=1;
684 temporary[i2]=ESC_EXPORT;
685 }
686 else if(lstrcmpi(temporary+i3,"Enum")==0){
687 i2=i3;
688 temporary[i2++]=1;
689 temporary[i2]=ESC_ENUM;
690 }
691
692 else if(temporary[i3+1]=='n'||temporary[i3+1]=='N'){
693 //終了記述
694 if(lstrcmpi(temporary+i3,"EndIf")==0){
695 i2=i3;
696 temporary[i2++]=1;
697 temporary[i2]=ESC_ENDIF;
698 }
699 else if(lstrcmpi(temporary+i3,"EndFunction")==0){
700 i2=i3;
701 temporary[i2++]=1;
702 temporary[i2]=ESC_ENDFUNCTION;
703 }
704 else if(lstrcmpi(temporary+i3,"EndSub")==0){
705 i2=i3;
706 temporary[i2++]=1;
707 temporary[i2]=ESC_ENDSUB;
708 }
709 else if(lstrcmpi(temporary+i3,"EndMacro")==0){
710 i2=i3;
711 temporary[i2++]=1;
712 temporary[i2]=ESC_ENDMACRO;
713 }
714 else if(lstrcmpi(temporary+i3,"EndClass")==0){
715 i2=i3;
716 temporary[i2++]=1;
717 temporary[i2]=ESC_ENDCLASS;
718 }
719 else if(lstrcmpi(temporary+i3,"EndInterface")==0){
720 i2=i3;
721 temporary[i2++]=1;
722 temporary[i2]=ESC_ENDINTERFACE;
723 }
724 else if(lstrcmpi(temporary+i3,"EndTry")==0){
725 i2=i3;
726 temporary[i2++]=1;
727 temporary[i2]=ESC_ENDTRY;
728 }
729 else if(lstrcmpi(temporary+i3,"EndType")==0){
730 i2=i3;
731 temporary[i2++]=1;
732 temporary[i2]=ESC_ENDTYPE;
733 }
734 else if(lstrcmpi(temporary+i3,"EndEnum")==0){
735 i2=i3;
736 temporary[i2++]=1;
737 temporary[i2]=ESC_ENDENUM;
738 }
739 else if(lstrcmpi(temporary+i3,"EndSelect")==0){
740 i2=i3;
741 temporary[i2++]=1;
742 temporary[i2]=ESC_ENDSELECT;
743 }
744 else if(lstrcmpi(temporary+i3,"EndWith")==0){
745 i2=i3;
746 temporary[i2++]=1;
747 temporary[i2]=ESC_ENDWITH;
748 }
749 }
750 else if(temporary[i3+1]=='x'||temporary[i3+1]=='X'){
751 if(lstrcmpi(temporary+i3,"ExitFor")==0){
752 i2=i3;
753 temporary[i2++]=1;
754 temporary[i2]=ESC_EXITFOR;
755 }
756 else if(lstrcmpi(temporary+i3,"ExitWhile")==0){
757 i2=i3;
758 temporary[i2++]=1;
759 temporary[i2]=ESC_EXITWHILE;
760 }
761 else if(lstrcmpi(temporary+i3,"ExitDo")==0){
762 i2=i3;
763 temporary[i2++]=1;
764 temporary[i2]=ESC_EXITDO;
765 }
766 else if(lstrcmpi(temporary+i3,"ExitFunction")==0){
767 i2=i3;
768 temporary[i2++]=1;
769 temporary[i2]=ESC_EXITFUNCTION;
770 }
771 else if(lstrcmpi(temporary+i3,"ExitSub")==0){
772 i2=i3;
773 temporary[i2++]=1;
774 temporary[i2]=ESC_EXITSUB;
775 }
776 else if(lstrcmpi(temporary+i3,"ExitMacro")==0){
777 i2=i3;
778 temporary[i2++]=1;
779 temporary[i2]=ESC_EXITMACRO;
780 }
781 }
782 break;
783 case 'f':
784 case 'F':
785 if(lstrcmpi(temporary+i3,"Finally")==0){
786 i2=i3;
787 temporary[i2++]=1;
788 temporary[i2]=ESC_FINALLY;
789 }
790 else if(lstrcmpi(temporary+i3,"Function")==0){
791 i2=i3;
792 temporary[i2++]=1;
793 temporary[i2]=ESC_FUNCTION;
794 }
795 break;
796 case 'i':
797 case 'I':
798 if(lstrcmpi(temporary+i3,"If")==0){
799 i2=i3;
800 temporary[i2++]=1;
801 temporary[i2]=ESC_IF;
802 }
803 else if(lstrcmpi(temporary+i3,"Inherits")==0){
804 i2=i3;
805 temporary[i2++]=1;
806 temporary[i2]=ESC_INHERITS;
807 }
808 else if(lstrcmpi(temporary+i3,"Interface")==0){
809 i2=i3;
810 temporary[i2++]=1;
811 temporary[i2]=ESC_INTERFACE;
812 }
813 break;
814 case 'm':
815 case 'M':
816 if(lstrcmpi(temporary+i3,"Mod")==0){
817 i2=i3;
818 temporary[i2++]=1;
819 temporary[i2]=ESC_MOD;
820 }
821 else if(lstrcmpi(temporary+i3,"Macro")==0){
822 i2=i3;
823 temporary[i2++]=1;
824 temporary[i2]=ESC_MACRO;
825 }
826 break;
827 case 'n':
828 case 'N':
829 if(lstrcmpi(temporary+i3,"Not")==0){
830 i2=i3;
831 temporary[i2++]=1;
832 temporary[i2]=ESC_NOT;
833 }
834 else if(lstrcmpi(temporary+i3,"New")==0){
835 i2=i3;
836 temporary[i2++]=1;
837 temporary[i2]=ESC_NEW;
838 }
839 break;
840 case 'o':
841 case 'O':
842 if(lstrcmpi(temporary+i3,"Or")==0){
843 i2=i3;
844 temporary[i2++]=1;
845 temporary[i2]=ESC_OR;
846 }
847 else if(lstrcmpi(temporary+i3,"Override")==0){
848 i2=i3;
849 temporary[i2++]=1;
850 temporary[i2]=ESC_OVERRIDE;
851 }
852 else if(lstrcmpi(temporary+i3,"Operator")==0){
853 i2=i3;
854 temporary[i2++]=1;
855 temporary[i2]=ESC_OPERATOR;
856 }
857 break;
858 case 's':
859 case 'S':
860 if(lstrcmpi(temporary+i3,"Sub")==0){
861 i2=i3;
862 temporary[i2++]=1;
863 temporary[i2]=ESC_SUB;
864 }
865 else if(lstrcmpi(temporary+i3,"SelectCase")==0){
866 i2=i3;
867 temporary[i2++]=1;
868 temporary[i2]=ESC_SELECTCASE;
869 }
870 else if(lstrcmpi(temporary+i3,"Static")==0){
871 i2=i3;
872 temporary[i2++]=1;
873 temporary[i2]=ESC_STATIC;
874 }
875 break;
876 case 't':
877 case 'T':
878 if(lstrcmpi(temporary+i3,"Then")==0){
879 i2=i3;
880 temporary[i2++]=1;
881 temporary[i2]=ESC_THEN;
882 }
883 else if(lstrcmpi(temporary+i3,"Throw")==0){
884 i2=i3;
885 temporary[i2++]=1;
886 temporary[i2]=ESC_THROW;
887 }
888 else if(lstrcmpi(temporary+i3,"Try")==0){
889 i2=i3;
890 temporary[i2++]=1;
891 temporary[i2]=ESC_TRY;
892 }
893 else if(lstrcmpi(temporary+i3,"Type")==0){
894 i2=i3;
895 temporary[i2++]=1;
896 temporary[i2]=ESC_TYPE;
897 }
898 else if(lstrcmpi(temporary+i3,"TypeDef")==0){
899 i2=i3;
900 temporary[i2++]=1;
901 temporary[i2]=ESC_TYPEDEF;
902 }
903 break;
904 case 'u':
905 case 'U':
906 if(lstrcmpi(temporary+i3,"Using")==0){
907 i2=i3;
908 temporary[i2++]=1;
909 temporary[i2]=ESC_USING;
910 }
911 break;
912 case 'v':
913 case 'V':
914 if(lstrcmpi(temporary+i3,"Virtual")==0){
915 i2=i3;
916 temporary[i2++]=1;
917 temporary[i2]=ESC_VIRTUAL;
918 }
919 break;
920 case 'w':
921 case 'W':
922 if(lstrcmpi(temporary+i3,"With")==0){
923 i2=i3;
924 temporary[i2++]=1;
925 temporary[i2]=ESC_WITH;
926 }
927 break;
928 case 'x':
929 case 'X':
930 if(lstrcmpi(temporary+i3,"Xor")==0){
931 i2=i3;
932 temporary[i2++]=1;
933 temporary[i2]=ESC_XOR;
934 }
935 break;
936 }
937
938 continue;
939 }
940 temporary[i2]=buffer[i];
941 if(buffer[i]=='\0') break;
942 }
943 lstrcpy(buffer,temporary);
944 GlobalFree(temporary);
945}
946void DefCommandFormat(char *buffer){
947 int i,i2,PareNum;
948 char temporary[255];
949
950 //Def命令語からFunction命令語へ
951 for(i=0;;i++){
952 if(buffer[i]==1&&buffer[i+1]==ESC_DEF){
953 buffer[i+1]=ESC_FUNCTION;
954 i+=2;
955 while(buffer[i]==' '||buffer[i]=='\t') i++;
956 for(i2=0;;i++,i2++){
957 if(!IsVariableChar(buffer[i])){
958 temporary[i2]=0;
959 break;
960 }
961 temporary[i2]=buffer[i];
962 }
963 while(buffer[i]==' '||buffer[i]=='\t') i++;
964 if(buffer[i]!='('){
965 SetError(1,NULL,i);
966 return;
967 }
968 i++;
969 while(1){
970 while(buffer[i]==' '||buffer[i]=='\t') i++;
971 if(buffer[i]==')') break;
972 SlideString(buffer+i,2);
973 buffer[i]=1;
974 buffer[i+1]=ESC_BYVAL;
975 i+=2;
976 PareNum=0;
977 for(;;i++){
978 if(buffer[i]=='(') PareNum++;
979 if(buffer[i]==')'){
980 PareNum--;
981 if(PareNum<0) break;
982 }
983 if(buffer[i]==','&&PareNum==0) break;
984 }
985 if(buffer[i]==')') break;
986 i++;
987 }
988 i++;
989 while(buffer[i]==' '||buffer[i]=='\t') i++;
990 if(buffer[i]!='='){
991 SetError(1,NULL,i);
992 break;
993 }
994 i2=lstrlen(temporary);
995 SlideString(buffer+i,i2+1);
996 buffer[i]=':';
997 i++;
998 memcpy(buffer+i,temporary,i2);
999 i+=i2;
1000 while(!IsCommandDelimitation(buffer[i])) i++;
1001 SlideString(buffer+i,3);
1002 buffer[i]=':';
1003 buffer[i+1]=1;
1004 buffer[i+2]=ESC_ENDFUNCTION;
1005 }
1006 if(buffer[i]=='\0') break;
1007 }
1008}
1009
1010void ChangeOneIf(char *write,int &wp,char *read,int &rp){
1011 int IsStr,sw;
1012
1013 //ブロック形式でないときはThenの後に区切り文字を入れる
1014 for(IsStr=0,sw=0;;wp++,rp++){
1015 if(read[rp]=='\"') IsStr^=1;
1016
1017 write[wp]=read[rp];
1018
1019 if(IsCommandDelimitation(read[rp])&&IsStr==0) return;
1020 if(read[rp]==1&&read[rp+1]==ESC_THEN&&
1021 (read[rp+2]==' '||read[rp+2]=='\t')){
1022 write[wp+1]=read[rp+1];
1023 write[wp+2]=':';
1024 rp+=3;
1025 wp+=3;
1026 while(read[rp]==' '||read[rp]=='\t') rp++;
1027 if((read[rp]>='0'&&read[rp]<='9')||read[rp]=='*'){
1028 memcpy(write+wp,"Goto ",5);
1029 wp+=5;
1030 }
1031 break;
1032 }
1033 }
1034
1035 //Elseの後に区切り文字を入れる
1036 for(IsStr=0;;wp++,rp++){
1037 if(read[rp]=='\"') IsStr^=1;
1038
1039 write[wp]=read[rp];
1040
1041 if(read[rp]=='\n'||read[rp]=='\0') break;
1042 if(read[rp]==1&&read[rp+1]==ESC_IF){
1043 write[wp+1]=read[rp+1];
1044 wp+=2;
1045 rp+=2;
1046 ChangeOneIf(write,wp,read,rp);
1047 wp--;
1048 rp--;
1049 continue;
1050 }
1051 if(read[rp]==1&&read[rp+1]==ESC_ELSE){
1052 write[wp++]=':';
1053
1054 write[wp]=read[rp];
1055 write[wp+1]=read[rp+1];
1056 wp+=2;
1057 rp+=2;
1058
1059 write[wp++]=':';
1060
1061 while(read[rp]==' '||read[rp]=='\t') rp++;
1062 if((read[rp]>='0'&&read[rp]<='9')||read[rp]=='*'){
1063 memcpy(write+wp,"Goto ",5);
1064 wp+=5;
1065 }
1066 break;
1067 }
1068 }
1069
1070 //"End If" を付加
1071 for(;;rp++,wp++){
1072 if(read[rp]=='\n'||read[rp]=='\0') break;
1073
1074 if(read[rp]==1&&read[rp+1]==ESC_IF){
1075 write[wp+1]=read[rp+1];
1076 wp+=2;
1077 rp+=2;
1078 ChangeOneIf(write,wp,read,rp);
1079 wp--;
1080 rp--;
1081 continue;
1082 }
1083 if(read[rp]==1&&read[rp+1]==ESC_ELSE) break;
1084
1085 write[wp]=read[rp];
1086 }
1087 write[wp]=':';
1088 write[wp+1]=1;
1089 write[wp+2]=ESC_ENDIF;
1090 wp+=3;
1091}
1092void OutsideIfFormat(char *write,int &wp,char *read,int &rp){
1093 int ElseCount=1;
1094
1095 for(;;rp++,wp++){
1096 if(read[rp]==1){
1097 if(read[rp+1]==ESC_IF){
1098 write[wp++]=read[rp++];
1099 write[wp++]=read[rp++];
1100 OutsideIfFormat(write,wp,read,rp);
1101 wp--,rp--;
1102 continue;
1103 }
1104 if(read[rp+1]==ESC_ENDIF){
1105 for(;ElseCount>0;wp+=3,ElseCount--){
1106 write[wp]=1;
1107 write[wp+1]=ESC_ENDIF;
1108 write[wp+2]=':';
1109 }
1110 rp+=2;
1111 break;
1112 }
1113 if(read[rp+1]==ESC_ELSEIF){
1114 write[wp]=1;
1115 write[wp+1]=ESC_ELSE;
1116 write[wp+2]=':';
1117
1118 write[wp+3]=1;
1119 write[wp+4]=ESC_IF;
1120
1121 wp+=4;
1122 rp++;
1123
1124 ElseCount++;
1125 continue;
1126 }
1127 }
1128
1129 write[wp]=read[rp];
1130 if(read[rp]=='\0') break;
1131 }
1132}
1133void IfCommandFormat(char *buffer){
1134 int i,i2;
1135
1136 char *temporary;
1137 temporary=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)*2+1024);
1138
1139 //1行Ifをブロック形式にする
1140 for(i=0,i2=0;;i++,i2++){
1141 if(buffer[i]==1&&buffer[i+1]==ESC_IF){
1142 temporary[i2++]=buffer[i++];
1143 temporary[i2++]=buffer[i++];
1144 ChangeOneIf(temporary,i2,buffer,i);
1145 i2--,i--;
1146 continue;
1147 }
1148
1149 temporary[i2]=buffer[i];
1150 if(buffer[i]=='\0') break;
1151 }
1152
1153 //ElseIfを入れ子構造に変更する
1154 for(i=0,i2=0;;i++,i2++){
1155 if(temporary[i]==1&&temporary[i+1]==ESC_IF){
1156 buffer[i2++]=temporary[i++];
1157 buffer[i2++]=temporary[i++];
1158 OutsideIfFormat(buffer,i2,temporary,i);
1159 i2--,i--;
1160 continue;
1161 }
1162
1163 buffer[i2]=temporary[i];
1164 if(temporary[i]=='\0') break;
1165 }
1166
1167 HeapDefaultFree(temporary);
1168}
1169void CheckPareCommand(void){
1170 extern char *basbuf;
1171 int i2,i3;
1172
1173 int FuncNum=0;
1174 int FuncType=0;
1175 int FuncPtr=-1;
1176 for(i2=0;;i2++){
1177 if(basbuf[i2]=='\0') break;
1178 if(IsCommandDelimitation(basbuf[i2])){
1179 if(basbuf[i2+1]==1){
1180 i2++;
1181 switch(basbuf[i2+1]){
1182 case ESC_FUNCTION:
1183 case ESC_SUB:
1184 case ESC_MACRO:
1185 if(FuncNum!=0){
1186 if(FuncType==ESC_FUNCTION)
1187 SetError(54,"End Function",FuncPtr);
1188 else if(FuncType==ESC_SUB)
1189 SetError(54,"End Sub",FuncPtr);
1190 else if(FuncType==ESC_MACRO)
1191 SetError(54,"End Macro",FuncPtr);
1192 return;
1193 }
1194 FuncType=basbuf[i2+1];
1195 FuncNum++;
1196 FuncPtr=i2;
1197 break;
1198 case ESC_ENDFUNCTION:
1199 case ESC_ENDSUB:
1200 case ESC_ENDMACRO:
1201 if(basbuf[i2+1]==ESC_ENDFUNCTION) i3=ESC_FUNCTION;
1202 else if(basbuf[i2+1]==ESC_ENDSUB) i3=ESC_SUB;
1203 else if(basbuf[i2+1]==ESC_ENDMACRO) i3=ESC_MACRO;
1204
1205 FuncNum--;
1206
1207 if(FuncNum!=0||i3!=FuncType){
1208 if(basbuf[i2+1]==ESC_ENDFUNCTION)
1209 SetError(12,"End Function",i2);
1210 else if(basbuf[i2+1]==ESC_ENDSUB)
1211 SetError(12,"End Sub",i2);
1212 else if(basbuf[i2+1]==ESC_ENDMACRO)
1213 SetError(12,"End Macro",i2);
1214 return;
1215 }
1216 break;
1217 }
1218 }
1219
1220
1221 }
1222 }
1223}
Note: See TracBrowser for help on using the repository browser.