-- file PGSTypes.Mesa
-- last modified by Satterthwaite, June 23, 1982 9:11 am

DIRECTORY
  Mopcodes: TYPE USING [zLI4, zRFSL, zSHIFT, zWFSL];

PGSTypes: DEFINITIONS = {

 -- long/short differences appear here and in PGSParseTable

 -- uninterpreted pointers

  LongDes: TYPE = LONG DESCRIPTOR FOR ARRAY OF UNSPECIFIED;
  LongPointer: TYPE = LONG POINTER;

 -- pointer-sensitive inlines

  Bit: PRIVATE TYPE = [0..1];
  GetBit: PROC [word: LongPointer, bit: CARDINAL] RETURNS [Bit] =
    MACHINE CODE {Mopcodes.zLI4; Mopcodes.zSHIFT; Mopcodes.zRFSL};
  SetBit: PROC [v: Bit, word: LongPointer, bit: CARDINAL] =
    MACHINE CODE {Mopcodes.zLI4; Mopcodes.zSHIFT; Mopcodes.zWFSL};


-- data structures and associated types
  
 -- data structtures using the following types are built by PGSScan

  alternateLim: CARDINAL = 31;
  maxProd: CARDINAL = 500;
  maxRhsSymbols: CARDINAL = 2*maxProd;  -- empirical relation
  maxRule: CARDINAL = 2047; --this is the current ProdInfo/PGSTab limit
  pssLim: CARDINAL = 1023; -- 10 bit field in itemrec to hold production, symbol
		           -- or state numbers, PGSTab allows an 11 bit field
  rhsLim: CARDINAL = 15; --this is the current PGSTab limit, change the grammar?
  symTabSize: CARDINAL = 350; --symbol table size
  tokenSize: CARDINAL = 14;

  SymTab: TYPE = LONG DESCRIPTOR FOR PACKED ARRAY OF CHARACTER;
    -- [0..(symTabSize+1)*tokensize)
  SymTabEntry: TYPE = RECORD [
    link: [0..symTabSize],
    length: [0..tokenSize],
    used: BOOLEAN];
  SymInfo: TYPE = LONG DESCRIPTOR FOR ARRAY OF SymTabEntry;
    -- [0..symtabsize]

  AliasEntry: TYPE = RECORD [terminal, alias: CARDINAL];
  Aliases: TYPE = LONG DESCRIPTOR FOR ARRAY OF AliasEntry; -- [0..63]

  TokenEntry: TYPE = RECORD [
    count: [0..alternateLim],
    empty: BOOLEAN,
    index: [0..maxProd]];
  TokenInfo: TYPE = LONG DESCRIPTOR FOR ARRAY OF TokenEntry;
    --(eofile..totaltokens]

  ProdEntry: TYPE = RECORD [
    count: [0..rhsLim],
    rule: [0..maxRule],
    chain: BOOLEAN,
    lhs: [0..symTabSize],
    index: [0..maxRhsSymbols]];
  ProdInfo: TYPE = LONG DESCRIPTOR FOR ARRAY OF ProdEntry;
    -- [0..maxProd]

  RhsChar: TYPE = LONG DESCRIPTOR FOR ARRAY OF CARDINAL;
    -- [0..maxRhsSymbols]

  Options: TYPE = {echo, chain, lists, printLR, printLALR, first, ids};

 -- types for LR(0) tables in PGSLALR

  StateInfoRec: TYPE = RECORD [link, nucleus, entries: CARDINAL];
  StateInfo: TYPE = LONG DESCRIPTOR FOR ARRAY OF StateInfoRec; --[0,maxstatenum+1];

  ItemRec: TYPE = RECORD [tag: [0..3], jf: [0..15], pss: [0..pssLim]];
  Table: TYPE = LONG DESCRIPTOR FOR ARRAY OF ItemRec; --[0..maxtabentries]
    --after table is built,
    --tag = 3 => pss is a nonterminal symbol, such an entry is followed by an entry:
    --tag = 0 => pss is a next state number
    --tag = 1 => pss is production number, scanreduce, jf=n[p]
    --tag = 2 => pss is production number, reduce, jf=n[p]

  -- types for LALR(1) lookahead sets in PGSLALR

  ChainRec: TYPE = RECORD [state, link: CARDINAL];
  BackChain: TYPE= LONG DESCRIPTOR FOR ARRAY OF ChainRec; --[0..totalshifts] initially

  Stack: TYPE = LONG DESCRIPTOR FOR ARRAY OF CARDINAL;  --[0..30) initially
  ChainStack: TYPE = LONG DESCRIPTOR FOR ARRAY OF CARDINAL;  --[0..90) initially  

  ContextRec: TYPE = RECORD [state, status, link: CARDINAL, item: ItemRec];
  BitsInfo: TYPE = LONG DESCRIPTOR FOR ARRAY OF ContextRec;  --[0..maxcontexts)
  BitString: TYPE = LONG DESCRIPTOR FOR ARRAY OF UNSPECIFIED;  --[0..maxcontexts)
  FirstBits: TYPE = LONG DESCRIPTOR FOR ARRAY OF UNSPECIFIED; --[eofile+1..totaltokens]

  -- types used internally by PGSLALR

  AttrVec: TYPE = LONG DESCRIPTOR FOR ARRAY OF CARDINAL; --[eofile+1..totaltokens]
  HashHeads: TYPE = ARRAY [0..60] OF CARDINAL;
  HashHeadsRef: TYPE = LONG POINTER TO HashHeads;

  -- types used by PGSTab

  HashTabRec: TYPE = MACHINE DEPENDENT RECORD [symPtr: [0..255], link: [0..255]];
  HashTab: TYPE =  LONG DESCRIPTOR FOR ARRAY OF HashTabRec; --[0..hashval]

  TabRec: TYPE = RECORD [symbol: CARDINAL, item: ItemRec];
  TTab: TYPE =  LONG DESCRIPTOR FOR ARRAY OF TabRec; --[0..tentries-1];
  NTab: TYPE =  LONG DESCRIPTOR FOR ARRAY OF TabRec; --[0..ntentries-1];

  ColumnRec: TYPE = RECORD [link, count: CARDINAL, item: ItemRec];
  Column: TYPE =  LONG DESCRIPTOR FOR ARRAY OF ColumnRec; --[0..ntentries];

  StateDataRec: TYPE = RECORD [tIndex, ntIndex: CARDINAL, tLink, ntLink: INTEGER];
  StateData: TYPE =  LONG DESCRIPTOR FOR ARRAY OF StateDataRec; --[0..slim-1];

  NTDefaultRec: TYPE = RECORD [count: CARDINAL, item: ItemRec];
  NTDefaults: TYPE = LONG DESCRIPTOR FOR ARRAY OF NTDefaultRec;
						 --[0..totaltokens-eofile+1];
  Renumber: TYPE = LONG DESCRIPTOR FOR ARRAY OF CARDINAL;  --[0..slim-1]
  VocabIndex: TYPE = LONG DESCRIPTOR FOR ARRAY OF CARDINAL;  --[0..eofile-1]

  -- types used by PGSFormat (also uses SymTab, RhsChar, HashHeads, HashHeadsRef)

  SInfoRec: TYPE = RECORD [symPtr, link, lhsHead: CARDINAL];
  SInfo: TYPE =  LONG DESCRIPTOR FOR ARRAY OF SInfoRec; --[0..symTabSize+1];
  PInfoRec: TYPE = RECORD [rule: [0..77777B], chain: BOOLEAN, link, rhsPtr: CARDINAL];
  PInfo: TYPE =  LONG DESCRIPTOR FOR ARRAY OF PInfoRec; --[0..maxProd+1];

  }.