Анимация
JavaScript
|
Главная Библионтека { Parse and Translate an Expression } procedure Expression; begin FirstTerm; while IsAddop(Look) do begin Push; case Look of +: Add; Subtract; end; end; end; { Recognize and Translate a Relational "Equals" } procedure Equal; begin Match(=); Expression; PopCompare; SetEqual; end; { Recognize and Translate a Relational "Less Than or Equal" } procedure LessOrEqual; begin Match(=); Expression; PopCompare; SetLessOrEqual; end; { Recognize and Translate a Relational "Not Equals" } procedure NotEqual; begin Match(>); Expression; PopCompare; SetNEqual; end; { Recognize and Translate a Relational "Less Than" } procedure Less; begin Match(<); case Look of =: LessOrEqual; >: NotEqual; else begin Expression; PopCompare; SetLess; end; end; end; { Recognize and Translate a Relational "Greater Than" } procedure Greater; begin Match(>); if Look = = then begin Match(=); Expression; PopCompare; SetGreaterOrEqual; end else begin Expression; PopCompare; SetGreater; end; end; { Parse and Translate a Relation } procedure Relation; begin Expression; if IsRelop(Look) then begin Push; case Look of =: Equal; <: Less; >: Greater; end; end; end; { Parse and Translate a Boolean Factor with Leading NOT } procedure NotFactor; begin if Look = ! then begin MatchC!); Relation; NotIt; end else Relation; end; { Parse and Translate a Boolean Term } procedure BoolTerm; begin NotFactor; while Look = & do begin Push; Matches); NotFactor; PopAnd; end; end; { Recognize and Translate a Boolean OR } procedure BoolOr; begin Match(l); BoolTerm; PopOr; end; { Recognize and Translate an Exclusive Or } procedure BoolXor; begin Match(~); BoolTerm; PopXor; end; { Parse and Translate a Boolean Expression } procedure BoolExpression; begin BoolTerm; while IsOrOp(Look) do begin Push; case Look of l: BoolOr; BoolXor; end; end; end; { Parse and Translate an Assignment Statement } procedure Assignment; var Name: string; begin Name := Value; Match(=); BoolExpression; Store(Name); end; { Recognize and Translate an IF Construct } procedure Block; Forward; procedure DoIf; var L1, L2: string; begin BoolExpression; L1 := NewLabel; L2 := L1; BranchFalse(L1); Block; if Token = l then begin L2 := NewLabel; Branch(L2); PostLabel(L1); Block; 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 |