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

end;

PostLabel(L2); MatchString(ENDIF); end;

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

L1 := NewLabel;

L2 := NewLabel;

PostLabel(L1);

BoolExpression;

BranchFalse(L2);

Block;

MatchString(ENDWHILE); Branch(L1); PostLabel(L2); end;

{ Process a Read Statement }

procedure DoRead;

begin

MatchCC);

GetName;

ReadVar;

while Look = , do begin

MatchC,);

GetName;

ReadVar; end;

Match()); end;

{ Process a Write Statement }

procedure DoWrite;

begin

MatchCC);

Expression;

WriteVar;

while Look = , do begin

MatchC,);

Expression;

WriteVar; end;

Match()); end;

{ Parse and Translate a Block of Statements } procedure Block; begin Scan;

while not(Token in [e, l]) do begin case Token of i: DoIf; w: DoWhile;



R: DoRead; W: DoWrite;

else Assignment; end; Scan; end; end;

{ Allocate Storage for a Variable } procedure Alloc(N: Symbol); begin

if InTable(N) then Abort(Duplicate Variable Name + N); AddEntry(N, v); Write(N, TAB, DC );

if Look = = then begin Match(=);

If Look = - then begin

Write(Look);

MatchC-); end;

WriteLn(GetNum); end else

WriteLn(0);

end;

{ Parse and Translate a Data Declaration }

procedure Decl;

begin

GetName;

Alloc(Value);

while Look = , do begin

MatchC,);

GetName;

Alloc(Value); end; end;

{ Parse and Translate Global Declarations } procedure TopDecls; begin Scan;

while Token <> b do begin case Token of v: Decl;

else Abort(Unrecognized Keyword + Value); end; Scan; end; end;

{ Parse and Translate a Main Program }

procedure Main;

begin

MatchString(BEGIN); Prolog;



Block;

MatchString(END); Epilog; end;

{ Parse and Translate a Program }

procedure Prog;

begin

MatchString(PROGRAM);

Header;

TopDecls;

Main;

Match(.); end;

{ Initialize } procedure Init; var i: integer; begin

for i := 1 to MaxEntry do begin

ST[i] := ; SType[i] := ;

end;

GetChar; Scan; end;

{ Main Program } begin

Init;

Prog;

if Look <> CR then Abort(Unexpected data after .); 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