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

Match(l); L2 := NewLabel; EmitLn(BRA + L2); PostLabel(L1); Block(L); end;

Match(e); PostLabel(L2);

end;

{ Parse and Translate a WHILE Statement } procedure DoWhile; var L1, L2: string; begin

Match(w);

L1 := NewLabel;

L2 := NewLabel;

PostLabel(L1);

Condition;

EmitLn(BEQ + L2); Block(L2); Match(e); EmitLn(BRA + L1); PostLabel(L2); end;

{ Parse and Translate a LOOP Statement } procedure DoLoop; var L1, L2: string; begin

Match(p);

L1 := NewLabel;

L2 := NewLabel;

PostLabel(L1);

Block(L2);

Match(e);

EmitLn(BRA + L1);

PostLabel(L2); end;

{ Parse and Translate a REPEAT Statement } procedure DoRepeat; var L1, L2: string; begin

Match(r);

L1 := NewLabel;

L2 := NewLabel;

PostLabel(L1);

Block(L2);

Match(u);

Condition;

EmitLn(BEQ + L1); PostLabel(L2); end;



{ Parse and Translate a FOR Statement } procedure DoFor; var L1, L2: string;

Name: char; begin

Match(f);

L1 := NewLabel; L2 := NewLabel;

Name := GetName;

Match(=);

Expression;

EmitLnCSUBQ #1,D0);

EmitLnCLEA + Name + (PC),A0);

EmitLnCMOVE D0,(A0));

Expression;

EmitLnCMOVE D0,-(SP));

PostLabel(L1);

EmitLnCLEA + Name + (PC),A0); EmitLnCMOVE (A0),D0); EmitLnCADDQ #1,D0); EmitLnCMOVE D0,(A0)); EmitLnCCMP (SP),D0); EmitLnCBGT + L2);

Block(L2);

MatchCe); EmitLnCBRA + L1);

PostLabel(L2);

EmitLnCADDQ #2,SP); end;

{ Parse and Translate a DO Statement } procedure Dodo; var L1, L2: string; begin

Match(d);

L1 := NewLabel; L2 := NewLabel; Expression; EmitLnCSUBQ #1,D0);

PostLabel(L1);

EmitLnCMOVE D0,-(SP));

Block(L2);

EmitLnCMOVE (SP) + ,D0); EmitLnCDBRA D0, + L1); EmitLnCSUBQ #2,SP);

PostLabel(L2);

EmitLnCADDQ #2,SP); end;

{ Recognize and Translate a BREAK } procedure DoBreak(L: string); begin

Match(b);

EmitLnCBRA + L); end;



{ Recognize and Translate an "Other" } procedure Other; begin

EmitLn(GetName); end;

{ Recognize and Translate a Statement Block } procedure Block(L: string); begin

while not(Look in [e, Ч, u]) do begin case Look of

i: DoIf(L);

w: DoWhile;

p: DoLoop;

r: DoRepeat;

f: DoFor; d: DoDo; b: DoBreak(L); else Other; end; end; end;

{ Parse and Translate a Program } procedure DoProgram; begin

Block();

if Look <> e then Expected(End); EmitLn(END) end;

{ Initialize } procedure Init; begin

LCount := 0;

GetChar; end;

{ Main Program } begin Init;

DoProgram;

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