home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / pascal / qparser.arc / SKELRTBL.PAS < prev    next >
Pascal/Delphi Source File  |  1985-08-16  |  5KB  |  167 lines

  1.     { SKELRTBL:  Parser table reading procedures for skeleton files,
  2.                  version 3. }
  3.     { Copyright (C) 1984 by QCAD Systems Inc., All Rights Reserved. }
  4.  
  5.     const TBL_VERSION = 23;  { table file version 2.3 }
  6.     var TFILEX:  int;  { the 'next' value in tfile (lookahead) }
  7.         FILE_ID:  string[80];  { table file identification string }
  8.         ERRWORD:  int;  { error location in table file }
  9.  
  10.     {................}
  11.     procedure TNEXT;
  12.       { grab the 'next' value in the tfile }
  13.     begin
  14.       errword := errword + 1;
  15.       read(tfile, tfilex)
  16.     end;
  17.  
  18.     {................}
  19.     function NEXT_VALUE:  int;
  20.       { read the 'next' value from tfile }
  21.     begin
  22.       next_value := tfilex;
  23.       tnext
  24.     end;
  25.  
  26.     {................}
  27.     procedure VERIFY(VALUE:  int);
  28.       { squawk if the next thing in tfile is not equal to value. }
  29.     var s: string[10];
  30.     begin
  31.       if tfilex = value then
  32.         tnext
  33.       else begin
  34.         str(errword, s);
  35.         abort('Initialization error for table file '+file_id+' at word '+s)
  36.         end
  37.     end;
  38.  
  39.     {................}
  40.     function READ_STRING:  string80;
  41.       { grabs a null-terminated string from the file.  Characters are
  42.         packed two to the word.  If there are an odd number of chars
  43.         in the string, then the pad char is a null.
  44.         A full word of zeros is required to terminate the
  45.         string.  Only the first eighty characters are kept. }
  46.       var STR:  string80;
  47.  
  48.     {. . . . . . . .}
  49.     function LOBYTE(VAL: int): byte;
  50.       var REC: record case boolean of
  51.                 true: (IVAL: int);
  52.                 false: (BVAL: packed array [0..1] of byte);
  53.                 end;
  54.     begin
  55.       with rec do begin
  56.         ival:=val;
  57.         lobyte:=bval[1];
  58.         end
  59.       end;
  60.  
  61.     {. . . . . . . .}
  62.     function HIBYTE(VAL: int): byte;
  63.       var REC: record case boolean of
  64.                 true: (IVAL: int);
  65.                 false: (BVAL: packed array [0..1] of byte);
  66.                 end;
  67.     begin
  68.       with rec do begin
  69.         ival:=val;
  70.         hibyte:=bval[0];
  71.         end
  72.       end;
  73.  
  74.     begin   { read_string }
  75.       str:='';
  76.       while (tfilex <> 0) do begin
  77.         { first, handle the "high" order byte. }
  78.         if length(str) < 80 then begin
  79.           str:=str+' ';
  80.           str[length(str)] := chr(hibyte(tfilex))
  81.           end;
  82.         { next, take care of the "low" order byte. }
  83.         if length(str) >= 80 then
  84.           tnext  { too many chars; just read the next word }
  85.         else begin
  86.           if lobyte(tfilex)>0 then begin
  87.             str:=str+' ';
  88.             str[length(str)] := chr(lobyte(tfilex));
  89.             end;
  90.           tnext
  91.           end
  92.         end;
  93.       tnext;  { skip the terminating null word }
  94.       read_string := str
  95.       end;
  96.  
  97.     {................}
  98.     procedure READ_HEADER;
  99.       { grabs the file id (which is mostly for debugging) and then
  100.         verifies that the tables are right ones (or at least of the
  101.         right size). }
  102.     begin
  103.       errword := -1;  { initialize }
  104.       tnext;  { fill the tfile lookahead pipe }
  105.       file_id := read_string;
  106.       { Validate the file.  The first number verified is the table
  107.         file version number which this skeleton file can handle. }
  108.       verify(tbl_version);
  109.       { OK, if that worked, then we can grab the data. }
  110.       verify(maxstate);   verify(reducelen);
  111.       verify(sstokens);   verify(rltokens);
  112.       verify(lookstate);  verify(prodtoks);
  113.       verify(all_toks)
  114.     end;
  115.  
  116.     {................}
  117.     procedure READ_TABLE_FILE;
  118.       { read the non-debugging portion of the table file }
  119.       var INDEX:  int;
  120.  
  121.       {. . . . . . . . .}
  122.       procedure GETSYM;
  123.         { grabs a symbol from tfile and defines it as a reserved word }
  124.         var
  125.           NAME:  string80;  { the symbol name in string format. }
  126.           TSYM:  symbol;  { ditto, in symbol format. }
  127.           SYMP:  symtabp;  { the new symbol. }
  128.           I:  byte;  { name copying index. }
  129.       begin
  130.         fillchar(tsym, maxtoklen, ' ');
  131.         name := read_string;
  132.         for i := 1 to length(name) do
  133.           tsym[i] := name[i];
  134.         symp := makesym(tsym, reserved, -1);
  135.         symp^.tokval := next_value
  136.       end;
  137.  
  138.     begin { read_table_file }
  139.       { read the goodies }
  140.       while tfilex <> -1 do
  141.         getsym;
  142.       verify(-1);
  143.       for index := 1 to maxstate do
  144.         statex[index] := next_value;
  145.       verify(-1);
  146.       for index := 1 to reducelen do
  147.         map[index] := next_value;
  148.       verify(-1);
  149.       for index := 1 to reducelen do
  150.         popno[index] := next_value;
  151.       verify(-1);
  152.       for index := 0 to sstokens do
  153.         stk_state[index] := next_value;
  154.       verify(-1);
  155.       for index := 0 to sstokens do
  156.         stk_tostate[index] := next_value;
  157.       verify(-1);
  158.       for index := 0 to rltokens do
  159.         toknum[index] := next_value;
  160.       verify(-1);
  161.       for index := 0 to rltokens do
  162.         tostate[index] := next_value;
  163.       verify(-1)
  164.       { that's all for the non-debugging information }
  165.     end { read_table_file };
  166.  
  167.