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

function IsDigit(c: char): boolean; begin

IsDigit := c in [0..9]; end;

{ Recognize an AlphaNumeric Character } function IsAlNum(c: char): boolean; begin

IsAlNum := IsAlpha(c) or IsDigit(c); end;

{ Recognize an Addop }

function IsAddop(c: char): boolean;

begin

IsAddop := c in [+, -]; end;

{ Recognize a Mulop }

function IsMulop(c: char): boolean;

begin

IsMulop := c in [*, /]; end;

{ 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 + ); GetChar; SkipWhite; end;

{ Skip a CRLF } procedure Fin; begin

if Look = CR then GetChar; if Look = LF then GetChar; SkipWhite; end;

{ Table Lookup }

function Lookup(T: TabPtr; s: string; n: integer): integer; var i: integer;

found: boolean; begin

found := false;



i := n;

while (i > 0) and not found do if s = T*[i] then

found := true else

dec(i); Lookup := i; end;

{ Get an Identifier } procedure GetName; begin

while Look = CR do Fin;

if not IsAlpha(Look) then Expected(Name); Value := ;

while IsAlNum(Look) do begin Value := Value + UpCase(Look);

GetChar; end;

SkipWhite; end;

{ Get a Number } procedure GetNum; begin

if not IsDigit(Look) then Expected(Integer); Value := ;

while IsDigit(Look) do begin Value := Value + Look;

GetChar; end;

Token := #; SkipWhite; end;

{ Get an Identifier and Scan it for Keywords }

procedure Scan;

begin

GetName;

Token := KWcode[Lookup(Addr(KWlist), Value, 4) + 1]; end;

{ Match a Specific Input String } procedure MatchString(x: string); begin

if Value <> x then Expected( + x + ); 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;

begin

GetName;

if Look = ( then begin MatchCC); MatchC));

EmitLnCBSR + Value); end else

EmitLn(MOVE + Value + (PC),D0);

end;

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

if Look = ( then begin MatchCC); Expression; MatchC)); end

else if IsAlpha(Look) then

Ident else begin

GetNum;

EmitLnCMOVE # + Value + ,D0); end; end;

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

s := Look = -; if IsAddop(Look) then begin GetChar; SkipWhite;



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