home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Modula / Utilities / Makefiles / MakeToken.MOD < prev   
Encoding:
Modula Implementation  |  1988-01-24  |  6.1 KB  |  214 lines  |  [TEXT/????]

  1. IMPLEMENTATION MODULE MakeToken;
  2.   (*
  3.    * MAKEMAKE.  Create a MAKEFILE for a MODULA-2 program.
  4.    *
  5.    * Written by Steve Tynor, 30 September 1986.
  6.    *            UUCP  : tynor@gitpyr
  7.    *            USNAIL: 2550 Akers Mill Rd. T-2, Atlanta GA. 30339
  8.    *
  9.    * Permission is granted to distribute, copy and change this program as long
  10.    * as this notice remains...
  11.    ---
  12.    *
  13.    * Make.
  14.    * Modified and extended for MacMETH by :
  15.    * J?rgen N?rgaard, 23 october 1987.
  16.    *            UUCP  : jnp@daimi.dk
  17.    *            MAIL  : Dybb?lvej 29, v?r. 2+3, 8240 Risskov, DENMARK
  18.    *
  19.    * Essentially only the parser remains from the original.
  20.    * Extensions are a dependency-tree and a make-like facility.
  21.    *
  22.    *)
  23.  
  24. IMPORT System;
  25. IMPORT FileSystem;
  26.  
  27. VAR 
  28.   currentCh : CHAR;
  29.   currentFile : FileSystem.File;
  30.   
  31.   (*======================================================================*)
  32.   MODULE FileStack;
  33.   IMPORT FileSystem;
  34.   EXPORT Pop, Push;
  35.  
  36.   CONST
  37.     StackSize = 25;
  38.   VAR
  39.     StrStack  : ARRAY [1 .. StackSize] OF FileSystem.File;
  40.     CharStack : ARRAY [1 .. StackSize] OF CHAR;
  41.     StackPtr  : CARDINAL;
  42.  
  43.     (*--------------------------------------------------------------------*)
  44.     PROCEDURE Push (str : FileSystem.File; ch : CHAR);
  45.     BEGIN
  46.       IF StackPtr + 1 <= StackSize THEN
  47.         INC (StackPtr);
  48.         StrStack [StackPtr] := str;
  49.         CharStack[StackPtr] := ch;
  50.       END; (* IF *)
  51.     END Push;
  52.  
  53.     (*--------------------------------------------------------------------*)
  54.     PROCEDURE Pop (VAR str : FileSystem.File; VAR ch : CHAR);
  55.     BEGIN
  56.       IF StackPtr > 0 THEN
  57.         str := StrStack [StackPtr];
  58.         ch  := CharStack[StackPtr];
  59.         DEC (StackPtr);
  60.       END; (* IF *)
  61.     END Pop;
  62.  
  63.   BEGIN
  64.     StackPtr := 0;
  65.   END FileStack;
  66.   (*======================================================================*)
  67.  
  68.  
  69.   (*----------------------------------------------------------------------*)
  70.   PROCEDURE OpenFile (VAR filename : System.Path;
  71.                       VAR success  : BOOLEAN);
  72.     VAR
  73.       path, name : System.Path;
  74.       whichPath : INTEGER;
  75.   BEGIN
  76.     Push (currentFile, currentCh);
  77.     whichPath := 0;
  78.     REPEAT
  79.       INC(whichPath);
  80.       System.FindPath(path, filename, whichPath);
  81.       System.AddPath(path, filename, name);
  82.       FileSystem.Lookup(currentFile, name, FALSE);
  83.       success := currentFile.res = FileSystem.done;
  84.     UNTIL success OR (whichPath = 0);
  85.     IF success THEN filename := name END;
  86.     currentCh := ' ';
  87.   END OpenFile;
  88.  
  89.   (*----------------------------------------------------------------------*)
  90.   PROCEDURE CloseFile;
  91.   BEGIN
  92.     FileSystem.Close(currentFile);
  93.     Pop (currentFile, currentCh);
  94.   END CloseFile;
  95.  
  96.  
  97.   (*----------------------------------------------------------------------*)
  98.   PROCEDURE SeparatingChar (ch : CHAR) : BOOLEAN;
  99.     (* we're just worried about a subset of the real separating chars... *)
  100.   BEGIN
  101.     RETURN NOT (((ORD(ch) >= ORD('a')) AND (ORD(ch) <= ORD('z'))) OR
  102.                 ((ORD(ch) >= ORD('A')) AND (ORD(ch) <= ORD('Z'))) OR
  103.                 ((ORD(ch) >= ORD('0')) AND (ORD(ch) <= ORD('9'))));
  104.   END SeparatingChar;
  105.  
  106.  
  107.   (*----------------------------------------------------------------------*)
  108.   PROCEDURE NextToken (VAR token : ARRAY OF CHAR;
  109.                        VAR eof   : BOOLEAN);
  110.   VAR
  111.     c : INTEGER;
  112.   BEGIN
  113.     c := 0;
  114.     IF currentCh = ';' THEN
  115.       token[0] := ';';
  116.       token[1] := 0C;
  117.       eof := currentFile.eof;
  118.       FileSystem.ReadChar(currentFile, currentCh);
  119.       RETURN;
  120.     END; (* IF *)
  121.     WHILE SeparatingChar (currentCh) DO
  122.       FileSystem.ReadChar(currentFile, currentCh);
  123.       IF currentCh = ';' THEN
  124.         token[0] := ';';
  125.         token[1] := 0C;
  126.         eof := currentFile.eof;
  127.         FileSystem.ReadChar(currentFile, currentCh);
  128.         RETURN;
  129.       ELSIF currentCh = '(' THEN
  130.         token[c] := currentCh;
  131.         FileSystem.ReadChar(currentFile, currentCh);
  132.         IF currentCh = '*' THEN
  133.           SkipComment;
  134.         ELSE
  135.           token[0] := '(';
  136.           token[1] := currentCh;
  137.           c := 2;
  138.         END; (* IF *)
  139.       END; (* IF *)
  140.     END; (* WHILE *)
  141.     REPEAT
  142.       IF currentCh = '(' THEN
  143.         token[c] := currentCh;
  144.         FileSystem.ReadChar(currentFile, currentCh);
  145.         IF currentCh = '*' THEN
  146.           IF c > 0 THEN
  147.             token[c+1] := 0C;
  148.             SkipComment;
  149.             RETURN;
  150.           ELSE
  151.             SkipComment;
  152.           END; (* IF *)
  153.         END; (* IF *)
  154.       END; (* IF *)
  155.       token[c] := currentCh;
  156.       INC (c);
  157.       FileSystem.ReadChar(currentFile, currentCh);
  158.     UNTIL currentFile.eof OR 
  159.           (c > HIGH (token)) OR 
  160.           SeparatingChar (currentCh);
  161.     token[c] := 0C;
  162.     eof := currentFile.eof;
  163.   END NextToken;
  164.  
  165.  
  166.   (*----------------------------------------------------------------------*)
  167.   PROCEDURE SkipTillSemicolon (VAR eof   : BOOLEAN);
  168.   VAR
  169.     ch : CHAR;
  170.   BEGIN
  171.     REPEAT
  172.       IF (NOT currentFile.eof) AND (currentCh = '(') THEN
  173.         FileSystem.ReadChar(currentFile, currentCh);
  174.         IF (NOT currentFile.eof) AND (currentCh = '*') THEN
  175.           SkipComment;
  176.         END; (* IF *)
  177.       ELSE
  178.         FileSystem.ReadChar(currentFile, currentCh);
  179.       END; (* IF *)
  180.     UNTIL currentFile.eof OR (currentCh = ';');
  181.   END SkipTillSemicolon;
  182.  
  183.  
  184.   (*----------------------------------------------------------------------*)
  185.   PROCEDURE SkipComment;
  186.   VAR
  187.     level : CARDINAL;
  188.     done  : BOOLEAN;
  189.   BEGIN
  190.     level := 1;
  191.     FileSystem.ReadChar(currentFile, currentCh);
  192.     done := FALSE;
  193.     REPEAT
  194.       IF (NOT currentFile.eof) AND (currentCh = '*') THEN
  195.         FileSystem.ReadChar(currentFile, currentCh);
  196.         IF (NOT currentFile.eof) AND (currentCh = ')') THEN
  197.           DEC(level);
  198.           done := level = 0;
  199.         END; (* IF *)
  200.       ELSIF (NOT currentFile.eof) AND (currentCh = '(') THEN
  201.         FileSystem.ReadChar(currentFile, currentCh);
  202.         IF (NOT currentFile.eof) AND (currentCh = '*') THEN
  203.           INC(level);
  204.         END; (* IF *)
  205.       ELSE
  206.         FileSystem.ReadChar(currentFile, currentCh);
  207.       END; (* IF *)
  208.     UNTIL currentFile.eof OR done;
  209.   END SkipComment;
  210.  
  211. BEGIN
  212.   currentCh := ' ';
  213. END MakeToken.
  214.