home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / pascal / qparser.arc / SKELSYMS.PAS < prev   
Pascal/Delphi Source File  |  1984-11-19  |  3KB  |  100 lines

  1.   { SKELSYMS:  Symbol table handling for skeleton files. }
  2.   { Copyright (C) 1984 by QCAD Systems Inc., All Rights Reserved. }
  3.  
  4.   {*******************}
  5.   function HASHIT(FSYM: symbol): int;
  6.   begin
  7.     hashit := (128*(ord(fsym[1])+ord(fsym[3])) +
  8.                ord(fsym[2])+ord(fsym[4]))
  9.               mod hashsize;
  10.   end;
  11.  
  12.   {*****************}
  13.   function FINDSYM(FSYM: symbol): symtabp;
  14.     { Finds a symbol, returning NIL if not there.  Use this for
  15.       variable references, calling error if it returns NIL. }
  16.     var SP: symtabp;
  17.   begin
  18.     findsym := nil;
  19.     sp := symtab[hashit(fsym)];
  20.     while sp <> nil do begin
  21.       with sp^ do begin
  22.         if sym <> fsym then
  23.           sp := next
  24.         else begin
  25.           findsym := sp;
  26.           sp := nil
  27.         end
  28.       end
  29.     end
  30.   end;
  31.  
  32.   {**********************}
  33.   function MAKESYM(FSYM: symbol;  SYT: symtype;  LEV: int):  symtabp;
  34.     { this returns a symbol entry if there; makes a new one if not.
  35.       Useful for FORTRAN-style variable declaration -- declare name
  36.       on first appearance, whether in a declaration or not. }
  37.     var SP: symtabp;
  38.         HX: int;
  39.   begin
  40.     sp := findsym(fsym);
  41.     if sp = nil then begin
  42.       new(sp);  { need a new one if here }
  43.       with sp^ do begin
  44.         { put at the head of the hash list}
  45.         sym := fsym;
  46.         symt := syt;
  47.         hx := hashit(fsym);
  48.         next := symtab[hx];
  49.         symtab[hx] := sp;
  50.         level := lev;
  51.       end
  52.     end;
  53.     makesym := sp
  54.   end;
  55.  
  56.   {**********************}
  57.   function FORCESYM(FSYM: symbol;  SYT: symtype;  LEV: int):  symtabp;
  58.     { This forces a new symbol entry.  Use this for declarations
  59.       to cover a previous declaration with the same name. }
  60.     var SP: symtabp;
  61.         HX: int;
  62.   begin
  63.     hx := hashit(fsym);
  64.     new(sp);
  65.     with sp^ do begin
  66.       { put at the head of the hash list. }
  67.       sym := fsym;
  68.       symt := syt;
  69.       next := symtab[hx];
  70.       symtab[hx] := sp;
  71.       level := lev;
  72.     end;
  73.     forcesym := sp;
  74.   end;
  75.  
  76.   {********************}
  77.   procedure CLEARSYM(CLEVEL: int);
  78.     { Sets the symbol table pointers to remove references to
  79.       everything at level >= CLEVEL, assuming that level numbers
  80.       are monotonic.  Prepares for a RELEASE of memory. }
  81.     var HX: int;
  82.         SP, KEEP: symtabp;
  83.   begin
  84.     { Don't clear the reserved words -- check, just in case }
  85.     if clevel<0 then clevel := 0;
  86.     for hx := 0 to hlimit do begin
  87.       sp := symtab[hx];  keep := nil;
  88.       while sp <> nil do begin
  89.         if sp^.level >= clevel then
  90.           sp := sp^.next
  91.         else begin
  92.           keep := sp;
  93.           sp := nil
  94.         end
  95.       end;
  96.       symtab[hx] := keep
  97.     end
  98.   end;
  99.  
  100.