
    <<P1.Mesa>>
        <<Copyright © 1985 by Xerox Corporation.  All rights reserved.>>
        <<Satterthwaite, June 5, 1986 2:00:58 pm PDT>>
        <<Maxwell, August 11, 1983 1:57 pm>>
        <<Paul Rovner, September 7, 1983 3:21 pm>>
        <<Russ Atkinson (RRA) March 6, 1985 10:13:49 pm PST>>
    <<>>
    DIRECTORY
        IO: TYPE USING [STREAM],
        ParseTable: TYPE USING [ActionEntry, ProdDataRef, State, TableRef, TSymbol],
        Rope: TYPE USING [ROPE],
        Symbols: TYPE USING [Name],
        Table: TYPE USING [Index];

    P1: DEFINITIONS = {
        OPEN ParseTable;

        Index: TYPE = INT;    -- FileStream.FileByteIndex

    <<ref types>>

        ValueStack: TYPE = REF  ValueSeq;
        StateStack: TYPE = REF StateSeq;
        LinkStack: TYPE = REF LinkSeq;
        ActionStack: TYPE = REF ActionSeq;

    <<record structures (LONG or REF does not occur past this point)>>

        Value: TYPE = RECORD[    -- type of the value stack
            SELECT OVERLAID * FROM
                scalar => [sb: BOOL, sn: INTEGER],
                ref => [r: Table.Index]
                ENDCASE];

        ValueSeq: TYPE = RECORD[SEQUENCE length: NAT OF P1.Value];

        nullValue: P1.Value = [scalar[FALSE, 0]];
        nullId: P1.Value = [ref[Table.Index.FIRST]];

        StateSeq: TYPE = RECORD[SEQUENCE length: NAT OF ParseTable.State];
        LinkSeq: TYPE = RECORD[SEQUENCE length: NAT OF P1.Index];   -- links to source text
        ActionSeq: TYPE = RECORD[SEQUENCE length: NAT OF ParseTable.ActionEntry];


        Token: TYPE = RECORD[
            class: ParseTable.TSymbol,    -- the token class
            value: P1.Value,
            index: P1.Index];        -- source line index


    <<implemented by Pass1>>
        IdOfFirst: PROC RETURNS[Symbols.Name];
        IdOfLock: PROC RETURNS[Symbols.Name];
        IdOfRest: PROC RETURNS[Symbols.Name];

    <<implemented by Scanner>>
        ErrorContext: PROC[to: IO.STREAM, message: Rope.ROPE, tokenIndex: P1.Index];
        InstallScanTable: PROC[ParseTable.TableRef];
        NextToken: PROC RETURNS[Token];
        ResetScanIndex: PROC[P1.Index] RETURNS[success: BOOL];
        ScanInit: PROC[
            source: IO.STREAM,
            logger: PROC[PROC[log: IO.STREAM]]];
        ScanReset: PROC;
        ScanStats: PROC RETURNS[nTokens, nErrors: CARDINAL];

    <<implemented by Parser>>
        InputLoc: PROC RETURNS[P1.Index];
        InstallParseTable: PROC[ParseTable.TableRef];
        Parse: PROC[
              source: IO.STREAM,
              logger: PROC[PROC [log: IO.STREAM]],
              prefixOk: BOOL]
            RETURNS[complete: BOOL, nTokens, nErrors: CARDINAL];

    <<implemented by TreeBuild (Pass1T)>>

        AssignDescriptors: PROC[
            qd: ActionStack, vd: ValueStack, ld: LinkStack, pp: ParseTable.ProdDataRef];
        ProcessQueue: PROC[qI, top: CARDINAL];
        TokenValue: PROC[ParseTable.TSymbol] RETURNS[P1.Value];

        }.

