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