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 - metrics - download
Index: B T

⟦f83c115e4⟧ TextFile

    Length: 6185 (0x1829)
    Types: TextFile
    Names: »B«

Derivation

└─⟦180fe333a⟧ Bits:30000405 8mm tape, Rational 1000, SW CATALOG, 10_20_0
└─⟦180fe333a⟧ Bits:30000537 8mm tape, Rational 1000, SW Catalog 10_20_0
    └─⟦5cb1d1d7f⟧ »DATA« 
        └─⟦3b1ee7bd8⟧ 
            └─⟦this⟧ 

TextFile

with Lex;                       -- the lexical analyzer
with Parsestack;                -- elements awaiting parsing
with Statestack;                -- stack of parse states
with Parsetables;               -- state tables generated by parser
-- generator
use Parsetables;

with Grammar_Constants;         -- constants generated by parser generator
use Grammar_Constants;

with Source_Instrumenter_Utilities;--

package body Parser is

    ------------------------------------------------------------------

    procedure Apply_Actions (Rule_Number : in Pt.Lefthandsiderange) is separate;

    ------------------------------------------------------------------

    function Parse return Pd.Parsestackelement is

        --| Overview
        --|
        --| The appropriate reference is:
        --|
        --| Using the NYU LALR Parser Generator. Philippe Charles and
        --| Gerald Fisher. Courant Institute, New York University, 251 Mercer
        --| Street, New York, N.Y.  10012. Unpublished paper. 1981.
        --|

        --|
        --| Notes
        --|
        --| Abbreviations Used:
        --|
        --| Cur : Current - used as prefix
        --| LH  : LeftHand
        --| RH  : RightHand
        --|

        ------------------------------------------------------------------
        -- Reduce Action Work Variables
        ------------------------------------------------------------------

        Reduce_Action_Number : Pt.Lefthandsiderange;
        --| reduction to perform

        Reduce_Action_Lh_Value : Grammarsymbolrange;
        --| grammar symbol number of left hand side of reduction

        Reduce_Action_Rh_Size : Pd.Stateparsestacksindex;
        --| number of elements in right hand side of reduction

        ------------------------------------------------------------------
        -- Other Objects
        ------------------------------------------------------------------

        Current_Action : Actionrange;
        --| return from PT.GetAction.

        Start_State : constant := 1;
        --| Start state for parser.

        Last_Element_Popped : Pd.Parsestackelement;
        --| Last element popped from parse stack

        ------------------------------------------------------------------

    begin

        --|
        --| Algorithm
        --|
        --| Function PT.GetAction returns an action value,
        --| which indicate one of four possible actions:
        --|
        --| Error:  action value = 0.
        --| Shift:  0 < action value < StateCountPlusOne.
        --| Accept: action value = StateCountPlusOne.
        --| Reduce: action value > StateCountPlusOne.
        --|
        --| The action is processed (as described below).
        --| This is repeated until no more tokens are obtained.
        --|
        --| The basic action processing is:
        --|
        --| SHIFT ACTION: the next token is placed on the ParseStack.
        --|
        --| REDUCE ACTION: the handle (a grammar rule's right hand side)
        --| found on the ParseStack is replaced with a
        --| non-terminal (grammar rule's left hand side) to which
        --| it has been reduced, and a new state.
        --|
        --| ACCEPT ACTION: the ParseStack contains the root
        --| of the parse tree, and processing is finished for
        --| If another compilation unit is present, parsing continues.
        --|
        --| ERROR ACTION: the exception Parser_Error is raised.

        ------------------------------------------------------------------

        -- Initialize Lexical Analyzer
        Lex.Initialization;

        Pd.Curtoken := Lex.Getnextnoncommenttoken;

        Statestack.Push (Start_State);

        Do_Parse:
            loop

                Current_Action := Pt.Getaction (Statestack.Copytop,
                                                Pd.Curtoken.Gram_Sym_Val);

                -- Accept action
                exit when (Current_Action in Pd.Accept_Action_Range);

                if Current_Action in Pd.Shift_Action_Range then

                    -- Pretty Printer Utility call
                    Source_Instrumenter_Utilities.Put (Pd.Curtoken);

                    -- Shift token from CurToken to ParseStack.
                    Parsestack.Push (Pd.Curtoken);

                    -- Add new state to top of StateStack
                    Statestack.Push (Current_Action);

                    -- Get next token.
                    Pd.Curtoken := Lex.Getnextnoncommenttoken;

                elsif Current_Action in Pd.Reduce_Action_Range then

                    Reduce_Action_Number := Current_Action - Statecountplusone;

                    Reduce_Action_Lh_Value :=
                       Pt.Get_Lefthandside (Reduce_Action_Number);

                    Reduce_Action_Rh_Size :=
                       Pt.Get_Righthandside (Reduce_Action_Number);

                    -- Reduce Parse Stack
                    Parsestack.Reduce (Reduce_Action_Rh_Size);

                    Parsestack.Push ((Gram_Sym_Val => Reduce_Action_Lh_Value,
                                      Lexed_Token => (Text =>
                                                         Pd.Null_Source_Text,
                                                      Srcpos_Line => 0,
                                                      Srcpos_Column => 0)));

                    -- Reduce State Stack
                    Statestack.Reduce (Reduce_Action_Rh_Size);

                    Statestack.Push (Pt.Getaction (Statestack.Copytop,
                                                   Reduce_Action_Lh_Value));

                    Apply_Actions (Reduce_Action_Number);

                else
                    -- Current_Action is in PD.Error_Action_Range
                    raise Pd.Parser_Error;
                end if;
            end loop Do_Parse;
        return Parsestack.Pop;

    exception
        when Pd.Memoryoverflow =>
            -- raised if Parse runs out of newable memory.
            raise Pd.Memoryoverflow;

    end Parse;

    ------------------------------------------------------------------

end Parser;

----------------------------------------------------------------------