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
|
{******************************************}
{ }
{ FastReport v2.3 }
{ Interpreter }
{ }
{ Copyright (c) 1998-2000 by Tzyganenko A. }
{ }
{******************************************}
unit LR_Intrp;
interface
{$I LR_Vers.inc}
uses Classes, SysUtils, LR_Pars;
type
TCharArray = array [0..31999] of Char;
PCharArray = ^TCharArray;
type
{ TfrInterpretator }
TfrInterpretator = class(TObject)
private
Buf: PCharArray;
Cur:integer;
Len: Integer;
procedure SkipSpace;
function GetToken: String;
function CopyArr(ACur, ACnt: Integer): String;
private
FParser: TfrParser;
public
constructor Create;
destructor Destroy; override;
procedure GetValue(const {%H-}Name: String; var {%H-}Value: Variant); virtual;
procedure SetValue(const {%H-}Name: String; {%H-}Value: Variant); virtual;
procedure DoFunction(const {%H-}name: String; {%H-}p1, {%H-}p2, {%H-}p3: Variant;
var {%H-}val: Variant); virtual;
//procedure PrepareScript(MemoFrom, MemoTo, MemoErr: TStringList); virtual;
procedure PrepareScript(MemoFrom, MemoTo, MemoErr: TStrings); virtual;
procedure DoScript(Memo: TStringList); virtual;
end;
TfrVariables = class(TObject)
private
FList: TFpList;
procedure SetVariable(aName: String; AValue: Variant);
function GetVariable(aName: String): Variant;
procedure SetValue(Index: Integer; AValue: Variant);
function GetValue(Index: Integer): Variant;
function GetName(Index: Integer): String;
function GetCount: Integer;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Delete(Index: Integer);
function IndexOf(aName: String): Integer;
property Variable[aName: String]: Variant
read GetVariable write SetVariable; default;
property Value[Index: Integer]: Variant read GetValue write SetValue;
property Name[Index: Integer]: String read GetName;
property Count: Integer read GetCount;
end;
implementation
uses Variants, LR_Const;
type
LRec = record
name: String[16];
n: Integer;
end;
PVariable = ^TVariable;
TVariable = record
//Name : PString;
Name : String;
Value: Variant;
end;
const
ttIf = #1;
ttGoto = #2;
ttProc = #3;
var
labels: Array[0..100] of lrec;
labc: Integer;
{------------------------------------------------------------------------------}
constructor TfrVariables.Create;
begin
inherited Create;
FList := TFpList.Create;
end;
destructor TfrVariables.Destroy;
begin
Clear;
FList.Free;
inherited Destroy;
end;
procedure TfrVariables.Clear;
begin
while FList.Count > 0 do
Delete(0);
end;
procedure TfrVariables.SetVariable(aName: String; AValue: Variant);
var
i: Integer;
p: PVariable;
begin
for i := 0 to FList.Count - 1 do
if AnsiCompareText(PVariable(FList[i])^.Name, aName) = 0 then
begin
PVariable(FList[i])^.Value := AValue;
Exit;
end;
GetMem(p, SizeOf(TVariable));
FillChar(p^, SizeOf(TVariable), 0);
p^.Name := aName; //NewStr(aName);
p^.Value := AValue;
FList.Add(p);
end;
function TfrVariables.GetVariable(aName: String): Variant;
var
i: Integer;
begin
Result := Null;
for i := 0 to FList.Count - 1 do
if AnsiCompareText(PVariable(FList[i])^.Name, aName) = 0 then
begin
Result := PVariable(FList[i])^.Value;
break;
end;
end;
procedure TfrVariables.SetValue(Index: Integer; AValue: Variant);
begin
if (Index < 0) or (Index >= FList.Count) then Exit;
PVariable(FList[Index])^.Value := AValue;
end;
function TfrVariables.GetValue(Index: Integer): Variant;
begin
Result := 0;
if (Index < 0) or (Index >= FList.Count) then Exit;
Result := PVariable(FList[Index])^.Value;
end;
function TfrVariables.IndexOf(AName: String): Integer;
var
i: Integer;
begin
Result := -1;
for i := 0 to FList.Count - 1 do
if AnsiCompareText(PVariable(FList[i])^.Name, AName) = 0 then
begin
Result := i;
break;
end;
end;
function TfrVariables.GetCount: Integer;
begin
Result := FList.Count;
end;
function TfrVariables.GetName(Index: Integer): String;
begin
Result := '';
if (Index < 0) or (Index >= FList.Count) then Exit;
Result := PVariable(FList[Index])^.Name;
end;
procedure TfrVariables.Delete(Index: Integer);
var
p: PVariable;
begin
if (Index < 0) or (Index >= FList.Count) then Exit;
p := FList[Index];
//DisposeStr(p^.Name);
p^.Name:='';
p^.Value := 0;
FreeMem(p, SizeOf(TVariable));
FList.Delete(Index);
end;
{------------------------------------------------------------------------------}
function Remain(const S: String; From: Integer): String;
begin
Result := Copy(s, From, Length(s) - 1);
end;
function GetIdentify(const s: String; var i: Integer): String;
var
k: Integer;
begin
while (i <= Length(s)) and (s[i] = ' ') do
Inc(i);
k := i;
while (i <= Length(s)) and (s[i] <> ' ') do
Inc(i);
Result := Copy(s, k, i - k);
end;
procedure TfrInterpretator.SkipSpace;
begin
while (Buf^[cur] <= ' ') and (Cur < Len) do Inc(Cur);
end;
function TfrInterpretator.GetToken: String;
var
ST, SC: Integer;
begin
if Cur<Len then
begin
repeat
SkipSpace;
ST := Cur; //Start of token
SC:=-1;
while (Buf^[Cur] > ' ') and (Cur < Len) and (SC=-1) do
begin
if Buf^[ST] <> '''' then
begin
case Buf^[Cur] of
'{':begin
//Skip {...} comment
SC := Cur; //Start of comment
while (Buf^[Cur] <> '}') and (cur < len) do Inc(cur);
Move(Buf^[Cur + 1], Buf^[SC], Len - Cur);
Dec(Len, Cur - SC + 1);
Cur := SC;
Continue;
end;
'/':if (Buf^[Cur + 1] = '/') then
begin
//Skip // comment
SC:= Cur; //Start of comment
while (Buf^[Cur] <> #13) and (Cur < Len) do Inc(Cur);
Move(Buf^[Cur + 1], Buf^[SC], Len - Cur);
Dec(Len, Cur - SC + 1);
Cur := SC;
Continue;
end;
end
end;
Inc(Cur);
end;
until (SC=-1) or (Cur>=Len);
Result := UpperCase(CopyArr(ST, Cur - ST));
end
else
Result:='';
end;
function TfrInterpretator.CopyArr(ACur, ACnt: Integer): String;
begin
SetLength(Result, ACnt);
Move(Buf^[ACur], Result[1], ACnt);
end;
{-----------------------------------------------------------------------------}
constructor TfrInterpretator.Create;
begin
inherited Create;
FParser := TfrParser.Create;
FParser.OnGetValue := @GetValue;
FParser.OnFunction := @DoFunction;
end;
destructor TfrInterpretator.Destroy;
begin
FParser.Free;
inherited Destroy;
end;
//procedure TfrInterpretator.PrepareScript(MemoFrom, MemoTo, MemoErr: TStringList);
procedure TfrInterpretator.PrepareScript(MemoFrom, MemoTo, MemoErr: TStrings);
var
i, j, lastp: Integer;
s, bs: String;
Error: Boolean;
procedure DoCommand; forward;
procedure DoBegin; forward;
procedure DoIf; forward;
procedure DoRepeat; forward;
procedure DoWhile; forward;
procedure DoGoto; forward;
procedure DoEqual; forward;
procedure DoExpression; forward;
procedure DoSExpression; forward;
procedure DoTerm; forward;
procedure DoFactor; forward;
procedure DoVariable; forward;
procedure DoConst; forward;
procedure DoLabel; forward;
procedure DoFunc; forward;
procedure DoFuncId; forward;
function last: Integer;
begin
Result := MemoTo.Count;
end;
procedure AddLabel(const s: String; n: Integer);
var
i: Integer;
f: Boolean;
begin
f := True;
for i := 0 to labc - 1 do
if labels[i].name = s then f := False;
if f then
begin
labels[labc].name := s;
labels[labc].n := n;
Inc(labc);
end;
end;
procedure AddError(const s: String);
var
i, j, c: Integer;
s1: String;
begin
Error := True;
cur := lastp;
SkipSpace;
c := 0;
for i := 0 to cur do
if buf^[i] > ' ' then Inc(c);
i := 0;
j := 1;
while (c > 0) and (i < MemoFrom.Count) do
begin
s1 := MemoFrom[i];
j := 1;
while (j <= Length(s1)) and (c > 0) do
begin
if s1[j] = '{' then break;
if s1[j] > ' ' then Dec(c);
Inc(j);
end;
if c = 0 then break;
Inc(i);
end;
MemoErr.Add(Format('%s %d/%d: %s', [sErrLine, i+1, j-1, s]));
end;
procedure ProcessBrackets(var i: Integer);
var
c: Integer;
fl1, fl2: Boolean;
begin
fl1 := True; fl2 := True; c := 0;
Dec(i);
repeat
Inc(i);
if fl1 and fl2 then
if buf^[i] = '[' then
Inc(c) else
if buf^[i] = ']' then Dec(c);
if fl1 then
if buf^[i] = '"' then fl2 := not fl2;
if fl2 then
if buf^[i] = '''' then fl1 := not fl1;
until (c = 0) or (i >= len);
end;
{----------------------------------------------}
procedure DoDigit;
begin
while (buf^[cur] = ' ') and (cur < len) do Inc(cur);
if buf^[cur] in ['0'..'9'] then
while (buf^[cur] in ['0'..'9']) and (cur < len) do Inc(cur)
else Error := True;
end;
procedure DoBegin;
label 1;
begin
1:DoCommand;
if Error then Exit;
lastp := cur;
bs := GetToken;
if (bs = '') or (bs[1] = ';') then
begin
cur := cur - Length(bs) + 1;
goto 1;
end
else
if Pos('END', bs) = 1 then
cur := cur - Length(bs) + 3
else
AddError(sErrExpectedEnd);
end;
procedure DoIf;
var
nsm, nl, nl1: Integer;
begin
nsm := cur;
DoExpression;
if Error then Exit;
bs := ttIf + ' ' + CopyArr(nsm, cur - nsm);
nl := last;
MemoTo.Add(bs);
lastp := cur;
if GetToken = 'THEN' then
begin
DoCommand;
if Error then Exit;
nsm := cur;
if GetToken = 'ELSE' then
begin
nl1 := last;
MemoTo.Add(ttGoto + ' ');
bs := MemoTo[nl]; bs[2] := Chr(last); bs[3] := Chr(last div 256); MemoTo[nl] := bs;
DoCommand;
bs := MemoTo[nl1]; bs[2] := Chr(last); bs[3] := Chr(last div 256); MemoTo[nl1] := bs;
end
else
begin
bs := MemoTo[nl]; bs[2] := Chr(last); bs[3] := Chr(last div 256); MemoTo[nl] := bs;
cur := nsm;
end;
end
else AddError(sErrExpectedThen);
end;
procedure DoRepeat;
label 1;
var
nl, nsm: Integer;
begin
nl := last;
1:DoCommand;
if Error then Exit;
lastp := cur;
bs := GetToken;
if (bs<>'') and (bs[1] = ';') then
begin
cur := cur - Length(bs) + 1;
goto 1;
end
else
if bs = 'UNTIL' then
begin
nsm := cur;
DoExpression;
MemoTo.Add(ttIf + Chr(nl) + Chr(nl div 256) + CopyArr(nsm, cur - nsm));
end
else AddError(sErrExpectedUntil);
end;
procedure DoWhile;
var
nl, nsm: Integer;
begin
nl := last;
nsm := cur;
DoExpression;
if Error then Exit;
MemoTo.Add(ttIf + ' ' + CopyArr(nsm, cur - nsm));
lastp := cur;
if GetToken = 'DO' then
begin
DoCommand;
MemoTo.Add(ttGoto + Chr(nl) + Chr(nl div 256));
bs := MemoTo[nl];
bs[2] := Chr(last);
bs[3] := Chr(last div 256);
MemoTo[nl] := bs;
end
else
AddError(sErrExpectedDO);
end;
procedure DoGoto;
var
nsm: Integer;
begin
SkipSpace;
nsm := cur;
lastp := cur;
DoDigit;
if Error then AddError(sErrLabelGoto);
MemoTo.Add(ttGoto + Trim(CopyArr(nsm, cur - nsm)));
end;
procedure DoEqual;
var
s: String;
n, nsm: Integer;
begin
nsm := cur;
DoVariable;
s := Trim(CopyArr(nsm, cur - nsm)) + ' ';
lastp := cur;
bs := GetToken;
if (bs = ';') or (bs = '') or (bs = #0) then
begin
s := Trim(CopyArr(nsm, lastp - nsm));
MemoTo.Add(ttProc + s + '(0)');
cur := lastp;
end
else
if Pos(':=', bs) = 1 then
begin
cur := cur - Length(bs) + 2;
nsm := cur;
DoExpression;
n := Pos('[', s);
if n <> 0 then
begin
s := ttProc + 'SETARRAY(' + Copy(s, 1, n - 1) + ', ' +
Copy(s, n + 1, Length(s) - n - 2) + ', ' + CopyArr(nsm, cur - nsm) + ')';
end
else
s := s + CopyArr(nsm, cur - nsm);
MemoTo.Add(s);
end
else
AddError(sErrExpectedAssign);
end;
{-------------------------------------}
procedure DoExpression;
var
nsm: Integer;
begin
DoSExpression;
nsm := cur;
bs := GetToken;
if (Pos('>=', bs) = 1) or (Pos('<=', bs) = 1) or (Pos('<>', bs) = 1) then
begin
cur := cur - Length(bs) + 2;
DoSExpression;
end
else
if (bs<>'') and ((bs[1] = '>') or (bs[1] = '<') or (bs[1] = '=')) then
begin
cur := cur - Length(bs) + 1;
DoSExpression;
end
else
cur := nsm;
end;
procedure DoSExpression;
var
nsm: Integer;
begin
DoTerm;
nsm := cur;
bs := GetToken;
if (bs<>'') and ((bs[1] = '+') or (bs[1] = '-')) then
begin
cur := cur - Length(bs) + 1;
DoSExpression;
end
else
if Pos('OR', bs) = 1 then
begin
cur := cur - Length(bs) + 2;
DoSExpression;
end
else
cur := nsm;
end;
procedure DoTerm;
var
nsm: Integer;
begin
DoFactor;
nsm := cur;
bs := GetToken;
if (bs<>'') and ((bs[1] = '*') or (bs[1] = '/')) then
begin
cur := cur - Length(bs) + 1;
DoTerm;
end
else
if (Pos('AND', bs) = 1) or (Pos('MOD', bs) = 1) then
begin
cur := cur - Length(bs) + 3;
DoTerm;
end
else
cur := nsm;
end;
procedure DoFactor;
var
nsm: Integer;
begin
nsm := cur;
bs := GetToken;
if (bs<>'') and (bs[1] = '(') then
begin
cur := cur - Length(bs) + 1;
DoExpression;
SkipSpace;
lastp := cur;
if buf^[cur] = ')' then Inc(cur)
else AddError(sErrExpectedClosingBracket1);
end
else
if (bs<>'') and (bs[1] = '[') then
begin
cur := cur - Length(bs);
ProcessBrackets(cur);
SkipSpace;
lastp := cur;
if buf^[cur] = ']' then Inc(cur)
else AddError(sErrExpectedClosingBracket2);
end
else
if (bs<>'') and ((bs[1] = '+') or (bs[1] = '-')) then
begin
cur := cur - Length(bs) + 1;
DoExpression;
end
else
if bs = 'NOT' then
begin
cur := cur - Length(bs) + 3;
DoExpression;
end
else
begin
cur := nsm;
DoVariable;
if Error then
begin
Error := False;
cur := nsm;
DoConst;
if Error then
begin
Error := False;
cur := nsm;
DoFunc;
end;
end;
end;
end;
procedure DoVariable;
begin
SkipSpace;
if (buf^[cur] in ['a'..'z', 'A'..'Z']) then
begin
Inc(cur);
while buf^[cur] in ['0'..'9', '_', '.', 'A'..'Z', 'a'..'z'] do Inc(cur);
if buf^[cur] = '(' then
Error := True
else
if buf^[cur] = '[' then
begin
Inc(cur);
DoExpression;
if buf^[cur] <> ']' then
Error := True else
Inc(cur);
end;
end
else Error := True;
end;
procedure DoConst;
label
lblLine;
begin
SkipSpace;
if buf^[cur] = #$27 then
begin
lblLine:
Inc(cur);
while (buf^[cur] <> #$27) and (cur < len) do
begin
Inc(cur);
end;
if (cur < len) and (buf^[cur + 1] = #$27) then
begin
Inc(cur);
goto lblLine;
end;
if cur = len then Error := True
else Inc(cur);
end
else
begin
DoDigit;
if buf^[cur] = '.' then
begin
Inc(cur);
DoDigit;
end;
end;
end;
procedure DoLabel;
begin
DoDigit;
if buf^[cur] = ':' then Inc(cur)
else Error := True;
end;
procedure DoFunc;
label 1;
begin
DoFuncId;
if buf^[cur] = '(' then
begin
Inc(cur);
1: DoExpression;
lastp := cur;
SkipSpace;
if buf^[cur] = ',' then
begin
Inc(cur);
goto 1;
end
else if buf^[cur] = ')' then Inc(cur)
else AddError(sErrExpectedComma);
end;
end;
procedure DoFor;
var
nsm, nl: Integer;
loopvar: String;
S:string;
begin
nsm := cur;
DoEqual;
if Error then Exit;
bs := Trim(CopyArr(nsm, cur - nsm));
loopvar := Copy(bs, 1, Pos(':=', bs) - 1);
lastp := cur;
S:=GetToken;
if S = 'TO' then
begin
nsm := cur;
DoExpression;
if Error then Exit;
nl := last;
MemoTo.Add(ttIf + ' ' + loopvar + '<=' + CopyArr(nsm, cur - nsm));
lastp := cur;
if GetToken = 'DO' then
begin
DoCommand;
if Error then Exit;
MemoTo.Add(loopvar + ' ' + loopvar + '+1');
MemoTo.Add(ttGoto + Chr(nl) + Chr(nl div 256));
bs := MemoTo[nl];
bs[2] := Chr(last);
bs[3] := Chr(last div 256);
MemoTo[nl] := bs;
end
else
AddError(sErrNeedDo);
end
else
if S = 'DOWNTO' then
begin
nsm := cur;
DoExpression;
if Error then Exit;
nl := last;
MemoTo.Add(ttIf + ' ' + loopvar + '>=' + CopyArr(nsm, cur - nsm));
lastp := cur;
if GetToken = 'DO' then
begin
DoCommand;
if Error then Exit;
MemoTo.Add(loopvar + ' ' + loopvar + '-1');
MemoTo.Add(ttGoto + Chr(nl) + Chr(nl div 256));
bs := MemoTo[nl];
bs[2] := Chr(last);
bs[3] := Chr(last div 256);
MemoTo[nl] := bs;
end
else
AddError(sErrNeedDo);
end
else
AddError(sErrNeedTo);
end;
procedure DoFuncId;
begin
SkipSpace;
if buf^[cur] in ['A'..'Z', 'a'..'z'] then
while buf^[cur] in ['0'..'9', '_', '.', 'A'..'Z', 'a'..'z'] do Inc(cur)
else Error := True;
end;
procedure DoCommand;
label 1;
var
nsm: Integer;
begin
1:Error := False;
nsm := cur;
lastp := cur;
bs := GetToken;
if bs = 'BEGIN' then DoBegin
else
if bs = 'IF' then DoIf
else
if bs = 'REPEAT' then DoRepeat
else
if bs = 'WHILE' then DoWhile
else
if bs = 'GOTO' then DoGoto
else
if bs = 'FOR' then
DoFor
else
if (bs = 'END') or (bs = 'END;') then
begin
cur := nsm;
Error := False;
end
else
begin
cur := nsm;
DoLabel;
if Error then
begin
Error := False;
cur := nsm;
DoVariable;
if not Error then
begin
cur := nsm;
DoEqual;
end
else
begin
cur := nsm;
Error := False;
DoExpression;
MemoTo.Add(ttProc + Trim(CopyArr(nsm, cur - nsm)));
end;
end
else
begin
AddLabel(Trim(CopyArr(nsm, cur - nsm)), last);
goto 1;
end;
end;
end;
begin
Error := False;
GetMem(buf, 32000);
FillChar(buf^, 32000, 0);
len := 0;
for i := 0 to MemoFrom.Count - 1 do
begin
s := ' ' + MemoFrom[i] + #13;
while Pos(#9, s) <> 0 do
s[Pos(#9, s)] := ' ';
Move(S[1], Buf^[len], Length(S));
Inc(len, Length(s));
end;
cur := 0; labc := 0;
MemoTo.Clear;
MemoErr.Clear;
if len > 0 then
DoCommand;
FreeMem(buf, 32000);
for i := 0 to MemoTo.Count - 1 do
if MemoTo[i][1] = ttGoto then
begin
s := Remain(MemoTo[i], 2) + ':';
for j := 0 to labc do
if labels[j].name = s then
begin
s := MemoTo[i]; s[2] := Chr(labels[j].n);
s[3] := Chr(labels[j].n div 256); MemoTo[i] := s;
break;
end;
end
else if MemoTo[i][1] = ttIf then
begin
s := FParser.Str2OPZ(Remain(MemoTo[i], 4));
MemoTo[i] := Copy(MemoTo[i], 1, 3) + s;
end
else if MemoTo[i][1] = ttProc then
begin
s := FParser.Str2OPZ(Remain(MemoTo[i], 2));
MemoTo[i] := Copy(MemoTo[i], 1, 1) + s;
end
else
begin
j := 1;
GetIdentify(MemoTo[i], j);
len := j;
s := FParser.Str2OPZ(Remain(MemoTo[i], j));
MemoTo[i] := Copy(MemoTo[i], 1, len) + s;
end;
end;
procedure TfrInterpretator.DoScript(Memo: TStringList);
var
i, j: Integer;
s, s1: String;
begin
i := 0;
while i < Memo.Count do
begin
s := Memo[i];
j := 1;
if s[1] = ttIf then
begin
if FParser.CalcOPZ(Remain(s, 4)) = 0 then
begin
i := Ord(s[2]) + Ord(s[3]) * 256;
continue;
end;
end
else if s[1] = ttGoto then
begin
i := Ord(s[2]) + Ord(s[3]) * 256;
continue;
end
else if s[1] = ttProc then
FParser.CalcOPZ(Remain(s, 2))
else
begin
s1 := GetIdentify(s, j);
SetValue(s1, FParser.CalcOPZ(Remain(s, j)));
end;
Inc(i);
end;
end;
procedure TfrInterpretator.GetValue(const Name: String; var Value: Variant);
begin
// abstract method
end;
procedure TfrInterpretator.SetValue(const Name: String; Value: Variant);
begin
// abstract method
end;
procedure TfrInterpretator.DoFunction(const name: String; p1, p2, p3: Variant;
var val: Variant);
begin
// abstract method
end;
end.
|