home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1988-01-24 | 6.1 KB | 214 lines | [TEXT/????] |
- IMPLEMENTATION MODULE MakeToken;
- (*
- * MAKEMAKE. Create a MAKEFILE for a MODULA-2 program.
- *
- * Written by Steve Tynor, 30 September 1986.
- * UUCP : tynor@gitpyr
- * USNAIL: 2550 Akers Mill Rd. T-2, Atlanta GA. 30339
- *
- * Permission is granted to distribute, copy and change this program as long
- * as this notice remains...
- ---
- *
- * Make.
- * Modified and extended for MacMETH by :
- * J?rgen N?rgaard, 23 october 1987.
- * UUCP : jnp@daimi.dk
- * MAIL : Dybb?lvej 29, v?r. 2+3, 8240 Risskov, DENMARK
- *
- * Essentially only the parser remains from the original.
- * Extensions are a dependency-tree and a make-like facility.
- *
- *)
-
- IMPORT System;
- IMPORT FileSystem;
-
- VAR
- currentCh : CHAR;
- currentFile : FileSystem.File;
-
- (*======================================================================*)
- MODULE FileStack;
- IMPORT FileSystem;
- EXPORT Pop, Push;
-
- CONST
- StackSize = 25;
- VAR
- StrStack : ARRAY [1 .. StackSize] OF FileSystem.File;
- CharStack : ARRAY [1 .. StackSize] OF CHAR;
- StackPtr : CARDINAL;
-
- (*--------------------------------------------------------------------*)
- PROCEDURE Push (str : FileSystem.File; ch : CHAR);
- BEGIN
- IF StackPtr + 1 <= StackSize THEN
- INC (StackPtr);
- StrStack [StackPtr] := str;
- CharStack[StackPtr] := ch;
- END; (* IF *)
- END Push;
-
- (*--------------------------------------------------------------------*)
- PROCEDURE Pop (VAR str : FileSystem.File; VAR ch : CHAR);
- BEGIN
- IF StackPtr > 0 THEN
- str := StrStack [StackPtr];
- ch := CharStack[StackPtr];
- DEC (StackPtr);
- END; (* IF *)
- END Pop;
-
- BEGIN
- StackPtr := 0;
- END FileStack;
- (*======================================================================*)
-
-
- (*----------------------------------------------------------------------*)
- PROCEDURE OpenFile (VAR filename : System.Path;
- VAR success : BOOLEAN);
- VAR
- path, name : System.Path;
- whichPath : INTEGER;
- BEGIN
- Push (currentFile, currentCh);
- whichPath := 0;
- REPEAT
- INC(whichPath);
- System.FindPath(path, filename, whichPath);
- System.AddPath(path, filename, name);
- FileSystem.Lookup(currentFile, name, FALSE);
- success := currentFile.res = FileSystem.done;
- UNTIL success OR (whichPath = 0);
- IF success THEN filename := name END;
- currentCh := ' ';
- END OpenFile;
-
- (*----------------------------------------------------------------------*)
- PROCEDURE CloseFile;
- BEGIN
- FileSystem.Close(currentFile);
- Pop (currentFile, currentCh);
- END CloseFile;
-
-
- (*----------------------------------------------------------------------*)
- PROCEDURE SeparatingChar (ch : CHAR) : BOOLEAN;
- (* we're just worried about a subset of the real separating chars... *)
- BEGIN
- RETURN NOT (((ORD(ch) >= ORD('a')) AND (ORD(ch) <= ORD('z'))) OR
- ((ORD(ch) >= ORD('A')) AND (ORD(ch) <= ORD('Z'))) OR
- ((ORD(ch) >= ORD('0')) AND (ORD(ch) <= ORD('9'))));
- END SeparatingChar;
-
-
- (*----------------------------------------------------------------------*)
- PROCEDURE NextToken (VAR token : ARRAY OF CHAR;
- VAR eof : BOOLEAN);
- VAR
- c : INTEGER;
- BEGIN
- c := 0;
- IF currentCh = ';' THEN
- token[0] := ';';
- token[1] := 0C;
- eof := currentFile.eof;
- FileSystem.ReadChar(currentFile, currentCh);
- RETURN;
- END; (* IF *)
- WHILE SeparatingChar (currentCh) DO
- FileSystem.ReadChar(currentFile, currentCh);
- IF currentCh = ';' THEN
- token[0] := ';';
- token[1] := 0C;
- eof := currentFile.eof;
- FileSystem.ReadChar(currentFile, currentCh);
- RETURN;
- ELSIF currentCh = '(' THEN
- token[c] := currentCh;
- FileSystem.ReadChar(currentFile, currentCh);
- IF currentCh = '*' THEN
- SkipComment;
- ELSE
- token[0] := '(';
- token[1] := currentCh;
- c := 2;
- END; (* IF *)
- END; (* IF *)
- END; (* WHILE *)
- REPEAT
- IF currentCh = '(' THEN
- token[c] := currentCh;
- FileSystem.ReadChar(currentFile, currentCh);
- IF currentCh = '*' THEN
- IF c > 0 THEN
- token[c+1] := 0C;
- SkipComment;
- RETURN;
- ELSE
- SkipComment;
- END; (* IF *)
- END; (* IF *)
- END; (* IF *)
- token[c] := currentCh;
- INC (c);
- FileSystem.ReadChar(currentFile, currentCh);
- UNTIL currentFile.eof OR
- (c > HIGH (token)) OR
- SeparatingChar (currentCh);
- token[c] := 0C;
- eof := currentFile.eof;
- END NextToken;
-
-
- (*----------------------------------------------------------------------*)
- PROCEDURE SkipTillSemicolon (VAR eof : BOOLEAN);
- VAR
- ch : CHAR;
- BEGIN
- REPEAT
- IF (NOT currentFile.eof) AND (currentCh = '(') THEN
- FileSystem.ReadChar(currentFile, currentCh);
- IF (NOT currentFile.eof) AND (currentCh = '*') THEN
- SkipComment;
- END; (* IF *)
- ELSE
- FileSystem.ReadChar(currentFile, currentCh);
- END; (* IF *)
- UNTIL currentFile.eof OR (currentCh = ';');
- END SkipTillSemicolon;
-
-
- (*----------------------------------------------------------------------*)
- PROCEDURE SkipComment;
- VAR
- level : CARDINAL;
- done : BOOLEAN;
- BEGIN
- level := 1;
- FileSystem.ReadChar(currentFile, currentCh);
- done := FALSE;
- REPEAT
- IF (NOT currentFile.eof) AND (currentCh = '*') THEN
- FileSystem.ReadChar(currentFile, currentCh);
- IF (NOT currentFile.eof) AND (currentCh = ')') THEN
- DEC(level);
- done := level = 0;
- END; (* IF *)
- ELSIF (NOT currentFile.eof) AND (currentCh = '(') THEN
- FileSystem.ReadChar(currentFile, currentCh);
- IF (NOT currentFile.eof) AND (currentCh = '*') THEN
- INC(level);
- END; (* IF *)
- ELSE
- FileSystem.ReadChar(currentFile, currentCh);
- END; (* IF *)
- UNTIL currentFile.eof OR done;
- END SkipComment;
-
- BEGIN
- currentCh := ' ';
- END MakeToken.
-