Анимация
JavaScript


Главная  Библионтека 

0 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

{ Get a Number } function GetNum: char; begin

if not IsDigit(Look) then Expected(Integer);

GetNum := Look;

GetChar;

SkipWhite;

end;

{ Generate a Unique Label } function NewLabel: string; var S: string; begin

Str(LCount, S);

NewLabel := L + S; Inc(LCount);

end;

{ Post a Label To Output } procedure PostLabel(L: string); begin

WriteLn(L, :);

end;

{ Output a String with Tab } procedure Emit(s: string); begin

Write(TAB, s);

end;

{ Output a String with Tab and CRLF }

procedure EmitLn(s: string);

begin

Emit(s);

WriteLn;

end;

{ Parse and Translate an Identifier } procedure Ident; var Name: char; begin

Name := GetName; if Look = ( then begin MatchCC); Match());

EmitLn(BSR + Name); end else

EmitLnCMOVE + Name + (PC),D0);

end;

{ Parse and Translate a Math Factor } procedure Expression; Forward; procedure Factor; begin

if Look = ( then begin MatchCC); Expression;



Match()); end

else if IsAlpha(Look) then

Ident else

EmitLnCMOVE # + GetNum + ,D0);

end;

{ Parse and Translate the First Math Factor } procedure SignedFactor; var s: boolean; begin

s := Look =

if IsAddop(Look) then begin

GetChar;

SkipWhite; end; Factor; if s then

EmitLnCNEG D0);

end;

{ Recognize and Translate a Multiply }

procedure Multiply;

begin

MatchC*);

Factor;

EmitLn(MULS (SP)+,D0);

end;

{ Recognize and Translate a Divide }

procedure Divide;

begin

MatchC/);

Factor;

EmitLnCMOVE (SP)+,D1); EmitLn(EXS.L D0); EmitLn(DIVS D1,D0);

end;

{ Completion of Term Processing (called by Term and FirstTerm } procedure Term1; begin

while IsMulop(Look) do begin EmitLnCMOVE D0,-(SP)); case Look of

*: Multiply; /: Divide; end; end; end;

{ Parse and Translate a Math Term }

procedure Term;

begin

Factor;

Term1;



{ Parse and Translate a Math Term with Possible Leading Sign }

procedure FirstTerm;

begin

SignedFactor;

Term1;

end;

{ Recognize and Translate an Add }

procedure Add;

begin

Match(+);

Term;

EmitLnCADD (SP) + ,D0);

end;

{ Recognize and Translate a Subtract }

procedure Subtract;

begin

MatchC-);

Term;

EmitLnCSUB (SP) + ,D0); EmitLnCNEG DO);

end;

{ Parse and Translate an Expression }

procedure Expression;

begin

FirstTerm;

while IsAddop(Look) do begin EmitLnCMOVE D0,-(SP)); case Look of

+: Add;

-: Subtract;

end; end;

end;

{ Parse and Translate a Boolean Condition } { This version is a dummy }

Procedure Condition;

begin

EmitLn(Condition);

end;

{ Recognize and Translate an IF Construct } procedure Block;

Forward; procedure DoIf; var L1, L2: string; begin

MatchCi);

Condition;

L1 := NewLabel;



0 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