DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400 Tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400 Tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ B T

⟦8e326f704⟧ TextFile

    Length: 4303 (0x10cf)
    Types: TextFile
    Names: »B«

Derivation

└─⟦a7d1ea751⟧ Bits:30000550 8mm tape, Rational 1000, !users!projects 94_04_11
    └─ ⟦129cab021⟧ »DATA« 
        └─⟦this⟧ 

TextFile

with Message;
with Value, Block;
with Class_Integer, Class_String, Class_Block;
with Class_Printer;
with Bug_Report;
with Bounded_String;
with String_Utilities;

package body Primary is

    type Node_Structure is
        record
            Rule : Natural range 0 .. 4 := 0;
            Obj : Object.Reference := Object.Void_Reference;
            Ident : Message.Unary;
            Val : Value.Node := Value.Empty_Node;
            Blk : Block.Node := Block.Get_Current_Node;
            Line : Object.Index := Scanner.Get_Line_Number;
        end record;

    procedure Parse (N : in out Node) is
        Result : Integer;
        Success : Boolean;
        use Scanner;
    begin  
        N := new Node_Structure;  
        case Scanner.Get_Token is
            when Scanner.Integer =>
                N.Rule := 0;
                String_Utilities.String_To_Number
                   (Source => Bounded_String.Image (Scanner.Get_Value),
                    Worked => Success,
                    Target => Result);
                N.Obj := Class_Integer.Create (Object.Index (Result));
                Scanner.Next;
            when Scanner.String =>
                N.Rule := 1;  
                N.Obj := Class_String.Create (Scanner.Get_Value);
                Scanner.Next;
            when Scanner.Identifier =>
                N.Rule := 2;
                Message.Put (Scanner.Get_Value, N.Ident);
                Scanner.Next;
            when Scanner.Open_Parenthesis =>
                N.Rule := 3;  
                Scanner.Next;
                Value.Parse (N.Val);
                if Scanner.Get_Token = Scanner.Close_Parenthesis then
                    Scanner.Next;
                else
                    raise Bug_Report.Parenthesis_Is_Missing;
                end if;
            when Scanner.Open_Brace =>
                N.Rule := 4;
                Block.Parse (N.Blk);
                N.Obj := Class_Block.Create (Node => N.Blk);
            when others =>
                raise Bug_Report.Unexpected_Token;
        end case;
    end Parse;

    function Is_First (T : Scanner.Token) return Boolean is
        use Scanner;
    begin
        return T = Scanner.Integer or else T = Scanner.String or else
                  T = Scanner.Identifier or else
                  T = Scanner.Open_Parenthesis or else
                  T = Scanner.Open_Brace or else Block.Is_First (T);
    end Is_First;

    procedure Unparse (N : Node) is
        Result : Object.Reference := Object.Void_Reference;
        Success : Boolean;
    begin
        case N.Rule is
            when 0 =>
                Class_Printer.Put
                   (String_Utilities.Number_To_String
                       (Value => (Integer (Object.Get (Index_From => N.Obj)))));
            when 1 =>
                Class_Printer.Put
                   ('"' &
                    Bounded_String.Image
                       (Class_String.Get (Object.Get (Index_From => N.Obj))) &
                    '"');
            when 2 =>
                Class_Printer.Put (Bounded_String.Image
                                      (Message.Get (N.Ident)));
            when 3 =>
                Class_Printer.Put ("(");
                Value.Unparse (N.Val);
                Class_Printer.Put (")");
            when 4 =>
                Block.Unparse (N.Blk);
        end case;
    end Unparse;

    function Interpret (N : Node) return Object.Reference is
        Result : Object.Reference := Object.Void_Reference;
        Success : Boolean;
    begin
        Scanner.Put_Line_Number (N.Line);
        case N.Rule is
            when 0 =>
                Result := N.Obj;
            when 1 =>
                Result := N.Obj;
            when 2 =>
                Block.Get_From_Table (Object_Named => Message.Get (N.Ident),
                                      From_Block => N.Blk,
                                      Into => Result,
                                      Status => Success);
                if not Success then
                    raise Bug_Report.Undefined_Identifier;
                end if;
            when 3 =>
                Result := Value.Interpret (N.Val);
            when 4 =>
                Result := N.Obj;
        end case;
        return Result;  
    end Interpret;
end Primary;