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

⟦354711e86⟧ TextFile

    Length: 17176 (0x4318)
    Types: TextFile
    Names: »B«

Derivation

└─⟦2f6cfab89⟧ Bits:30000547 8mm tape, Rational 1000, !projects 94-01-04
    └─ ⟦d65440be7⟧ »DATA« 
        └─⟦this⟧ 

TextFile

with Fichier_Io;
with Io;
with Langage;
with String_Utilities;
package body Lex is


    function Get_Token return Token is
        Car : Character;
    begin

        if Lex_Token = Special then
            Car := Bounded_String.Char_At (Lex_Value, 1);
            case Car is
                when '.' =>
                    Lex_Token := Dot;
                when '(' =>
                    Lex_Token := Open_Parenthesis;
                when ')' =>
                    Lex_Token := Close_Parenthesis;

                when '{' =>
                    Lex_Token := Open_Bracket;

                when '}' =>
                    Lex_Token := Close_Bracket;

                when others =>
                    null;
            end case;
        end if;

        return (Lex_Token);
    end Get_Token;


    function Get_Value return String is
    begin
        return (String_Utilities.Upper_Case (Bounded_String.Image (Lex_Value)));
    end Get_Value;


    function In_Reserved_Word (Lex_Value : in Bounded_String.Variable_String)
                              return Boolean is
        X : Langage.Reserved_Word;
    begin
        X := Langage.Reserved_Word'Value (Bounded_String.Image (Lex_Value));
        return (True);
    exception
        when Constraint_Error =>
            return (False);
    end In_Reserved_Word;


    procedure Spell_Reserved_Word (Lex_Value : in out
                                      Bounded_String.Variable_String) is
        X : Langage.Reserved_Word;
    begin
        X := Langage.Reserved_Word'Value (Bounded_String.Image (Lex_Value));
        Bounded_String.Copy (Lex_Value, Langage.Reserved_Word'Image (X));
    end Spell_Reserved_Word;


    procedure Open (Name : in String) is
    begin
        Fichier_Io.Open (Fichier_Source, Name);
    end Open;


    procedure Close (Name : in String) is
    begin
        Fichier_Io.Close (Fichier_Source);
    end Close;


    procedure Next_Token is

        Current_Character : Character := ' ';
        State : State_Key := Normal;
    begin
        Bounded_String.Free (Lex_Value);

        loop
            Current_Character := Fichier_Io.Get (Fichier_Source);
            case Current_Character is

                when 'A' .. 'Z' | 'a' .. 'z' =>
                    case State is
                        when Identifier | Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Special | Operator =>
                            Fichier_Io.Unget (Fichier_Source);
                            return;
                        when Normal =>  
                            State := Identifier;
                            Lex_Token := Identifier;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Integer =>
                            State := Unknown;
                            Lex_Token := Unknown;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                            return;
                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            return;
                    end case;


                when '0' .. '9' =>
                    case State is
                        when Integer =>  
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Normal =>
                            State := Integer;
                            Lex_Token := Integer;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Identifier =>
                            State := Unknown;
                            Lex_Token := Unknown;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);

                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;

                            return;
                    end case;


                when ':' =>
                    case State is
                        when Identifier =>
                            State := Key_Word;
                            Lex_Token := Key_Word;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);

                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;

                            return;
                    end case;


                when '<' =>
                    case State is
                        when Normal =>
                            State := Less;  
                            Lex_Token := Binary_Message;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Less | Less_Equal | Greater_Equal |
                             Greater | Equal | Different =>
                            State := Unknown;
                            Lex_Token := Unknown;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);

                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;

                            return;
                    end case;

                when '>' =>
                    case State is
                        when Normal =>
                            State := Greater;  
                            Lex_Token := Binary_Message;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Less =>
                            State := Different;
                            Lex_Token := Binary_Message;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Greater | Greater_Equal |
                             Less_Equal | Equal | Different =>
                            State := Unknown;
                            Lex_Token := Unknown;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);

                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;

                            return;
                    end case;


                when '=' =>
                    case State is
                        when Normal =>
                            State := Equal;
                            Lex_Token := Binary_Message;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Less =>
                            State := Less_Equal;
                            Lex_Token := Binary_Message;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Greater =>
                            State := Greater_Equal;
                            Lex_Token := Binary_Message;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Equal | Operator =>
                            State := Unknown;
                            Lex_Token := Unknown;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);

                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;

                            return;
                    end case;


                when '*' | '+' | '-' | '/' =>
                    case State is
                        when Normal =>
                            State := Operator;
                            Lex_Token := Binary_Message;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Operator | Less | Different | Greater |
                             Equal | Less_Equal | Greater_Equal =>
                            State := Unknown;
                            Lex_Token := Unknown;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);

                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;

                            return;
                    end case;


                when '{' | '}' | '(' | ')' | '.' =>
                    case State is
                        when Normal =>
                            State := Special;
                            Lex_Token := Special;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);

                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;

                            return;
                    end case;
                when ' ' =>
                    case State is
                        when Normal =>
                            null;
                        when Special | Different | Less | Greater |
                             Equal | Less_Equal | Greater_Equal |
                             Integer | Key_Word | Operator =>
                            State := Found;
                            return;
                        when Identifier =>
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;  
                            State := Found;
                            return;
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);

                        when others =>
                            State := Unknown;
                            Lex_Token := Unknown;
                            return;
                    end case;




                when Ascii.Cr | Ascii.Ht | Ascii.Lf =>
                    case State is
                        when Normal =>
                            null;
                        when Special | Different | Less | Greater |
                             Equal | Less_Equal | Greater_Equal |
                             Integer | Key_Word | Operator =>
                            State := Found;
                            return;
                        when Identifier =>
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;  
                            State := Found;

                            return;
                        when others =>
                            State := Unknown;
                            Lex_Token := Unknown;
                            return;
                    end case;


                when '"' =>
                    case State is
                        when Normal =>
                            State := Tiny_Str;
                            Lex_Token := Tiny_String;
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                        when Tiny_Str =>
                            Bounded_String.Append
                               (Lex_Value, Current_Character);
                            return;
                        when others =>
                            Fichier_Io.Unget (Fichier_Source);
                            if In_Reserved_Word (Lex_Value) then
                                Spell_Reserved_Word (Lex_Value);
                                Lex_Token := Token'Value (Bounded_String.Image
                                                             (Lex_Value));
                                State := Found;
                                return;
                            end if;

                            return;
                    end case;

                when Ascii.Eot =>
                    Lex_Token := L_End;
                    return;
                when others =>
                    State := Unknown;
                    Lex_Token := Unknown;
                    Bounded_String.Append (Lex_Value, Current_Character);
            end case;
        end loop;
        -- Lex_Token := L_End;
    exception
        when Io.End_Error =>
            Lex_Token := L_End;
            return;
    end Next_Token;
end Lex;