Анимация
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

{ Recognize White Space }

function IsWhite(c: char): boolean;

begin

IsWhite := c in [ , TAB]; end;

{ Skip Over Leading White Space }

procedure SkipWhite;

begin

while IsWhite(Look) do

GetChar;

end;

{ Match a Specific Input Character }

procedure Match(x: char);

begin

if Look <> x then Expected( + x + ) else begin

GetChar;

SkipWhite; end; end;

{ Get an Identifier } function GetName: string; var Token: string; begin

Token := ;

if not IsAlpha(Look) then Expected(Name); while IsAlNum(Look) do begin

Token := Token + UpCase(Look);

GetChar; end;

GetName := Token; SkipWhite; end;

{ Get a Number } function GetNum: string; var Value: string; begin

Value := ;

if not IsDigit(Look) then Expected(Integer); while IsDigit(Look) do begin

Value := Value + Look;

GetChar; end;

GetNum := Value; SkipWhite; 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 a Identifier } procedure Ident; var Name: string[8]; begin

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

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

EmitLn(MOVE # + GetNum + ,D0);

end;

{ Recognize and Translate a Multiply }

procedure Multiply;

begin

MatchC*);

Factor;

EmitLnCMULS (SP) + ,D0); end;

{ Recognize and Translate a Divide }

procedure Divide;

begin

Match(/);

Factor;

EmitLnCMOVE (SP) + ,D1); EmitLnCEXS.L D0); EmitLnCDIVS D1,D0); end;



{ Parse and Translate a Math Term }

procedure Term;

begin

Factor;

while Look in [*, /] do begin EmitLn(MOVE D0,-(SP)); case Look of *: Multiply; /: Divide; end; end; end;

{ Recognize and Translate an Add }

procedure Add;

begin

Match(+); Term;

EmitLn(ADD (SP)+,D0); end;

{ Recognize and Translate a Subtract }

procedure Subtract;

begin

Match(-); Term;

EmitLn(SUB (SP)+,D0); EmitLn(NEG D0); end;

{ Parse and Translate an Expression }

procedure Expression;

begin

if IsAddop(Look) then

EmitLn(CLR D0)

else Term;

while IsAddop(Look) do begin

EmitLn(MOVE D0,-(SP));

case Look of

+: Add; -: Subtract; end; end; end;

{ Parse and Translate an Assignment Statement } procedure Assignment; var Name: string[8]; begin

Name := GetName;

Match(=);

Expression;

EmitLn(LEA + Name + (PC),A0); EmitLn(MOVE D0,(A0))

end;



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