-- file P1.Mesa
-- last modified by Satterthwaite, February 18, 1983 8:39 am

DIRECTORY
  ParseTable: TYPE USING [ActionEntry, ProdDataRef, State, TableRef, TSymbol],
  Stream: TYPE USING [Handle],
  Strings: TYPE USING [String],
  Symbols: TYPE USING [Name];

P1: DEFINITIONS = {
  OPEN ParseTable;

 -- pointer types
 
  ValueStack: TYPE = LONG POINTER TO  P1.ValueSeq;
  StateStack: TYPE = LONG POINTER TO StateSeq;
  LinkStack: TYPE = LONG POINTER TO LinkSeq;
  ActionStack: TYPE = LONG POINTER TO ActionSeq;
  
 -- record structures (LONG does not occur past this point)
  
  Value: TYPE = RECORD [	-- type of the value stack
    SELECT OVERLAID * FROM
      scalar => [s: UNSPECIFIED],
      ref => [r: UNSPECIFIED]
      ENDCASE];

  nullValue: P1.Value = [scalar[0]];
  nullId: P1.Value = [ref[0]];

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

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


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


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

 -- implemented by Scanner
  Atom: PROC RETURNS [Token];
  ErrorContext: PROC [to: Stream.Handle, message: Strings.String, tokenIndex: CARDINAL];
  InstallScanTable: PROC [ParseTable.TableRef];
  ResetScanIndex: PROC [CARDINAL] RETURNS [success: BOOL];
  ScanInit: PROC [
      source: Stream.Handle,
      scratchZone: UNCOUNTED ZONE,
      logger: PROC [PROC [log: Stream.Handle]]];
  ScanReset: PROC RETURNS [nTokens, nErrors: CARDINAL];

 -- implemented by Parser
  InstallParseTable: PROC [ParseTable.TableRef];
  Parse: PROC [
      source: Stream.Handle,
      scratchZone: UNCOUNTED ZONE,
      logger: PROC [PROC [log: Stream.Handle]]]
    RETURNS [complete: BOOL, nTokens, nErrors: CARDINAL];
  ParserID: PROC RETURNS [Strings.String];
  InputLoc: PROC RETURNS [CARDINAL];

 -- implemented by TreeBuild (Pass1T)

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

  }.