-- file PGSConDefs.mesa
-- last modified by Satterthwaite, September 16, 1982 10:14 am

DIRECTORY
  Environment: TYPE USING [bitsPerWord, charsPerWord, wordsPerPage],
  PGSTypes: TYPE USING [
    Aliases, LongDes, LongPointer, Options, ProdInfo, RhsChar, SymTab, SymInfo, TokenInfo,
    alternateLim, maxProd, maxRhsSymbols, maxRule, pssLim, rhsLim, symTabSize, tokenSize,
    GetBit, SetBit],
  Stream: TYPE USING [Handle],
  Strings: TYPE USING [String],
  TimeStamp: TYPE USING [Stamp];

PGSConDefs: DEFINITIONS IMPORTS PGSTypes = {

 -- machine parameters
  cpw: CARDINAL = Environment.charsPerWord;
  pageSize: CARDINAL = Environment.wordsPerPage;
  wordLength: CARDINAL = Environment.bitsPerWord;
  maxCharCode: CARDINAL = LAST[CHAR]-FIRST[CHAR];

 -- common compile time constants
  outbufLim: CARDINAL = 90;

 --PGSScan compile time constants
  alternateLim: CARDINAL = PGSTypes.alternateLim;
  maxProd: CARDINAL = PGSTypes.maxProd;
  maxRhsSymbols: CARDINAL = PGSTypes.maxRhsSymbols;
  maxRule: CARDINAL = PGSTypes.maxRule;
  pssLim: CARDINAL = PGSTypes.pssLim;
  rhsLim: CARDINAL = PGSTypes.rhsLim;
  symTabSize: CARDINAL = PGSTypes.symTabSize;
  tokenSize: CARDINAL = PGSTypes.tokenSize;

  wordsForToken: CARDINAL = (tokenSize+cpw-1)/cpw;
  ControlZ: CHAR = '\032;  -- ↑Z, Bravo escape character
  query: CHAR = '?; -- marker character in PGSformat

 --PGSLALR constants
  maxStateNum: CARDINAL = 400;
  stateExt: CARDINAL = 100;
  maxTabEntries: CARDINAL = 7000;
  tabExt: CARDINAL = 1000;
  maxContexts: CARDINAL = 960;

 --PGSTab constants
  defaultMarker: CARDINAL = 0;


 -- structures built and exported by PGSControl, used by PGSFormat and PGSBcd
  pgsVersion: VAR TimeStamp.Stamp;
  sourceVersion: VAR TimeStamp.Stamp;
  sourceName: VAR Strings.String;
  objectVersion: VAR TimeStamp.Stamp;

 -- structures built by PGSScan, exported by PGSControl, used by PGSLALR and PGSTab
  warningsLogged: VAR BOOL;
  eofile: VAR CARDINAL;  -- last terminal
  totalTokens: VAR CARDINAL;  -- size of grammar vocabulary
  numprod: VAR CARDINAL;  -- number of productions
  numrules: VAR CARDINAL;  -- number of rules
  nextAlias: VAR CARDINAL;  -- number of aliased terminal symbols
  flags: VAR ARRAY PGSTypes.Options OF BOOL;
  symtab: VAR PGSTypes.SymTab;
  syminfo: VAR PGSTypes.SymInfo;
  aliases: VAR PGSTypes.Aliases;
  tokeninfo: VAR PGSTypes.TokenInfo;
  prodinfo: VAR PGSTypes.ProdInfo;
  rhschar: VAR PGSTypes.RhsChar;

 -- structures built by PGSLALR, exported by PGSControl, used by PGSTab
  slim, tentries, ntentries: VAR CARDINAL;

 -- structures built by PGSLALR, exported by PGSControl, used by PGSControl and PGSLALR
  bitstrsize: VAR CARDINAL;

-- procedures

  LongPointer: TYPE = PGSTypes.LongPointer;
  LongDes: TYPE = PGSTypes.LongDes;

 -- storage management, exported by PGSControl

  AcquireZone: PROC RETURNS [UNCOUNTED ZONE];
  ReleaseZone: PROC [UNCOUNTED ZONE] = INLINE {};
  
  MakeArray: PROC [length, width: CARDINAL] RETURNS [LongDes];
  Expand: PROC [des: LongDes, width, ext: CARDINAL] RETURNS [LongDes];
  FreeArray: PROC [des: LongDes];
  
 -- stream input/output, exported by PGSControl

  seterrstream: PROC;
  setoutstream: PROC [dotstring: Strings.String];
  resetoutstream: PROC;
  closeoutstream: PROC;
  cleanupstreams: PROC;

  inchar: PROC RETURNS [c: CHAR, end: BOOL];

  outchar: PROC [c: CHAR, n: INTEGER];
  outeol: PROC [n: CARDINAL];
  outnum: PROC [val: INTEGER, cols: CARDINAL, signChar: CHAR←'-];
  outstring: PROC [string: Strings.String];
  outtab: PROC;
  outtime: PROC;

  openwordstream: PROC [scratch: BOOL ← TRUE];
  closewordstream: PROC;
  inword: PROC RETURNS [CARDINAL];
  outword: PROC [n: CARDINAL];
  outblock: PROC [address: LongPointer, words: CARDINAL];

 -- bit manipulation, exported by PGSControl
  FindBit: PROC [num: CARDINAL, source: LongPointer] RETURNS [BOOL] =
    INLINE {RETURN [PGSTypes.GetBit[source+num/wordLength, num MOD wordLength] # 0]};
  InsertBit: PROC [num: CARDINAL, sink: LongPointer] =
    INLINE {PGSTypes.SetBit[1, sink + num/wordLength, num MOD wordLength]};
  orCount: VAR CARDINAL;
  OrBits: PROC [source, sink: LongPointer];

 -- errors, exported by PGSControl
  PGSFail: ERROR;

 -- implemented by PGSScan
  OutToken: PROC [symbol: CARDINAL] RETURNS [CARDINAL];
  CheckOut: PROC;

 -- implemented by PGSLALR
  LALRGen: PROC RETURNS [BOOL];

 -- implemented by PGSTab
  TabGen: PROC [prefix, suffix: PROC] RETURNS [BOOL];
  OutModule: PROC [typename, modfname: Strings.String, long: BOOL ← FALSE];

 -- implemented by PGSFormat
  Format: PROC [table, type, export: Strings.String];
  PrintGrammar: PROC;

 -- implemented by PGSBcd
  WriteBcdHeader: PROC [
      outStream: Stream.Handle,
      tableId, binaryId: Strings.String,	-- file being written
      interfaceId, fileId: Strings.String,	-- interface being exported
      altoCode: BOOL ← FALSE];
  FixupBcdHeader: PROC;

 -- implemented by PGSSymbols
  WriteSymbols: PROC [s: Stream.Handle, moduleId: Strings.String];

 -- implemented by PGSInterface
  AcquireTable: PROC RETURNS [LONG POINTER];
  ReleaseTable: PROC;

  }.