-
Notifications
You must be signed in to change notification settings - Fork 5
/
BASICA.PAS
1987 lines (1907 loc) · 43.5 KB
/
BASICA.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{ @author: Sylvain Maltais ([email protected])
@created: 2022
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program BASICA;
Uses Crt,DOS,Printer;
Const
CommandList:Array[0..91]of String[12]=(
'AND','AUTO','BEEP','BLOAD','BSAVE','CALL','CAT','CHAIN','CHDIR',
'CIRCLE','CLEAR','CLOSE','CLR','CLS','COLOR','COM','COMMON','CONT',
'DATA','DEF','DELETE','DIM','DRAW','EDIT','ELSE','END','ERASE','ERROR',
'FIELD','FILES','FOR','GET','GOSUB','GOTO','HELP','IF','INPUT','KEY',
'KILL','LET','LINE','LIST','LLIST','LOAD','LOCATE','LPRINT',
'LSET','MERGE','MKDIR','NAME','NEW','NEXT','ON','OPEN','OPTION',
'OR','OUT','PAINT','PALETTE','POKE','PLAY','PRESET','PRINT',
'PSET','PUT','RANDOMIZE','READ','REM','RENUM','RESET','RESUME',
'RESTORE','RETURN','RMDIR','RSET','RUN','SAVE','SCREEN','SHELL','SLEEP',
'STOP','SYSTEM','THEN','TROFF','TRON','VIEW','WAIT','WEND','WHILE',
'WIDTH','WINDOW','WRITE'
);
FunctionList:Array[0..53]of String[12]=(
'ABS','ASC','ATN','CHR$','CINT','CSNG','CSRLIN','COS','CVD','CVI',
'CVS','DATE$','EOF','ERL','ERR','EXP','FIX','FRE','INKEY$','INP',
'INPUT$','INSTR','INT','LEFT$','LEN','LOF','LOG','LPOS','LTRIM$',
'MID$','OCT$','PEEK','PLAY','PMAP','POS','RIGHT$','RND','RTRIM$',
'SCREEN','SGN','SIN','SQR','STR$','STRIG','STRING$','TAN','TAB',
'TIME$','TIMER','TRIM$','USR','VAL','VARPTR','VARPTR$'
);
MaxLine=1024;
MaxVariable=100;
Type
VarTypeEnum=(_None,_Integer,_LongInt,_Real,_String);
StrPointer=^String;
VarRec=Record
Variant:Record Case Integer of
0:(I:Integer);
1:(L:LongInt);
2:(R:Real);
3:(S:StrPointer);
End;
VarType:VarTypeEnum;
VarName:String[20];
End;
VarPointer=^VarRec;
GosubStackRec=Record
Line,Col:Word;
LineNumber:Integer;
End;
ForStackRec=Record
Line,Col:Word;
LineNumber:Integer;
VarName:String[20];
End;
Var
Terminated,Tron,KeyFunction:Boolean;
CurrCommand:String;
FileName,CurrLine:String;
CurrPos:Byte;
PA:Array[1..MaxLine] of StrPointer;
CurrLinePtr,NumberLine:Integer;
CurrNumberLine:Integer;
VarList:Array[1..MaxVariable]of VarPointer;
I,NumberVariable:Integer;
FunctionKeyList:Array[1..10]of String[15];
GosubStack:Array[1..10]of GosubStackRec;
GosubPos:Byte;
ForStack:Array[1..10]of ForStackRec;
ForPos:Byte;
Function RunBasic(InList:Boolean):Boolean;Forward;
Procedure NewCommand;Forward;
Function TAN(X:Real):Real;Begin
If Cos(X)=0.0Then Tan:=0.0
Else Tan:=SIN(X)/COS(X);
End;
Function LTrim(S:String):String;
Var
I:Integer;
Begin
I:=1;
While(I<=Length(s)) and (S[I] in [#9,' ']) do Inc(I);
Delete(S,1,I-1);
LTrim:=S;
End;
Function PadRight(S:String;Space:Byte):String;
Var
I:Byte;
Begin
If Length(S)<Space Then For I:=Length(S)+1 to Space do S:=S+' ';
PadRight:=S;
End;
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Function GetCurrentDisk:Char;
Var
CurrentDir:String;
Begin
GetDir(0,CurrentDir);
GetCurrentDisk:=CurrentDir[1];
End;
Function GetErrorMessage(Code:Word):String;Begin
Case Code of
0:GetErrorMessage:='';
2:GetErrorMessage:='Fichier introuvable';
3:GetErrorMessage:='Chemin introuvable';
4:GetErrorMessage:='Trop de fichiers ouvert';
5:GetErrorMessage:='Acces refuse';
6:GetErrorMessage:='Handle de fichier invalide';
12:GetErrorMessage:='Mode d''acces sur disque invalide';
15:GetErrorMessage:='Num‚ro de disque invalide';
16:GetErrorMessage:='Impossible de supprimer le r‚pertoire';
17:GetErrorMessage:='Impossible de renommer sur plusieurs volumes';
100:GetErrorMessage:='Erreur de lecture … partir du disque';
101:GetErrorMessage:='Erreur d''ecriture sur le disque';
102:GetErrorMessage:='Fichier non attribue';
103:GetErrorMessage:='Le fichier n''est pas ouvert';
104:GetErrorMessage:='Le fichier n''est pas ouvert … l''entree';
105:GetErrorMessage:='Le fichier n''est pas ouvert … la sortie';
106:GetErrorMessage:='Numero invalide';
150:GetErrorMessage:='Disque protege en ecriture';
151:GetErrorMessage:='Peripherique est inconnu';
152:GetErrorMessage:='Disque pas pret';
153:GetErrorMessage:='Commande inconnue';
154:GetErrorMessage:='Echec de verification CRC';
155:GetErrorMessage:='Disque invalide';
156:GetErrorMessage:='Erreur de recherche sur disque';
157:GetErrorMessage:='Type de media invalide';
158:GetErrorMessage:='Secteur introuvable';
159:GetErrorMessage:='L''imprimante n''a plus de papier';
160:GetErrorMessage:='Erreur d''ecriture sur le peripherique';
161:GetErrorMessage:='Erreur de lecture sur le peripherique';
162:GetErrorMessage:='Defaillance materielle';
Else GetErrorMessage:='Erreur inconnue';
End;
End;
Procedure ShowFunctionKey;
Var
I,J,OldY:Byte;
Temp:String;
Begin
OldY:=WhereY;
Window(1,1,80,25);
GotoXY(1,25);
ClrEol;
If(KeyFunction)Then Begin
For I:=1 to 10 do Begin
TextColor(7);
TextBackground(0);
Write(I mod 10);
TextColor(0);
TextBackground(7);
Temp:='';
For J:=1 to Length(FunctionKeyList[I])do Begin
If FunctionKeyList[I][J]<>#13Then Temp:=Temp+FunctionKeyList[I][J];
End;
Write(Temp);
TextColor(7);
TextBackground(0);
If I<10 Then Begin
If Length(Temp)<7 Then Write(' ':7-Length(Temp));
End;
End;
End;
Window(1,1,80,24);
GotoXY(1,OldY);
End;
Procedure HomeMessage;Begin
ClrScr;
ShowFunctionKey;
Window(1,1,80,24);
WriteLn('BASICA 2022');
WriteLn('Tous droits reserves Gladir.com 2021, 2022');
End;
Function ExtractCommand:Byte;
Var
I:Byte;
Begin
ExtractCommand:=255;
CurrCommand:='';
For I:=CurrPos to Length(CurrLine)do Begin
If Not(CurrLine[I]in['A'..'Z','a'..'z','$','%','!','#'])Then Begin
CurrCommand:=StrToUpper(Copy(CurrLine,CurrPos,I-CurrPos));
CurrPos:=I;
Break;
End;
End;
If CurrCommand=''Then Begin
CurrCommand:=StrToUpper(Copy(CurrLine,CurrPos,255));
CurrPos:=Length(CurrLine)+1;
End;
For I:=Low(CommandList)to High(CommandList)do Begin
If CurrCommand=CommandList[I]Then Begin
ExtractCommand:=I;
Exit;
End;
End;
End;
{ Traitement des variables }
Function VariableExist(S:String):Boolean;
Var
I:Integer;
Begin
VariableExist:=False;
For I:=1 to NumberVariable do If(StrToUpper(S)=VarList[I]^.VarName)Then Begin
VariableExist:=True;
Exit;
End;
End;
Function VariableType(S:String):VarTypeEnum;
Var
I:Integer;
Begin
VariableType:=_None;
For I:=1 to NumberVariable do If(StrToUpper(S)=VarList[I]^.VarName)Then Begin
VariableType:=VarList[I]^.VarType;
Exit;
End;
End;
Function AddVariableInt(S:String;Value:Integer):Boolean;
Var
P:VarPointer;
Begin
If NumberVariable>=MaxVariable Then Begin
AddVariableInt:=False;
Exit;
End;
Inc(NumberVariable);
GetMem(P,SizeOf(VarRec));
P^.VarName:=Copy(StrToUpper(S),1,20);
P^.VarType:=_Integer;
P^.Variant.I:=Value;
VarList[NumberVariable]:=P;
AddVariableInt:=True;
End;
Function GetVariableInt(S:String):Integer;
Var
I:Integer;
Begin
GetVariableInt:=0;
For I:=1 to NumberVariable do If(StrToUpper(S)=VarList[I]^.VarName)Then Begin
GetVariableInt:=VarList[I]^.Variant.I;
Exit;
End;
End;
Procedure SetVariableInt(S:String;Value:Integer);
Var
I:Integer;
Begin
For I:=1 to NumberVariable do If(S=VarList[I]^.VarName)Then Begin
VarList[I]^.Variant.I:=Value;
Exit;
End;
End;
Function AddVariableLongInt(S:String;Value:LongInt):Boolean;
Var
P:VarPointer;
Begin
If NumberVariable>=MaxVariable Then Begin
AddVariableLongInt:=False;
Exit;
End;
Inc(NumberVariable);
GetMem(P,SizeOf(VarRec));
P^.VarName:=Copy(StrToUpper(S),1,20);
P^.VarType:=_LongInt;
P^.Variant.L:=Value;
VarList[NumberVariable]:=P;
AddVariableLongInt:=True;
End;
Function GetVariableLongInt(S:String):LongInt;
Var
I:Integer;
Begin
GetVariableLongInt:=0;
For I:=1 to NumberVariable do If(StrToUpper(S)=VarList[I]^.VarName)Then Begin
GetVariableLongInt:=VarList[I]^.Variant.L;
Exit;
End;
End;
Procedure SetVariableLongInt(S:String;Value:LongInt);
Var
I:Integer;
Begin
For I:=1 to NumberVariable do If(S=VarList[I]^.VarName)Then Begin
VarList[I]^.Variant.L:=Value;
Exit;
End;
End;
Function AddVariableReal(S:String;Value:Real):Boolean;
Var
P:VarPointer;
Begin
If NumberVariable>=MaxVariable Then Begin
AddVariableReal:=False;
Exit;
End;
Inc(NumberVariable);
GetMem(P,SizeOf(VarRec));
P^.VarName:=Copy(StrToUpper(S),1,20);
P^.VarType:=_Real;
P^.Variant.R:=Value;
VarList[NumberVariable]:=P;
AddVariableReal:=True;
End;
Function GetVariableReal(S:String):Real;
Var
I:Integer;
Begin
GetVariableReal:=0;
For I:=1 to NumberVariable do If(StrToUpper(S)=VarList[I]^.VarName)Then Begin
GetVariableReal:=VarList[I]^.Variant.R;
Exit;
End;
End;
Procedure SetVariableReal(S:String;Value:Real);
Var
I:Integer;
Begin
For I:=1 to NumberVariable do If(S=VarList[I]^.VarName)Then Begin
VarList[I]^.Variant.R:=Value;
Exit;
End;
End;
Function AddVariableString(S:String;Value:String):Boolean;
Var
P:VarPointer;
PS:StrPointer;
Begin
If NumberVariable>=MaxVariable Then Begin
AddVariableString:=False;
Exit;
End;
Inc(NumberVariable);
GetMem(P,SizeOf(VarRec));
P^.VarName:=Copy(StrToUpper(S),1,20);
P^.VarType:=_String;
GetMem(PS,SizeOf(String));
PS^:=Value;
P^.Variant.S:=PS;
VarList[NumberVariable]:=P;
AddVariableString:=True;
End;
Function GetVariableString(S:String):String;
Var
I:Integer;
Begin
GetVariableString:='';
For I:=1 to NumberVariable do If(StrToUpper(S)=VarList[I]^.VarName)Then Begin
GetVariableString:=VarList[I]^.Variant.S^;
Exit;
End;
End;
Procedure SetVariableString(S:String;Value:String);
Var
I:Integer;
Begin
For I:=1 to NumberVariable do If(S=VarList[I]^.VarName)Then Begin
VarList[I]^.Variant.S^:=Value;
Exit;
End;
End;
{ Traitement de la liste }
Function AddLine(S:String):Boolean;
Var
P:StrPointer;
Begin
If NumberLine>=MaxLine Then Begin
AddLine:=False;
Exit;
End;
Inc(NumberLine);
GetMem(P,Length(S)+1);
P^:=S;
PA[NumberLine]:=P;
AddLine:=True;
End;
Function FirstNumberInStr(S:String):Integer;
Var
J,Number,Err:Integer;
Begin
FirstNumberInStr:=0;
J:=1;
While(J<Length(S))do Begin
If Not(S[J]in['0'..'9'])Then Begin
Val(Copy(S,1,J-1),Number,Err);
FirstNumberInStr:=Number;
Break;
End;
Inc(J);
End;
End;
Procedure QuickSort(Left,Right:Word);
Var
Lower,Upper,Middle:Word;
Pivot,T:String;
Temp:StrPointer;
Begin
Lower:=Left;
Upper:=Right;
Middle:=(Left+Right) shr 1;
Pivot:=PA[Middle]^;
Repeat
While FirstNumberInStr(PA[Lower]^) < FirstNumberInStr(Pivot) do Inc(Lower);
While FirstNumberInStr(Pivot) < FirstNumberInStr(PA[Upper]^) do Dec(Upper);
If(Lower<=Upper)Then Begin
Temp:=PA[Lower];
PA[Lower]:=PA[Upper];
PA[Upper]:=Temp;
Inc(Lower);
Dec(Upper);
End;
Until Lower>Upper;
If Left<Upper Then QuickSort(Left,Upper);
If Lower<Right Then QuickSort(Lower,Right);
End;
Procedure ResortList;Begin
If NumberLine>1 Then QuickSort(1,NumberLine);
End;
{ Evaluation d'expression (Infix to PostFix ) }
Var
Stack:Array[0..100]of Char;
TopOfStack:Byte;
resultStack:Array[0..100]of Real;
TopOfStackInt:Byte;
Procedure StackPushChar(C:Char);Begin
If TopOfStack>=High(Stack)Then Begin
WriteLn('Pile pleine!');
Halt;
End
Else
Begin
Stack[TopOfStack]:=C;
Inc(TopOfStack);
End;
End;
Function StackPop:String;
Var
S:String;
Err:Word;
Begin
Dec(TopOfStack);
If TopOfStack<1Then Begin
StackPop:='';
WriteLn('Pile vide');
Halt;
End
Else
StackPop:=Stack[TopOfStack];
End;
Function StackPeek:Char;Begin
StackPeek:=Stack[TopOfStack-1];
End;
Procedure ResultStackPush(C:Real);Begin
If TopOfStackInt>=High(ResultStack)Then Begin
WriteLn('Pile pleine!');
Halt;
End
Else
Begin
ResultStack[TopOfStackInt]:=C;
Inc(TopOfStackInt);
End;
End;
Function ResultStackPop:Real;Begin
Dec(TopOfStackInt);
If TopOfStackInt<1Then Begin
ResultStackPop:=-1.0;
WriteLn('Pile vide');
Exit;
End
Else
ResultStackPop:=ResultStack[TopOfStackInt];
End;
Procedure SkipSpace;Begin
While(CurrLine[CurrPos]in[' '])and(CurrPos<Length(CurrLine))do Inc(CurrPos);
End;
Function GetSeparator:Char;Begin
If CurrPos>Length(CurrLine)Then Begin
GetSeparator:=#0;
Exit;
End;
SkipSpace;
GetSeparator:=CurrLine[CurrPos];
End;
Function IsStringValue:Boolean;
Var
I:Byte;
Begin
IsStringValue:=False;
If CurrLine[CurrPos]='"'Then Begin
IsStringValue:=True;
End
Else
Begin
I:=CurrPos;
While(CurrLine[I]in[' '])and(I<Length(CurrLine))do Inc(I);
If CurrLine[I]in['A'..'Z','a'..'z']Then Begin
Inc(I);
While I<Length(CurrLine)do Begin
If Not(CurrLine[I]in['A'..'Z','a'..'z','0'..'9'])Then Break;
Inc(I);
End;
If(I<=Length(CurrLine))and(CurrLine[I]='$')Then IsStringValue:=True;
End;
End;
End;
Function GetVariableName:String;
Var
S:String;
Begin
S:='';
If CurrLine[CurrPos]in['A'..'Z','a'..'z']Then Begin
S:=S+CurrLine[CurrPos];
Inc(CurrPos);
While CurrPos<Length(CurrLine)do Begin
If Not(CurrLine[CurrPos]in['A'..'Z','a'..'z','0'..'9'])Then Break;
S:=S+CurrLine[CurrPos];
Inc(CurrPos);
End;
End;
GetVariableName:=StrToUpper(S);
End;
Function ReadWord:String;
Var
S:String;
Begin
S:='';
If CurrLine[CurrPos]in['A'..'Z','a'..'z']Then Begin
S:=S+CurrLine[CurrPos];
Inc(CurrPos);
While CurrPos<Length(CurrLine)do Begin
If Not(CurrLine[CurrPos]in['A'..'Z','a'..'z','0'..'9'])Then Break;
S:=S+CurrLine[CurrPos];
Inc(CurrPos);
End;
End;
ReadWord:=StrToUpper(S);
End;
Function ReadWordString:String;
Var
S:String;
Begin
S:='';
If CurrLine[CurrPos]in['A'..'Z','a'..'z']Then Begin
S:=S+CurrLine[CurrPos];
Inc(CurrPos);
While CurrPos<Length(CurrLine)do Begin
If Not(CurrLine[CurrPos]in['A'..'Z','a'..'z','0'..'9'])Then Break;
S:=S+CurrLine[CurrPos];
Inc(CurrPos);
End;
If CurrLine[CurrPos]='$'Then Begin
S:=S+'$';
Inc(CurrPos);
End;
End;
ReadWordString:=StrToUpper(S);
End;
Function GetNumberValue(MinTopOfStack:Integer):Real;Forward;
Function GetStringValue:String;
Label Restart;
Var
J:Integer;
_Result:Real;
FunctionFound:Boolean;
S,VarName:String;
Begin
GetStringValue:='';
S:='';
Restart:
If CurrLine[CurrPos]='"'Then Begin
Inc(CurrPos);
While(CurrLine[CurrPos]<>'"')and(CurrPos<=Length(CurrLine))do Begin
S:=S+CurrLine[CurrPos];
Inc(CurrPos);
End;
If CurrLine[CurrPos]='"'Then Inc(CurrPos);
End
Else
Begin
VarName:=ReadWordString;
SkipSpace;
FunctionFound:=False;
For J:=Low(FunctionList)to High(FunctionList)do Begin
If FunctionList[J]=VarName Then Begin
FunctionFound:=True;
Case J of
3:Begin{CHR$}
If CurrLine[CurrPos]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(CurrPos);
_Result:=GetNumberValue(1);
If CurrLine[CurrPos]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(CurrPos);
S:=S+Chr(Byte(Trunc(_Result)));
GetStringValue:=S;
Break;
End;
Else Begin
WriteLn('Type incompatible');
Exit;
End;
End;
End;
End;
If Not(FunctionFound)Then Begin
If VariableExist(VarName)Then Begin
S:=S+GetVariableString(VarName);
End;
End;
End;
SkipSpace;
If CurrLine[CurrPos]in['+',';']Then Begin
Inc(CurrPos);
Goto Restart;
End;
GetStringValue:=S;
End;
Function GetNumberValue(MinTopOfStack:Integer):Real;
Var
I,J:Byte;
Top,P_2:Char;
AppendOk,FunctionFound:Boolean;
_Result,P,P2:Real;
Err:Word;
PostFix:String;
VarName,Value:String;
Exposant:Boolean;
StopChar:Set Of Char;
Infix:String;
Begin
StopChar:=[',',':',';','"','<','=','>'];
TopOfStack:=1;
TopOfStackInt:=1;
PostFix:='';
Infix:=CurrLine;
I:=CurrPos;
If Infix[CurrPos]='-'Then Begin
Insert('(0)',Infix,CurrPos);
Dec(CurrPos,3);
End;
Repeat
If(I<=Length(Infix))and(Infix[I]in['A'..'Z','a'..'z'])Then Begin
VarName:=Infix[I];
Inc(I);
While(I<=Length(Infix))and(Infix[I]in['A'..'Z','a'..'z','%','!','#'])do Begin
VarName:=VarName+Infix[I];
Inc(I);
End;
VarName:=StrToUpper(VarName);
If VariableExist(VarName)Then Begin
Case VariableType(VarName)of
_Integer:Str(GetVariableInt(VarName),Value);
_LongInt:Str(GetVariableLongInt(VarName),Value);
_Real:Str(GetVariableReal(VarName),Value);
Else Begin
WriteLn('Type incompatiable');
Exit;
End;
End;
End
Else
Begin { Fonction ?}
FunctionFound:=False;
For J:=Low(FunctionList)to High(FunctionList)do Begin
If FunctionList[J]=VarName Then Begin
FunctionFound:=True;
Case J of
0:Begin{ABS}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=GetNumberValue(TopOfStack);
If Frac(_Result)=0.0 Then Str(Trunc(_Result),Value)
Else Str(_Result,Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
1:Begin{ASC}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
Value:=GetStringValue;
If Length(Value)=0Then _Result:=0.0
Else _Result:=Ord(Value[1]);
Str(_Result:0:0,Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
2:Begin{ATN}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=GetNumberValue(TopOfStack);
Str(ArcTan(_Result),Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
3:Begin{CHR$}
WriteLn('Type incompatible');
Exit;
End;
4:Begin{CINT}
End;
5:Begin{CSNG}
End;
6:Begin{CSRLIN}
Str(WhereY,Value);
End;
7:Begin{COS}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=GetNumberValue(TopOfStack);
Str(Cos(_Result),Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
8:Begin{CVD}
End;
9:Begin{CVI}
End;
10:Begin{CVS}
End;
11:Begin{DATE$}
End;
12:Begin{EOF}
End;
13:Begin{ERL}
End;
14:Begin{ERR}
End;
15:Begin{EXP}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=GetNumberValue(TopOfStack);
Str(Exp(_Result),Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
16:Begin{FIX}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=Trunc(GetNumberValue(TopOfStack));
Str(_Result:0:0,Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
17:Begin{FRE}
End;
18:Begin{INKEY$}
End;
19:Begin{INP}
End;
20:Begin{INPUT$}
End;
21:Begin{INSTR}
End;
22:Begin{INT}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=Round(GetNumberValue(TopOfStack));
Str(_Result:0:0,Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
23:Begin{LEFT$}
End;
24:Begin{LEN}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
Value:=GetStringValue;
If Length(Value)=0Then _Result:=0.0
Else _Result:=Length(Value);
Str(_Result:0:0,Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
25:Begin{LOF}
End;
26:Begin{LOG}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=GetNumberValue(TopOfStack);
Str(Ln(_Result),Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
27:Begin{LPOS}
End;
28:Begin{LTRIM$}
End;
29:Begin{MID$}
End;
30:Begin{OCT$}
End;
31:Begin{PEEK}
End;
32:Begin{PLAY}
End;
33:Begin{PMAP}
End;
34:Begin{POS}
End;
35:Begin{RIGHT$}
End;
36:Begin{RND}
End;
37:Begin{RTRIM$}
End;
38:Begin{SCREEN}
End;
39:Begin{SGN}
End;
40:Begin{SIN}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=GetNumberValue(TopOfStack);
Str(Sin(_Result),Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
41:Begin{SQR}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=GetNumberValue(TopOfStack);
Str(Sqrt(_Result),Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
42:Begin{STR$}
End;
43:Begin{STRIG}
End;
44:Begin{STRING$}
End;
45:Begin{TAN}
If Infix[I]<>'('Then Begin
WriteLn('"(" attendu');
Exit;
End;
Inc(I);
CurrPos:=I;
_Result:=GetNumberValue(TopOfStack);
Str(Tan(_Result),Value);
I:=CurrPos;
If Infix[I]<>')'Then Begin
WriteLn('")" attendu');
Exit;
End;
Inc(I);
End;
46:Begin{TAB}