Develop and Download Open Source Software

Browse Subversion Repository

Contents of /control.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Mon Nov 7 12:03:00 2011 UTC (12 years, 4 months ago) by shiraishikazuo
File MIME type: text/x-pascal
File size: 45702 byte(s)


1 unit control;
2 {$IFDEF FPC}
3 {$MODE DELPHI}{$H+}
4 {$ENDIF}
5
6 (***************************************)
7 (* Copyright (C) 2006, SHIRAISHI Kazuo *)
8 (***************************************)
9
10
11 {********}
12 interface
13 {********}
14 uses Classes,
15 variabl,base2,struct,express;
16
17 type
18 TForStructure=class(TStatement)
19 controlVar:TSubstance;//TVariable;
20 own1,own2 :TSubstance;//TVariable;
21 Block :TStatement;
22 initial :TPrincipal;
23 limit :TPrincipal;
24 increment :TPrincipal;
25 variable :AnsiString;
26 constructor create(prev,eld:TStatement);
27 procedure CollectLabelInfo(t:TLabelNumberTable);override;
28 //function SetBreakPoint(i:integer; b:boolean):boolean;override;
29 destructor destroy;override;
30 //procedure exec;override;
31 //procedure execloop;
32 function BlockCode(PreLabel,AfterLabel:TStringList; HaveEXLINE:boolean):AnsiString; override;
33 private
34 HaveExitFor:boolean;
35 HaveExitForInWhen:boolean;
36 end;
37
38 TDoStructure=class(TStatement)
39 cond1 : TLogical;
40 until1: boolean;
41 Block : TStatement;
42 constructor create(prev,eld:TStatement);
43 procedure CollectLabelInfo(t:TLabelNumberTable);override;
44 //function SetBreakPoint(i:integer; b:boolean):boolean;override;
45 destructor destroy;override;
46 //procedure exec;override;
47 function BlockCode(PreLabel,AfterLabel:TStringList; HaveEXLINE:boolean):AnsiString; override;
48 private
49 HaveExitDo:boolean;
50 HaveExitDoInWhen:boolean;
51 end;
52
53 type
54 TCustomIfStatement=class(TSTatement)
55 condition :TLogical;
56 thenBlock :TStatement;
57 ElseBlock :TStatement;
58 constructor create(prev,eld:TStatement; cond1:TLogical);
59 destructor destroy;override;
60 //procedure exec;override;
61 function BlockCode(PreLabel,AfterLabel:TStringList; HaveEXLINE:boolean):AnsiString; override;
62 end;
63
64
65 TIfStructure=class(TCustomIfStatement)
66 InitialLine:TStatement;
67 constructor create(prev,eld:TStatement; cond1:TLogical; ini:TStatement);
68 //procedure exec;override;
69 procedure CollectLabelInfo(t:TLabelNumberTable);override;
70 //function SetBreakPoint(i:integer; b:boolean):boolean;override;
71 end;
72
73 TIfStatement=class(TCustomIfSTatement)
74 constructor create(prev,eld:TStatement; cond1:TLogical);
75 //procedure exec;override;
76 end;
77
78 TSelect=class(TStatement)
79 exp:TPrincipal;
80 own:TSubstance;
81 caseblock:TStatement;
82 OwnToFree:boolean;
83 constructor create(prev,eld:TStatement);
84 procedure CollectLabelInfo(t:TLabelNumberTable);override;
85 //function SetBreakPoint(i:integer; b:boolean):boolean;override;
86 destructor destroy;override;
87 //procedure exec;override;
88 function BlockCode(Prelabel,Afterlabel:TStringList; HaveEXLINE:boolean):Ansistring;override;
89 end;
90
91
92 function GOTOst(prev,eld:TStatement):TStatement;
93 function EXITst(prev,eld:TStatement):TStatement;
94 function STOPst(prev,eld:TStatement):TStatement;
95
96 {************}
97 implementation
98 {************}
99 uses SysUtils, Forms, Dialogs, Controls,
100 base0,helpctex,base,texthand,optina,math2sub,sconsts,io;
101
102 {*****************}
103 {control Structure}
104 {*****************}
105
106 function GOTOst(prev,eld:TStatement):TStatement;
107 begin
108 GOTOst:=TGOTO.create(prev,eld)
109 end;
110
111 {********}
112 {GOSUB st}
113 {********}
114
115 type
116 TGOSUB=class(TGOTO)
117 procedure FillInfo(LabelNumbertable:TLabelNumberTable);override;
118 //procedure exec;override;
119 function Code:ansistring;override;
120 end;
121
122 procedure TGosub.FillInfo(LabelNumbertable:TLabelNumberTable);
123 begin
124 inherited FillInfo(LabelNumbertable);
125
126 next.haveBranchLabel:=true;
127 if WhenBlock=nil then
128 begin
129 proc.ReturnLables.add(inttostr(Next.LabelNumb));
130 proc.LabelsList.add(InttoStr(Next.LabelNumb));
131 end
132 else
133 begin
134 WhenBlock.ReturnLables.add(inttostr(Next.LabelNumb));
135 proc.LabelsList.add(InttoStr(Next.LabelNumb));
136 end;
137 end;
138
139 function GOSUBst(prev,eld:TStatement):TStatement;far;
140 begin
141 GOSUBst:=TGOSUB.create(prev,eld)
142 end;
143
144 function GOst(prev,eld:TStatement):TStatement;far;
145 begin
146 if token='SUB' then
147 begin
148 gettoken;
149 GOst:=GOSUBst(prev,eld)
150 end
151 else
152 begin
153 checkToken1('TO',IDH_CONTROL);
154 GOst:=GOTOst(prev,eld);
155 end;
156 end;
157
158
159 {************}
160 {if structure}
161 {************}
162
163
164 constructor TCustomIfStatement.create(prev,eld:TStatement; cond1:TLogical);
165 begin
166 inherited create(prev,eld);
167 condition:=cond1;
168 end;
169
170 destructor TCustomIfStatement.destroy;
171 begin
172 ElseBlock.free;
173 thenblock.free;
174 condition.free;
175 inherited destroy
176 end;
177
178 procedure TIfStructure.CollectLabelInfo(t:TLabelNumberTable);
179 begin
180 t.additem(self);
181 if ThenBlock<>nil then ThenBlock.CollectLabelInfo(t);
182 if ElseBlock<>nil then ElseBlock.CollectLabelInfo(t);
183 if next<>nil then next.CollectLabelInfo(t);
184 end;
185 (*
186 function TIfStructure.SetBreakPoint(i:integer; b:boolean):boolean;
187 begin
188 if i=LineNumb then
189 result:=changeStopKeySence(b)
190 else
191 result:=(ThenBlock<>nil) and ThenBlock.SetBreakPoint(i,b)
192 or (ElseBlock<>nil) and ElseBlock.SetBreakPoint(i,b)
193 or (next<>nil) and next.SetBreakPoint(i,b)
194 end;
195 *)
196
197 {*******}
198 {compile}
199 {*******}
200
201 function imperativest(prev,eld:TStatement):TStatement;
202 var
203 prc:StatementFunction;
204 sp:statementspec;
205 p:TStatement;
206 begin
207 result:=nil;
208
209 if (token='IF') and not permitMicrosoft and (AutoCorrect[ac_multi] or
210 confirm(s_IFTHENCorrectConfirm,IDH_MicroSoft_CONTROL) ) then
211 NestedIfStatement;
212
213 if (token='END') then
214 if permitMicrosoft then
215 begin result:=STOPst(prev,eld);gettoken;exit end
216 else if (AutoCorrect[ac_end] or
217 confirm(s_ENDCorrectConfirm,IDH_MICROSOFT_CONTROL)) then
218 begin
219 replaceToken('STOP');
220 raise ERecompile.create('');
221 end;
222
223 if statementTable.find(token,prc,sp)
224 and ((sp=imperative) or permitMicrosoft and (sp=structural) )then
225 begin
226 gettoken;
227 result:=prc(prev,eld);
228 end
229 else
230 result:=tryLETst(prev,eld);
231
232 if (result<>nil) and (permitMicrosoft) and (token=':') then
233 begin
234 gettoken;
235 result.next:=imperativest(result,eld);
236 end;
237
238 end;
239
240 {************}
241 {IF Statement}
242 {************}
243
244 function IFstSub(prev,eld,ini:TStatement; elseifst:boolean):TCustomIfStatement;forward;
245 function IFst(prev,eld:TStatement):TStatement;far;
246 begin
247 IFline:=true;
248 IFst:=IFstSub(prev,eld,nil,false)
249 end;
250
251 function IFstSub(prev,eld,ini:TStatement; elseifst:boolean):TCustomIfStatement;
252 var
253 condition:TLogical;
254 begin
255 condition:=relationalExpression;
256 checkToken('THEN',IDH_IF);
257 SaveToken(SvThenBlockPos);
258 result:=nil;
259 try
260 if (tokenspec<>tail)
261 and not(permitMicrosoft and (token=':'))
262 and not elseifst then
263 result:=TIfStatement.create(prev,eld,condition)
264 else
265 result:=TIfStructure.create(prev,eld,condition,ini)
266 except
267 result.free;
268 raise
269 end;
270 end;
271
272 constructor TIfStatement.create(prev,eld:TStatement; cond1:TLogical);
273 begin
274 inherited create(prev,eld,cond1);
275 if tokenspec=NRep then
276 begin
277 thenBlock:=TGOTO.create(self,nil);
278 //if thenBlock<>nil then thenBlock.eldest:=thenBlock;
279 if (token='ELSE') and (NextTokenSpec=Nrep) then
280 begin
281 gettoken;
282 ElseBlock:=TGOTO.create(self,nil);
283 //if ElseBlock<>nil then ElseBlock.Eldest:=ElseBlock;
284 end;
285 end
286 else
287 begin
288 thenBlock:=imperativest(self,nil);
289 //SetEldest(thenBlock);
290 if token='ELSE' then
291 begin
292 gettoken;
293 ElseBlock:=imperativest(self,nil);
294 //setEldest(ElseBlock);
295 end;
296 end;
297 end;
298
299 constructor TIfStructure.create(prev,eld:TStatement; cond1:TLogical; ini:TStatement);
300 var
301 p:TStatement;
302 begin
303 inherited create(prev,eld,cond1);
304 if ini<>nil then
305 InitialLine:=ini
306 else
307 InitialLine:=self ;
308 nextline;
309 thenblock:=block(self);
310 p:=Last(ThenBlock);
311 if p is TTerminal then
312 TTerminal(p).statement:=initialLine;
313 if token='ELSEIF' then
314 begin
315 gettoken;
316 ElseBlock:=IFstSub(self,nil,initialLine,true) ;
317 //if ElseBlock<>nil then setEldest(ElseBlock);
318 end
319 else
320 begin
321 if token ='ELSE' then
322 begin
323 gettoken;
324 nextline ;
325 ElseBlock:=block(self);
326 p:=last(ElseBlock);
327 if p is TTerminal then
328 TTerminal(p).statement:=initialLine;
329 end;
330 checktoken1('END',IDH_IF);
331 checktoken('IF',IDH_IF);
332 end;
333 end;
334
335 function ELSEst(prev,eld:TStatement):TStatement;far;
336 begin
337 result:=TTerminal.create(prev,eld)
338 end;
339
340 {********}
341 {FOR NEXT}
342 {********}
343 type
344 TNEXT=class(TStatement)
345 controlVar,own1,own2:TSubstance;//TVariable; {copy pointer,������������}
346 HaveIncrement:boolean;
347 //procedure exec;override;
348 function Code:Ansistring;override;
349 end;
350
351 TFNEXT=class(TNEXT)
352 //procedure exec;override;
353 end;
354
355 TFsimpleNEXT=class(TNEXT)
356 //procedure exec;override;
357 end;
358
359 TCNEXT=class(TNEXT)
360 //procedure exec;override;
361 end;
362
363
364 procedure TForStructure.CollectLabelInfo(t:TLabelNumberTable);
365 begin
366 t.additem(self);
367 if Block<>nil then Block.CollectLabelInfo(t);
368 if next<>nil then next.CollectLabelInfo(t);
369 end;
370 (*
371 function TForStructure.SetBreakPoint(i:integer; b:boolean):boolean;
372 begin
373 if i=LineNumb then
374 result:=changeStopKeySence(b)
375 else
376 result:=(Block<>nil) and Block.SetBreakPoint(i,b)
377 or (next<>nil) and next.SetBreakPoint(i,b)
378 end;
379 *)
380
381 destructor TForStructure.destroy;
382 begin
383 controlVar.free;
384 initial.free;
385 limit.free;
386 increment.free;
387 Block.free;
388 //own1.free;
389 //own2.free;
390 inherited destroy
391 end;
392
393
394
395 function FORst(prev,eld:TStatement):TStatement;far;
396 begin
397 Forst:=TForStructure.create(prev,eld)
398 end;
399
400 procedure checkForVariable;
401 var
402 i:integer;
403 begin
404 with ForStack do
405 for i:=0 to count-1 do
406 if (TObject(items[i]) as TForStructure).variable=token then
407 seterr(s_NestedSameVarFOR,IDH_FOR_NEXT);
408 end;
409
410 var
411 SeqCounter:cardinal=0;
412 function Own1Name:string;
413 begin
414 result:='_own1_'+Format('%5.5u',[SeqCounter]);
415 inc(SeqCounter)
416 end;
417 function Own2Name:string;
418 begin
419 result:='_own2_'+Format('%5.5u',[SeqCounter])
420 end;
421
422
423
424 constructor TForStructure.create(prev,eld:TStatement);
425 var
426 p:TStatement;
427 idrec:TIdRec;
428 begin
429 inherited create(prev,eld);
430 {inc(ForNest);}
431 if ForStack.count>0 then CheckForVariable;
432 ForStack.add(self);
433 {control variable}
434 variable:=token;
435 controlVar:=simpleVariable;
436 checktoken('=',IDH_FOR_NEXT);
437 initial:=NExpression;
438 checktoken('TO',IDH_FOR_NEXT);
439 limit:=NExpression;
440 if token='STEP' then
441 begin
442 gettoken;
443 increment:=NEXpression
444 end;
445 nextline;
446
447 if pass=2 then
448 begin
449 idrec:=TIdRec.initSimple(Own1Name,intern,maxint);
450 own1:=idrec.subs;
451 if ForNextBroadOwn then
452 ProgramUnit.VarTable.add(idrec)
453 else
454 Proc.VarTable.add(idrec); //2008.4.2
455 idrec:=TIdRec.initSimple(Own2name,intern,maxint);
456 own2:=idrec.subs;
457 if ForNextBroadOwn then
458 ProgramUnit.VarTable.add(idrec)
459 else
460 Proc.VarTable.add(idrec); //2008.4.2
461 end;
462
463 Block:=struct.block(self);
464 with ForStack do delete(count-1); {Dec(ForNest);}
465 checktoken1('NEXT',IDH_FOR_NEXT);
466
467 if token=variable then
468 gettoken
469 else
470 if permitMicrosoft then
471 else
472 if (autocorrect[ac_next] or
473 confirm(variable+s_IsExpected+s_InquireInsert,IDH_FOR_NEXT))
474 and (token='') then
475 inserttext(variable)
476 else
477 seterrExpected(variable,IDH_FOR_NEXT);
478 p:=last(Block);
479 if p is TNEXT then
480 begin
481 TNEXT(p).controlvar:=controlvar;
482 TNEXT(p).own1:=own1;
483 TNEXT(p).own2:=own2;
484 TNext(p).HaveIncrement:=(Increment<>nil);
485 end;
486
487 if pass=2 then
488 begin
489 ControlVar.AddQueryInteger(Initial.QueryInteger);
490 if increment<>nil then
491 ControlVar.AddQueryInteger(Increment.QueryInteger);
492 Own1.AddQueryInteger(Limit.QueryInteger);
493 if Increment<>nil then
494 Own2.AddQueryInteger(Increment.QueryInteger);
495 end;
496 end;
497
498
499 function NEXTst(prev,eld:TStatement):TStatement;far;
500 begin
501 if (ProgramUnit.arithmetic=PrecisionNative) then
502 if (eld<>nil) and (eld.previous <> nil)
503 and (eld.previous is TForStructure) //2010.07.02
504 and ((eld.previous as TForStructure).increment=nil) then
505 NEXTst:=TFsimpleNEXT.create(prev,eld)
506 else
507 NEXTst:=TFNEXT.create(prev,eld)
508 else if (ProgramUnit.arithmetic=PrecisionComplex) then
509 NEXTst:=TCNEXT.create(prev,eld)
510 else
511 NEXTst:=TNEXT.create(prev,eld)
512 end;
513
514
515 {**********}
516 { DO block }
517 {**********}
518 type
519 TLOOP=class(TStatement)
520 cond2:TLogical;
521 while2:Boolean;
522 constructor create(prev,eld:TStatement);
523 destructor destroy;override;
524 //procedure exec;override;
525 function Code:AnsiString;override;
526 end;
527
528 destructor TDoStructure.destroy;
529 begin
530 cond1.free;
531 Block.free;
532 inherited destroy;
533 end;
534
535 destructor TLOOP.destroy;
536 begin
537 cond2.free;
538 inherited destroy;
539 end;
540
541 procedure TDoStructure.CollectLabelInfo(t:TLabelNumberTable);
542 begin
543 t.additem(self);
544 if Block<>nil then Block.CollectLabelInfo(t);
545 if next<>nil then next.CollectLabelInfo(t);
546 end;
547 (*
548 function TDoStructure.SetBreakPoint(i:integer; b:boolean):boolean;
549 begin
550 if i=LineNumb then
551 result:=changeStopKeySence(b)
552 else
553 result:=(block<>nil) and Block.SetBreakPoint(i,b)
554 or (next<>nil) and Next.SetBreakPoint(i,b)
555 end;
556 *)
557
558 function DOst(prev,eld:TStatement):TStatement;far;
559 begin
560 DOst:=TDOstructure.create(prev,eld)
561 end;
562
563 constructor TDoStructure.create(prev,eld:TStatement);
564 var
565 dummy:TStatement;
566 begin
567 inherited create(prev,eld);
568 DoStack.add(self);
569 if token='UNTIL' then
570 begin
571 gettoken;
572 until1:=true;
573 cond1:=relationalexpression
574 end
575 else if token='WHILE' then
576 begin
577 gettoken;
578 until1:=false;
579 cond1:=relationalexpression
580 end;
581
582 nextline;
583 Block:=struct.block(self);
584 with DoStack do delete(count-1); {dec(DoNest);}
585 checkToken1('LOOP',IDH_DO_LOOP);
586 {skip;}
587 {95.5.20} dummy:=TLOOP.create(self,eld);
588 dummy.free;
589 end;
590
591 function LOOPst(prev,eld:TStatement):TStatement;far;
592 begin
593 LOOPst:=TLOOP.create(prev,eld)
594 end;
595
596
597 constructor TLOOP.create(prev,eld:TStatement);
598 begin
599 inherited create(prev,eld);
600 if token='UNTIL' then
601 begin
602 gettoken;
603 while2:=false;
604 cond2:=relationalexpression
605 end
606 else if token='WHILE' then
607 begin
608 gettoken;
609 while2:=true;
610 cond2:=relationalexpression
611 end;
612 end;
613
614 {***************}
615 {EXIT statements}
616 {***************}
617
618 type
619 TEXITHandlerU=class(TStatement)
620 whenBlock0:TWhenException;
621 constructor create(prev,eld:TStatement);
622 //procedure exec;override;
623 function code:ansistring;override;
624 end;
625
626 constructor TEXITHandlerU.create(prev,eld:TStatement);
627 begin
628 inherited create(prev,eld);
629 with WhenUseStack do WhenBlock0:=items[count-1];
630 end;
631
632 type
633 TEXITHandlerH=class(TStatement)
634 handler:THandler;
635 constructor create(prev,eld:TStatement);
636 //procedure exec;override;
637 function code:ansistring;override;
638 end;
639
640 constructor TEXITHandlerH.create(prev,eld:TStatement);
641 begin
642 inherited create(prev,eld);
643 handler:=LocalRoutine as THandler;
644 end;
645
646 type
647 TEXITDO=class(TStatement)
648 statement:TStatement;
649 TryInside:boolean;
650 constructor create(prev,eld:TStatement);
651 //procedure exec;override;
652 function Code:AnsiString; override;
653 end;
654
655 TEXITDO1=class(TStatement) //USE������������������������������������������
656 statement:TStatement;
657 constructor create(prev,eld:TStatement);
658 //procedure exec;override;
659 function Code:AnsiString; override;
660 end;
661
662
663 constructor TEXITDO.create(prev,eld:TStatement);
664 var
665 p:TStatement;
666 begin
667 inherited create(prev,eld);
668 p:=self;
669 repeat
670 if p.eldest=nil then
671 raise Exception.create('');
672 p:=p.eldest.previous;
673 if p is TWhenException then TryInside:=true;
674 until p is TDoStructure;
675 Statement:=p;
676
677 //if (prev is TReadInput) then // IF MISSING THEN EXIT DO
678 // TryInside:=true;
679 if TryInside then
680 (TStatement(Statement) as TDoStructure).haveExitDoInWhen:=true
681 else
682 (TStatement(Statement) as TDoStructure).haveExitDo:=true;
683 end;
684
685 constructor TEXITDO1.create(prev,eld:TStatement);
686 begin
687 inherited create(prev,eld);
688 with DoStack do Statement:=items[count-1];
689 // (TStatement(Statement) as TDoStructure).haveExitDo:=true;
690 (TStatement(Statement) as TDoStructure).haveExitDoInWhen:=true;
691 end;
692
693 type
694 TEXITFOR=class(TStatement)
695 statement:TStatement;
696 TryInside:boolean;
697 constructor create(prev,eld:TStatement);
698 //procedure exec;override;
699 function Code:AnsiString; override;
700 end;
701
702 TEXITFOR1=class(TStatement) //USE���������������������������������������������
703 statement:TStatement;
704 constructor create(prev,eld:TStatement);
705 //procedure exec;override;
706 function Code:AnsiString; override;
707 end;
708
709 constructor TEXITFOR.create(prev,eld:TStatement);
710 var
711 p:TStatement;
712 begin
713 inherited create(prev,eld);
714 p:=self;
715 repeat
716 p:=p.eldest.previous;
717 if p is TWhenException then TryInside:=true;
718 until p is TForStructure;
719 Statement:=p;
720
721 //if (prev is TReadInput) then // IF MISSING THEN EXIT DO
722 // TryInside:=true;
723 if TryInside then
724 (TStatement(Statement) as TForStructure).haveExitForInWhen:=true
725 else
726 (TStatement(Statement) as TForStructure).haveExitFor:=true;
727 end;
728
729 constructor TEXITFOR1.create(prev,eld:TStatement);
730 begin
731 inherited create(prev,eld);
732 with FORStack do Statement:=items[count-1];
733 //(TStatement(Statement) as TForStructure).haveExitFor:=true;
734 (TStatement(Statement) as TForStructure).haveExitForInWhen:=true;
735 end;
736
737 function EXITst(prev,eld:TStatement):TStatement;
738 var
739 exitkind:integer;
740 begin
741 EXITst:=nil;
742 if (token='DO') and (DoStack.count>0) then
743 try
744 EXITst:=TEXITDO.create(prev,eld)
745 except
746 EXITst:=TEXITDO1.create(prev,eld)
747 end
748 else if (token='FOR') and (ForStack.count>0) then
749 try
750 EXITst:=TEXITFOR.create(prev,eld)
751 except
752 EXITst:=TEXITFOR1.create(prev,eld)
753 end
754 else if ((token='FUNCTION') or (token='SUB')
755 or (token='PICTURE')) then
756 if (LocalRoutine<>nil) and (LocalRoutine.kind=token[1]) then
757 begin
758 LocalRoutine.HaveExitst:=true;
759 case token[1] of
760 'F':EXITst:=TEXIT.create(prev,eld,EExitFunction);
761 'S':EXITst:=TEXIT.create(prev,eld,EExitSub);
762 'P':EXITst:=TEXIT.create(prev,eld,EExitPicture);
763 end;
764 end
765 else if (ProgramUnit.kind=token[1]) then
766 begin
767 ProgramUnit.HaveExitst:=true;
768 case token[1] of
769 'F':EXITst:=TEXIT.create(prev,eld,EExitFunction);
770 'S':EXITst:=TEXIT.create(prev,eld,EExitSub);
771 'P':EXITst:=TEXIT.create(prev,eld,EExitPicture);
772 end;
773 end
774 else
775 else if token='HANDLER' then
776 if (LocalRoutine<>nil) and (LocalRoutine.kind=token[1]) then {Handler���}
777 EXITst:=TEXITHandlerH.create(prev,eld)
778 else if usenest>0 then
779 EXITst:=TEXITHandlerU.create(prev,eld)
780 else
781 seterrIllegal('EXIT '+token,IDH_CAUSE)
782 else
783 seterrIllegal('EXIT '+token,IDH_DO_LOOP);
784 gettoken;
785 end;
786
787 {*****}
788 {Cause}
789 {*****}
790
791 type
792 TCause=class(TStatement)
793 typ:integer;
794 constructor create(prev,eld:TStatement; t:integer);
795 //procedure exec;override;
796 function Code:Ansistring;override;
797 end;
798
799 constructor TCause.create(prev,eld:TStatement; t:integer);
800 begin
801 inherited create(prev,eld);
802 typ:=t
803 end;
804
805
806 {***********}
807 {SELECT CASE}
808 {***********}
809
810 type
811 TCase=class(TCustomIFstatement)
812 constructor create(prev,eld:TStatement;idrec:TIdRec);
813 end;
814
815
816
817 function caseitem(idrec:TIdrec):TLogical;forward;
818
819 function caselist(idrec:TIDRec):TLogical;
820 var
821 list:TLogical;
822 begin
823 list:=caseItem(idrec);
824 while token=',' do
825 begin
826 gettoken;
827 list:=TDisjunction.create(list,caseitem(idrec));
828 end;
829 caselist:=list
830 end;
831
832 function caseitem(idrec:TIdRec):TLogical;
833 var
834 exp:TPrincipal;
835 f:comparefunction;
836 s:boolean;
837 begin
838 caseitem:=nil;
839 s:=false;
840 if token='IS' then
841 begin
842 s:=true;
843 gettoken;
844 findcomparefunction(token,f);
845 gettoken;
846 end
847 else
848 f:=Equals;
849 if idrec.kindchar='n' then
850 exp:=NConstant
851 else
852 exp:=SConstant ;
853 if exp=nil then exit;
854 if (token='TO') and not s then
855 begin
856 gettoken;
857 if idrec.kindchar='n' then
858 caseitem:=TConjunction.create(
859 TComparisonN.create(exp,idrec.subs,NotGreater),
860 TComparisonN.create(idrec.subs,NConstant,NotGreater))
861 else
862 caseitem:=TConjunction.create(
863 TComparisonS.create(exp,idrec.subs,NotGreater),
864 TComparisonS.create(idrec.subs ,SConstant,NotGreater))
865 end
866 else
867 if idrec.kindchar='n' then
868 caseitem:=TComparisonN.create(idrec.subs,exp,f)
869 else
870 caseitem:=TComparisonS.create(idrec.subs,exp,f)
871 end;
872
873 {***********}
874 {SELECT CASE}
875 {***********}
876
877
878
879 function SELECTst(prev,eld:TStatement):TStatement;far;
880 begin
881 checktoken('CASE',IDH_SELECT);
882 SELECTst:=TSelect.create(prev,eld)
883 end;
884
885 constructor TSelect.create(prev,eld:TStatement);
886 var
887 name:string[15];
888 condition:TLogical;
889 idr:TIdRec;
890 begin
891 inherited create(prev,eld);
892 exp:=NSExpression;
893 name:=Own1Name;
894 if exp.kind='s' then name:=name+'$';
895
896 idr:=TIdRec.initSimple(name,intern,maxint);
897 own:=idr.subs;
898 if pass=2 then
899 begin
900 ProgramUnit.VarTable.add(idr) ;
901 Own.AddQueryInteger(exp.QueryInteger);
902 end
903 else
904 OwnToFree:=true;
905
906
907 nextline;
908 checktoken1('CASE',IDH_SELECT);
909 caseblock:=TCase.create(self,nil,idr);
910 //SetEldest(CaseBlock);
911 checktoken1('END',IDH_SELECT);
912 checktoken('SELECT',IDH_SELECT);
913
914
915 end;
916
917
918 constructor TCASE.create(prev,eld:TStatement; idrec:TIdRec);
919 begin
920 inherited create(prev,eld,caselist(idrec));
921 nextline;
922 thenblock:=block(self);
923 if token='CASE' then
924 begin
925 gettoken;
926 if token='ELSE' then
927 begin
928 gettoken;
929 nextline;
930 elseblock:=block(self)
931 end
932 else
933 begin
934 elseblock:=TCase.create(self,nil,idrec);
935 //SetEldest(ElseBlock);
936 end;
937 end
938 else
939 begin
940 elseblock:=TCause.create(self,nil,10004); {END SELECT line}
941 end;
942 end;
943
944 procedure TSelect.CollectLabelInfo(t:TLabelNumberTable);
945 begin
946 t.additem(self);
947 if caseBlock<>nil then CaseBlock.CollectLabelInfo(t);
948 if next<>nil then next.CollectLabelInfo(t);
949 end;
950 (*
951 function TSelect.SetBreakPoint(i:integer; b:boolean):boolean;
952 begin
953 if i=LineNumb then
954 result:=changeStopKeySence(b)
955 else
956 result:=(CaseBlock<>nil) and CaseBlock.setBreakPoint(i,b)
957 or (next<>nil) and next.setBreakPoint(i,b)
958 end;
959 *)
960
961
962 destructor TSelect.destroy;
963 begin
964 exp.free;
965 caseblock.free;
966 //if pass=1 then
967 if OwnToFree then
968 own.idr.free;
969 inherited destroy
970 end;
971
972
973
974 {*******}
975 {STOP st}
976 {*******}
977
978 function STOPst(prev,eld:TStatement):TStatement;far;
979 begin
980 STOPst:=TEXIT.create(prev,eld,EStop)
981 end;
982 {******}
983 {RETURN}
984 {******}
985
986 type
987 TReturn=Class(TExit)
988 function Code:AnsiString;override;
989 end;
990
991 function RETURNst(prev,eld:TStatement):TStatement;far;
992 begin
993 RETURNst:=TRETURN.create(prev,eld,EReturn)
994 end;
995
996
997
998 {**************}
999 {RETRY CONTINUE}
1000 {**************}
1001
1002 Type
1003 TRetry=Class(TExit)
1004 WhenBlock0:TWhenException;
1005 constructor create(prev,eld:TStatement; t:TControlException);
1006 function Code:AnsiString;override;
1007 end;
1008
1009 constructor TRetry.create(prev,eld:TStatement; t:TControlException);
1010 begin
1011 inherited create(prev,eld,t);
1012 with WhenUseStack do WhenBlock0:=items[count-1];
1013 if WhenBlock0<>nil then
1014 begin
1015 WhenBlock0.HaveRetry:=true;
1016 proc.HaveRETRYst:=true;
1017 end
1018 else if (localRoutine<>nil) and (LocalRoutine is THandler) then
1019 (LocalRoutine as Thandler).HaveRetry:=true;
1020 end;
1021
1022 Function RETRYst(prev,eld:TStatement):TStatement;far;
1023 begin
1024 if usenest=0 then
1025 begin
1026 RETRYst:=nil;
1027 seterrillegal(prevtoken,IDH_WHEN_EXCEPTION)
1028 end
1029 else
1030 RETRYst:=TRETRY.create(prev,eld,ERetry)
1031 end;
1032
1033 Type
1034 TContinue=Class(TExit)
1035 WhenBlock0:TWhenException ;
1036 constructor create(prev,eld:TStatement; t:TControlException);
1037 function Code:AnsiString;override;
1038 end;
1039
1040 constructor TContinue.create(prev,eld:TStatement; t:TControlException);
1041 begin
1042 inherited create(prev,eld,t);
1043 with WhenUseStack do WhenBlock0:=items[count-1];
1044 if WhenBlock0<>nil then
1045 begin
1046 WhenBlock0.HaveContinue:=true;
1047 proc.HaveContinuest:=true;
1048 end
1049 else if (localRoutine<>nil) and (LocalRoutine is THandler) then
1050 (LocalRoutine as Thandler).HaveContinue:=true;
1051
1052 end;
1053
1054 Function CONTINUEst(prev,eld:TStatement):TStatement;far;
1055 begin
1056 if usenest=0 then
1057 begin
1058 CONTINUEst:=nil;
1059 seterrillegal(prevtoken,IDH_WHEN_EXCEPTION)
1060 end
1061 else
1062 CONTINUEst:=TContinue.create(prev,eld,EContinue)
1063 end;
1064
1065
1066 {***************}
1067 {CALL statement }
1068 {***************}
1069
1070
1071 function CALLst(prev,eld:TStatement):TStatement;far;
1072 begin
1073 CALLst:=TCALL.create(prev,eld,'S');
1074 end;
1075
1076 {***************}
1077 {Cause Exception}
1078 {***************}
1079 type
1080 TCauseException=class(TStatement)
1081 exp:TPrincipal;
1082 constructor create(prev,eld:TStatement);
1083 //procedure exec;override;
1084 destructor destroy;override;
1085 function Code:Ansistring;override;
1086 end;
1087
1088 function CauseExceptionst(prev,eld:TStatement):Tstatement;
1089 begin
1090 checkToken('EXCEPTION',IDH_WHEN);
1091 CauseExceptionst:=TCauseException.create(prev,eld);
1092 end;
1093
1094 constructor TCauseException.create(prev,eld:TStatement);
1095 begin
1096 inherited create(prev,eld);
1097 exp:=NExpression;
1098 end;
1099
1100 destructor TCauseException.destroy;
1101 begin
1102 exp.free;
1103 inherited destroy;
1104 end;
1105
1106 {************}
1107 {On statement}
1108 {************}
1109
1110 type
1111 TON=class(TStatement)
1112 exp:TPrincipal;
1113 list:TList;
1114 elsest:TStatement;
1115 gosub:boolean;
1116 constructor create(prev,eld:TStatement);
1117 //procedure exec; override;
1118 destructor destroy;override;
1119 function Code:Ansistring;override;
1120 end;
1121
1122 function ONst(prev,eld:TStatement):TStatement;
1123 begin
1124 ONst:=TON.create(prev,eld);
1125 end;
1126
1127 constructor TON.create(prev,eld:TStatement);
1128 var
1129 dummy:integer;
1130 p:TStatement;
1131 begin
1132 inherited create(prev,eld);
1133 list:=TList.create;
1134 exp:=NExpression;
1135 if token='GO' then
1136 begin
1137 gettoken;
1138 if token='SUB' then
1139 begin
1140 gettoken;
1141 gosub:=true;
1142 end;
1143 checktoken1('TO',IDH_CONTROL);
1144 end
1145 else if token='GOSUB' then
1146 begin
1147 gettoken;
1148 gosub:=true;
1149 end
1150 else
1151 checkToken1('GOTO',IDH_CONTROL);
1152
1153 repeat
1154 if gosub=false then
1155 p:=TGOTO.create(self,nil)
1156 else
1157 p:=TGOSUB.create(self,nil);
1158 //p.eldest:=p;
1159 dummy:=List.add(p)
1160 until test(',')=false;
1161
1162 if token='ELSE' then
1163 begin
1164 gettoken;
1165 elsest:=imperativest(self,nil);
1166 if elsest<>nil then elsest.eldest:=elsest;
1167 end;
1168 end;
1169
1170
1171 destructor TON.destroy;
1172 var
1173 i:integer;
1174 begin
1175 exp.free;
1176 elsest.free;
1177 for i:=0 to list.count-1 do TObject(list.items[i]).free;
1178 list .free;
1179 inherited destroy;
1180 end;
1181
1182 {*************}
1183 {WHILE ...WEND}
1184 {*************}
1185
1186 type
1187 TWHILE=class(TDoStructure)
1188 constructor create(prev,eld:TStatement);
1189 end;
1190
1191 function WHILEst(prev,eld:TStatement):TStatement;
1192 begin
1193 if (token='1') and ((nexttoken='') or (nextToken=':')) then
1194 begin
1195 if permitMicrosoft then
1196 begin
1197 gettoken;
1198 whilest:=Dost(prev,eld);
1199 end
1200 else if autocorrect[ac_while] or
1201 confirm(s_ConfirmWHILE1toDO,IDH_MICROSOFT_CONTROL) then
1202 begin
1203 ReplacePrevToken('DO');
1204 ReplaceToken('');
1205 raise ERecompile.create('');
1206 end
1207 else
1208 seterr('',IDH_MICROSOFT_CONTROL)
1209 end
1210 else
1211 begin
1212 if permitMicrosoft then
1213 begin
1214 Whilest:=TWHILE.create(prev,eld);
1215 end
1216 else if autocorrect[ac_while] or
1217 confirm(s_ConfirmWHILEtoDOWHILE,IDH_MICROSOFT_CONTROL) then
1218 begin
1219 ReplacePrevToken('DO WHILE');
1220 raise ERecompile.create('');
1221 end
1222 else
1223 seterr('',IDH_MICROSOFT_CONTROL)
1224 end;
1225
1226 end;
1227
1228 function WENDst(prev,eld:TStatement):TStatement;
1229 begin
1230 if permitMicrosoft then
1231 WENDst:=LOOPst(prev,eld)
1232 else if autocorrect[ac_while] or
1233 confirm(s_ConfirmWENDtoLOOP,IDH_MICROSOFT_CONTROL) then
1234 begin
1235 ReplacePrevToken('LOOP');
1236 raise ERecompile.create('');
1237 end
1238 else
1239 seterr('',IDH_MICROSOFT_CONTROL)
1240 end;
1241
1242 constructor TWHILE.create(prev,eld:TStatement);
1243 var
1244 dummy:TStatement;
1245 begin
1246 inherited Tstatementcreate(prev,eld);
1247 DoStack.add(self);
1248 until1:=false;
1249 cond1:=relationalexpression;
1250
1251 nextline;
1252 Block:=struct.block(self);
1253 with DoStack do delete(count-1); {dec(DoNest);}
1254 checkToken1('WEND',IDH_DO_LOOP);
1255 {skip;}
1256 {95.5.20} dummy:=TLOOP.create(self,eld);
1257 dummy.free;
1258 end;
1259
1260 {*********}
1261 {RANDOMIZE}
1262 {*********}
1263
1264 type
1265 TRandomize=class(TStatement)
1266 routine:TProgramUnit;
1267 exp:TPrincipal;
1268 constructor create(prev,eld:TStatement);
1269 //procedure exec;override;
1270 function Code:AnsiString;override;
1271 end;
1272
1273
1274 function RANDOMIZEst(prev,eld:TStatement):TStatement;far;
1275 begin
1276 RANDOMIZEst:=TRandomize.create(prev,eld)
1277 end;
1278
1279 constructor TRandomize.create(prev,eld:TStatement);
1280 begin
1281 inherited create(prev,eld);
1282 routine:=programunit;
1283 if (tokenspec<>tail) and (token<>'ELSE') then
1284 exp:=NExpression;
1285 end;
1286
1287 {****************}
1288 {Execute Routines}
1289 {****************}
1290 (*
1291 procedure TGOSUB.exec;
1292 var
1293 svCurrentStatement,svNextStatement:TStatement;
1294 begin
1295 if stacksize1>=StackLimit1 then
1296 setexception(stackoverflow);
1297 idle;
1298
1299 svCurrentStatement:=CurrentStatement;
1300 svNextStatement:=NextStatement;
1301 try
1302 RunBlock(statement)
1303 except
1304 on EExtype do
1305 if Extype=10002 then
1306 begin
1307 extype:=0;
1308 CurrentStatement:=svCurrentStatement;
1309 NextStatement:=svNextStatement;
1310 end
1311 else
1312 raise;
1313 end;
1314 end;
1315
1316 procedure TIfStatement.exec;
1317 begin
1318 if condition.evalBool then
1319 ThenBlock.SequentiallyExecute
1320 else
1321 ElseBlock.SequentiallyExecute;
1322 end;
1323
1324 procedure TIfStructure.exec;
1325 begin
1326 if condition.evalBool then
1327 if ThenBlock<>nil then
1328 NextStatement:=ThenBlock
1329 else
1330 NextStatement:=InitialLine.next //ExecutiveNext
1331 else
1332 if ELSEBlock<>nil then
1333 NextStatement:=ELSEBlock
1334 else
1335 NextStatement:=InitialLine.next //ExecutiveNext;
1336 end;
1337
1338 procedure TCustomIfStatement.exec;
1339 begin
1340 if condition.evalBool then
1341 if ThenBlock<>nil then
1342 NextStatement:=ThenBlock
1343 else
1344 NextStatement:=ExecutiveNext
1345 else
1346 if ELSEBlock<>nil then
1347 NextStatement:=ELSEBlock
1348 else
1349 NextStatement:=ExecutiveNext;
1350 end;
1351
1352 procedure TForStructure.exec;
1353 begin
1354 own1.assign(limit) ;
1355 if (increment=nil) then
1356 own2.substone
1357 else
1358 own2.assign(increment) ;
1359 ControlVar.assign(initial);
1360 execloop ;
1361 end;
1362
1363 procedure TForStructure.execloop;
1364 begin
1365 if (ControlVar.compare(own1) * Own2.sign <= 0) then
1366 NextStatement:=Block;
1367 end;
1368
1369
1370 procedure TNEXT.exec;
1371 begin
1372 idle;
1373 ControlVar.add(Own2);
1374 if (ControlVar.compare(Own1) * Own2.sign <= 0) then
1375 NextStatement:=eldest
1376 else
1377 NextStatement:=eldest.previous.next;
1378 end;
1379
1380 procedure TFNEXT.exec;
1381 var
1382 p,q:PDouble;
1383 begin
1384 idle;
1385 p:=TbasisFVar(ControlVar.ptr).GetPValue;
1386 q:=@(TorthoFVar(Own2.ptr).value);
1387 p^:=p^+q^;
1388 if (p^-TorthoFVar(Own1.ptr).value) * q^ <= 0 then
1389 NextStatement:=eldest
1390 else
1391 NextStatement:=eldest.previous.next;
1392 end;
1393
1394 procedure TFsimpleNEXT.exec;
1395 var
1396 p:PDouble;
1397 begin
1398 idle;
1399 p:=TbasisFVar(ControlVar.ptr).GetPValue;
1400 p^:=p^+1;
1401 if (p^-TorthoFVar(Own1.ptr).value) <= 0 then
1402 NextStatement:=eldest
1403 else
1404 NextStatement:=eldest.previous.next;
1405 end;
1406
1407 procedure TCNEXT.exec;
1408 var
1409 p,q:PDouble;
1410 begin
1411 idle;
1412 PComplex(p):=TbasisCVar(ControlVar.ptr).GetPValue;
1413 q:=@(TorthoCVar(Own2.ptr).value.x);
1414 p^:=p^+q^;
1415 if (p^-TorthoCVar(Own1.ptr).value.x) * q^ <= 0 then
1416 NextStatement:=eldest
1417 else
1418 NextStatement:=eldest.previous.next;
1419 end;
1420
1421 procedure TDoStructure.exec;
1422 begin
1423 if ((cond1=nil) or (cond1.evalbool xor until1)) then
1424 nextStatement:=Block ;
1425 end;
1426
1427 procedure TLOOP.exec;
1428 var
1429 s:boolean;
1430 begin
1431 idle;
1432 if (cond2<>nil) and (cond2.evalbool xor while2)
1433 then NextStatement:=eldest.previous.next
1434 else
1435 NextStatement:=eldest.previous
1436 end;
1437
1438 procedure TEXITHandlerU.exec;
1439 begin
1440 with whenblock0 do
1441 extype:=svextype;
1442 raise EExitHandler.create(WhenBlock0);
1443 end;
1444
1445 procedure TEXITHandlerH.exec;
1446 var
1447 p:TWhenException;
1448 begin
1449 with handler.WhenUseBlockStack do TObject(p):=items[count-1];
1450 with p do
1451 extype:=svextype;
1452 raise EExitHandler.create(p);
1453 end;
1454
1455
1456 procedure TEXITDO.exec;
1457 begin
1458 NextStatement:=statement.next
1459 end;
1460
1461 procedure TEXITDO1.exec;
1462 begin
1463 raise EExitDo.create(statement.next)
1464 end;
1465
1466 procedure TEXITFOR.exec;
1467 begin
1468 NextStatement:=Statement.next
1469 end;
1470
1471 procedure TEXITFOR1.exec;
1472 begin
1473 raise EExitDo.create(statement.next)
1474 end;
1475
1476 procedure TCause.exec;
1477 begin
1478 setexception(typ);
1479 end;
1480
1481 procedure TSelect.exec;
1482 begin
1483 own.ptr.assign(exp);
1484 caseBlock.exec;
1485 end;
1486
1487 procedure TCauseException.exec;
1488 begin
1489 setexceptionwith('CAUSE EXCEPTION',exp.evalInteger);
1490 end;
1491
1492
1493 procedure TRandomize.exec;
1494 begin
1495 if exp=nil then
1496 MyRandomize
1497 else
1498 MyRandomize2(exp.evalInteger)
1499 end;
1500 *)
1501 (*
1502 Procedure TON.exec;
1503 var
1504 i:longint;
1505 begin
1506 i:=exp.evalInteger;
1507 if (i>0) and (i<=list.count) then
1508 (TObject(list.items[i-1]) as TGOTO).exec
1509 else if elsest<>nil then
1510 elsest.exec
1511 else
1512 setexception(10001)
1513 end;
1514 *)
1515 {*************}
1516 {Generate Code}
1517 {*************}
1518
1519
1520
1521 function TRandomize.code:ansistring;
1522 begin
1523 if exp=nil then
1524 result:='MyRandoMize;'
1525 else
1526 result:='MyRandomize2('+exp.code+');'
1527 end;
1528
1529 function TCustomIfStatement.Blockcode(Prelabel,AfterLabel:TstringList; HaveEXLINE:boolean):AnsiString;
1530 begin
1531 result := 'if ' + condition.code + ' then' + EOL
1532 + ' begin' + EOL
1533 + thenblock.gencode(Prelabel,Afterlabel,haveEXLINE)
1534 + ' end'+EOL
1535 + ' else' + EOL
1536 + ' begin' + EOL
1537 + elseblock.gencode(Prelabel,Afterlabel,HaveEXLINE)
1538 + ' end;'
1539 end;
1540
1541
1542 function TForStructure.BlockCode(PreLabel,AfterLabel:TstringList; HaveEXLINE:boolean):AnsiString;
1543 begin
1544 if increment<>nil then
1545 result:= own1.Code + ' := ' + limit.Code +' ;' +EOL
1546 + own2.Code + ' := ' + increment.Code +' ;'+ EOL
1547 + ControlVar.Code + ' := ' + initial.Code +' ;' +EOL
1548 + 'while sign(' + ControlVar.Code + ' - ' + own1.Code
1549 + ') * sign(' + own2.Code +')<=0 do begin' + EOL
1550 + block.gencode(PreLabel,AfterLabel,HaveEXLINE)
1551
1552 + 'end;'
1553
1554 else
1555 result:= own1.Code + ' := ' + limit.Code +' ;' +EOL
1556 + ControlVar.Code+ ' := ' + initial.Code +' ;' +EOL
1557 + 'while (' + ControlVar.Code + ' <= ' + own1.Code + ') do begin' + EOL
1558 + block.gencode(PreLabel,AfterLabel,HaveEXLINE)
1559
1560 + 'end;';
1561
1562 if HaveExitFor then
1563 result:=result
1564 +MakeLabel+':'+EOL;
1565
1566 if HaveExitForInWhen then
1567 result:= 'try' + EOL
1568 + result + EOL
1569 + 'except' + EOL
1570 + ' on E:EExitFor do ;' +EOL
1571 + 'end;'
1572
1573 end;
1574
1575 function TNext.code:ansistring;
1576 begin
1577 if HaveIncrement then
1578 result:= ControlVar.Code + ' := '+ ControlVar.Code +' + ' +own2.Code + ' ;'
1579 else
1580 result:= ControlVar.Code + ' := ' + ControlVar.Code +' + 1 ;' ;
1581
1582 // TRACE
1583 if PUnit.haveTraceSt then
1584 begin
1585 result:=result + EOL +
1586 'if Trace' + IntToStr(PUNIT.LineNumb+1) + '<>nil then '+
1587 'Trace' + IntToStr(PUNIT.LineNumb+1) + '.PRINT([],rsNone, false ,['' ' +
1588 ControlVar.idr.name + '='' ,';
1589 if PUnit.Arithmetic=precisionComplex then
1590 result := result+ 'TComplex.create('+ControlVar.Code+')'
1591 else
1592 result := result + ControlVar.Code;
1593 result:=result+ ', TNewLine.create ]);' + EOL;
1594 end;
1595 end;
1596
1597
1598
1599
1600 function TDoStructure.BlockCode(PreLabel,AfterLabel:TStringList; HaveEXLINE:boolean):AnsiString;
1601 var
1602 s:string;
1603 begin
1604 if Cond1<>nil then
1605 begin
1606 s:=Cond1.Code;
1607 if until1 then s:= 'not( ' + s + ')';
1608 result:='while ' + s + ' do begin '+EOL
1609 + Block.GenCode(PreLabel,AfterLabel,HaveEXLINE)
1610 + 'end;' ;
1611 end
1612 else
1613 result := 'repeat' + EOL
1614 + Block.GenCode(PreLabel,AfterLabel,HaveEXLINE) ;
1615
1616 if HaveExitDo then
1617 result:=result
1618 +MakeLabel+':'+EOL;
1619
1620 if HaveExitDoInWhen then
1621 result:= 'try' + EOL
1622 + result
1623 + 'except' + EOL
1624 + ' on E:EExitDo do ;' +EOL
1625 + 'end;'
1626
1627
1628
1629 end;
1630
1631 function TLoop.Code:AnsiString;
1632 var
1633 s:string;
1634 begin
1635 if Cond2<>nil then
1636 begin
1637 s:=Cond2.Code;
1638 if while2 then s:='not( ' + s+ ')'
1639 end
1640 else
1641 s:='false' ;
1642
1643 if (TStatement(eldest.previous) as TDoStructure).Cond1<>nil then
1644 if Cond2<>nil then
1645 result:='if ' + s + ' then break;' +EOL
1646 else
1647 result:=''
1648 else
1649 result:='until ' + s + ';'
1650 end;
1651
1652
1653 function TExitDo.Code:AnsiString;
1654 begin
1655 if TryInside then
1656 result:='raise EExitDo.create;'
1657 else
1658 result:='goto '+(TStatement(Statement) as TDoStructure).MakeLabel +';'
1659 end;
1660
1661 function TExitDo1.Code:AnsiString;
1662 begin
1663 // if TryInside then
1664 result:='raise EExitDo.create;'
1665 // else
1666 // result:='goto '+(TStatement(Statement) as TDoStructure).MakeLabel +';'
1667 end;
1668
1669 function TExitFor.Code:AnsiString;
1670 begin
1671 if TryInside then
1672 result:='raise EExitFor.create;'
1673 else
1674 result:='goto '+(TStatement(Statement) as TForStructure).MakeLabel +';'
1675 end;
1676
1677 function TExitFor1.Code:AnsiString;
1678 begin
1679 //if TryInside then
1680 result:='raise EExitFor.create;'
1681 //else
1682 // result:='goto '+(TStatement(Statement) as TForStructure).MakeLabel +';'
1683 end;
1684
1685 function TSelect.BlockCode(PreLabel,AfterLabel:TStringList; HaveEXLINE:boolean):AnsiString;
1686 begin
1687 result:=CaseBlock.GenCode(PreLabel,AfterLabel,HaveEXLINE);
1688 result:= own.Code + ' := ' + exp.Code +' ;' +EOL
1689 + result;
1690 end;
1691
1692 function TCause.Code:Ansistring;
1693 begin
1694 result:= ' raise EExtype.create('+ strint(typ) +');' ;
1695 end;
1696
1697 function TCauseException.Code:Ansistring;
1698 begin
1699 result:= ' raise EExtype.create('+ exp.Code +');' ;
1700 end;
1701
1702 function TEXITHandlerU.Code:Ansistring;
1703 begin
1704 result:=' ExCode:=ExCodeRec; raise;'
1705 end;
1706
1707 function TEXITHandlerH.Code:Ansistring;
1708 begin
1709 result:=' ExCode:=ExCodeRec; raise E;'
1710 end;
1711
1712 function TOn.code:ansistring;
1713 var
1714 i:integer;
1715 begin
1716 if Gosub then
1717 raise ECodeNotYet.create(self)
1718 else
1719 begin
1720 result:='case System.Round('+ exp.code+') of'+EOL;
1721 for i:=1 to list.count do
1722 result:=result
1723 +inttostr(i)+':'+(TObject(list.items[i-1]) as TGOTO).code+EOL;
1724 if elsest<>nil then
1725 result:=result+elsest.code+EOL;
1726 result:=result+'end;'
1727 end;
1728 end;
1729
1730
1731 function TGoSub.code:ansistring;
1732 begin
1733 result:='GosubStack.push('+ IntToStr(Next.LabelNumb)+'); goto '+IntToStr(Numb)+';'+EOL;
1734 proc.LabelsList.add(Inttostr(Numb));
1735 end;
1736
1737 function TReturn.Code:ansistring;
1738 var
1739 i:integer;
1740 List:TStringList;
1741 begin
1742 if WhenBlock=nil then
1743 List:=Proc.ReturnLables
1744 else
1745 List:=WhenBlock.ReturnLables;
1746 result:='case GosubStack.pop of'+EOL;
1747 with List do
1748 for i:=0 to count -1 do
1749 result:=result
1750 + Strings[i]+': goto '+Strings[i]+';'+EOL;
1751 result:=result
1752 +'end;'
1753 end;
1754
1755
1756 function TRetry.Code:ansistring;
1757 begin
1758 result:='Retry:=ExLineNumb;'+EOL ;
1759 if WhenBlock0=nil then //in Handler
1760 result:=result
1761 +'Exit;'
1762 else
1763 result:=result
1764 +'goto h'+IntToStr(WhenBlock0.UseBlock.LineNumb)+';'
1765 end;
1766
1767 function TContinue.Code:ansistring;
1768 begin
1769 result:='Continue:=ExLineNumb;'+EOL;
1770 if WhenBlock0=nil then //in Handler
1771 result:=result
1772 +'Exit;'
1773 else
1774 result:=result
1775 +'goto h'+IntToStr(WhenBlock0.UseBlock.LineNumb)+';'
1776 end;
1777
1778
1779
1780 {**********}
1781 {initialize}
1782 {**********}
1783 procedure statementTableinit;far;
1784 begin
1785 statementTableinitStructural('FOR',FORst);
1786 statementTableinitTerminal ('NEXT',NEXTst);
1787 statementTableinitStructural('DO',DOst);
1788 statementTableinitStructural('WHILE',WHILEst);
1789 statementTableinitTerminal ('LOOP',LOOPst);
1790 //statementTableinitTerminal ('WEND',WENDst);
1791 statementTableinitStructural('IF',IFst);
1792 statementTableinitTerminal ('ELSE',ELSEst);
1793 statementTableinitTerminal ('ELSEIF',ELSEst);
1794 statementTableinitStructural('SELECT',SELECTst);
1795 statementTableinitTerminal ('CASE',ELSEst);
1796 statementTableinitImperative('EXIT',EXITst);
1797 statementTableinitImperative('CALL',CALLst);
1798 statementTableinitImperative('STOP',STOPst);
1799 statementTableinitImperative('RETRY',RETRYst);
1800 statementTableinitImperative('CONTINUE',CONTINUEst);
1801 statementTableinitImperative('GOTO',GOTOst);
1802 statementTableinitImperative('GO',GOst);
1803 statementTableinitImperative('GOSUB',GOSUBst);
1804 statementTableinitImperative('RETURN',RETURNst);
1805 statementTableinitImperative('CAUSE',CauseExceptionst);
1806 statementTableinitImperative('ON',ONst);
1807 StatementTableInitImperative('RANDOMIZE',RANDOMIZEst);
1808
1809 SeqCounter:=0;
1810 end;
1811
1812
1813 begin
1814 tableInitProcs.accept(statementTableinit);
1815 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26