|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - download
Length: 10240 (0x2800) Types: Ada Source Notes: 03_class, FILE, R1k_Segment, e3_tag, package body Expression, seg_046696
└─⟦8527c1e9b⟧ Bits:30000544 8mm tape, Rational 1000, Arrival backup of disks in PAM's R1000 └─ ⟦cfc2e13cd⟧ »Space Info Vol 2« └─⟦this⟧
with Text_Io, Enumeration_Array; package body Expression is procedure Create (Item : out Object; Kind : in Operator; Left, Right : in Object; Ok : out Boolean) is begin if Is_A_Number (Left) and Is_A_Number (Right) then case Kind is when Add => Item := new Node'(Kind => Add, Left_Node => Left, Right_Node => Right); when Substract => Item := new Node'(Kind => Substract, Left_Node => Left, Right_Node => Right); when Multiply => Item := new Node'(Kind => Multiply, Left_Node => Left, Right_Node => Right); when Divide => Item := new Node'(Kind => Divide, Left_Node => Left, Right_Node => Right); end case; Ok := True; else Item := Null_Object; Ok := False; end if; end Create; procedure Create (Item : out Object; A_Number : in Integer) is begin Item := new Node'(Kind => Number, Number_Value => A_Number); end Create; procedure Create (Item : out Object; An_Attribute : in Attribute.Object) is begin Item := new Node'(Kind => Single_Attribute, The_Attribute => An_Attribute); end Create; procedure Create (Item : out Object; Enumeration, Literal : in Positive) is begin Item := new Node'(Kind => Enumerate, Enumeration_Index => Enumeration, Literal_Index => Literal); end Create; procedure Show (Item : in Object) is begin Text_Io.Put_Line ("show kind : " & Node_Kind'Image (Item.Kind)); case Item.Kind is when Add | Substract | Multiply | Divide => Show (Item.Left_Node); Text_Io.Put (" " & Operator'Image (Item.Kind) & " "); Show (Item.Right_Node); Text_Io.New_Line; when Number => Text_Io.Put (Integer'Image (Item.Number_Value)); when Single_Attribute => Text_Io.Put (Attribute.Image (Item.The_Attribute)); when Enumerate => Text_Io.Put (Enumeration_Array.Literal_Image (Item.Enumeration_Index, Item.Literal_Index)); when Unknown => Text_Io.New_Line; end case; end Show; function Evaluate (Item : in Object) return Integer is Result : Integer := 0; begin if Is_A_Number (Item) then case Item.Kind is when Add => Result := Evaluate (Item.Left_Node) + Evaluate (Item.Right_Node); when Substract => Result := Evaluate (Item.Left_Node) - Evaluate (Item.Right_Node); when Multiply => Result := Evaluate (Item.Left_Node) * Evaluate (Item.Right_Node); when Divide => Result := Evaluate (Item.Left_Node) / Evaluate (Item.Right_Node); when Number => Result := Item.Number_Value; when Single_Attribute => if Attribute.Is_A_Number (Item.The_Attribute) then Result := Attribute.Number (Item.The_Attribute); else raise Numeric_Error; end if; when others => raise Numeric_Error; end case; return Result; else raise Numeric_Error; -- a voir !! end if; exception when Numeric_Error => return 0; end Evaluate; function Kind (Item : in Object) return Node_Kind is A_Kind : Node_Kind; begin if Item.Kind in Operator then A_Kind := Kind (Item.Left_Node); elsif Item.Kind = Single_Attribute then if Attribute.Is_A_Number (Item.The_Attribute) then A_Kind := Number; elsif Attribute.Is_An_Enumerate (Item.The_Attribute) then A_Kind := Enumerate; else A_Kind := Unknown; end if; else A_Kind := Item.Kind; end if; return A_Kind; end Kind; function Is_A_Number (Item : in Object) return Boolean is begin return Kind (Item) = Number; end Is_A_Number; function Is_An_Enumerate (Item : in Object) return Boolean is begin return Kind (Item) = Enumerate; end Is_An_Enumerate; function Enumeration (Item : in Object) return Natural is Index : Natural; begin if Item.Kind = Enumerate then Index := Item.Enumeration_Index; elsif Item.Kind = Single_Attribute and then Attribute.Is_An_Enumerate (Item.The_Attribute) then Index := Attribute.Enumeration (Item.The_Attribute); else Index := 0; end if; return Index; end Enumeration; function Literal (Item : in Object) return Natural is Index : Natural; begin if Item.Kind = Enumerate then Index := Item.Literal_Index; elsif Item.Kind = Single_Attribute and then Attribute.Is_An_Enumerate (Item.The_Attribute) then Index := Attribute.Literal (Item.The_Attribute); else Index := 0; end if; return Index; end Literal; end Expression;
nblk1=9 nid=0 hdr6=12 [0x00] rec0=19 rec1=00 rec2=01 rec3=03a [0x01] rec0=1e rec1=00 rec2=02 rec3=06c [0x02] rec0=03 rec1=00 rec2=06 rec3=00c [0x03] rec0=1b rec1=00 rec2=03 rec3=01e [0x04] rec0=14 rec1=00 rec2=05 rec3=03a [0x05] rec0=02 rec1=00 rec2=07 rec3=03c [0x06] rec0=25 rec1=00 rec2=09 rec3=00a [0x07] rec0=22 rec1=00 rec2=08 rec3=058 [0x08] rec0=09 rec1=00 rec2=04 rec3=000 tail 0x21749022e865137364744 0x42a00088462060003