Анимация
JavaScript
|
Главная Библионтека procedure Expected(s: string); begin Abort(s + Expected); end; { Report an Undefined Identifier } procedure Undefined(n: string); begin Abort(Undefined Identifier + n); end; { Report a Duplicate Identifier } procedure Duplicate(n: string); begin Abort(Duplicate Identifier + n); end; { Check to Make Sure the Current Token is an Identifier } procedure CheckIdent; begin if Token <> x then Expected(Identifier); end; { Recognize an Alpha Character } function IsAlpha(c: char): boolean; begin IsAlpha := UpCase(c) in [A..Z]; end; { Recognize a Decimal Digit } 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 a Boolean Orop } function IsOrop(c: char): boolean; begin IsOrop := c in [j, -]; end; { Recognize a Relop } function IsRelop(c: char): boolean; begin IsRelop := c in [=, #, <, >]; end; { Recognize White Space } function IsWhite(c: char): boolean; begin IsWhite := c in [ , TAB, CR, LF]; end; { Skip Over Leading White Space } procedure SkipWhite; begin while IsWhite(Look) do GetChar; 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; { Locate a Symbol in Table } { Returns the index of the entry. Zero if not present. } function Locate(N: Symbol): integer; begin Locate := Lookup(®ST, n, NEntry); end; { Look for Symbol in Table } function InTable(n: Symbol): Boolean; begin InTable := Lookup(®ST, n, NEntry) <> 0; end; { Check to See if an Identifier is in the Symbol Table { Report an error if its not. } procedure CheckTable(N: Symbol); begin if not InTable(N) then Undefined(N); end; { Check the Symbol Table for a Duplicate Identifier } { Report an error if identifier is already in table. } procedure CheckDup(N: Symbol); begin if InTable(N) then Duplicate(N); end; { Add a New Entry to Symbol Table } procedure AddEntry(N: Symbol; T: char); begin CheckDup(N); if NEntry = MaxEntry then Abort(Symbol Table Full); Inc(NEntry); ST[NEntry] := N; SType[NEntry] := T; end; { Get an Identifier } procedure GetName; begin SkipWhite; if Not IsAlpha(Look) then Expected(Identifier); Token := x; Value := ; repeat Value := Value + UpCase(Look); GetChar; until not IsAlNum(Look); end; { Get a Number } procedure GetNum; begin SkipWhite; if not IsDigit(Look) then Expected(Number); Token := #; Value := ; repeat Value := Value + Look; GetChar; until not IsDigit(Look); end; { Get an Operator } procedure GetOp; begin SkipWhite; Token := Look; Value := Look; GetChar; end; { Get the Next Input Token } procedure Next; begin SkipWhite; if IsAlpha(Look) then GetName else if IsDigit(Look) then GetNum else GetOp; end; { Scan the Current Identifier for Keywords } procedure Scan; begin if Token = x then 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 |