The following example used an XTRAN rules file comprising 166 non-comment lines of "meta-code" (XTRAN's rules language) to highlight PL/I code involved with either file or display I/O. The rules took about four hours to create and debug. They are not particularly specific to PL/I; they can easily be adapted to do the same for any 3GL language.
Note that the rules infer display or file I/O usage of a variable to which a value is assigned that contains any variables of either type.
The following is an English paraphrase of the XTRAN rules used for this example:
Specify HTML as module output "decoration" prefix and suffix
Specify HTML as statement output "decoration" prefix and suffix
according to statement's I/O involvement if any
Specify HTML as expression output "decoration" prefix and suffix
according to expression's I/O involvement if any
For each PL/I statement
If DISPLAY or ACCEPT statement
Mark statement as "display I/O"
Mark all variables in statement as "display I/O"
Else if CLOSE, OPEN, READ, or WRITE statement
Mark statement as "file I/O"
Mark all variables in statement as "file I/O"
While variables to mark
For each PL/I statement
If assignment statement
If right side has "file I/O" and/or "display I/O" variables
If left side not already marked
Mark left side as such
Put out code; XTRAN will decorate it as specified
The input to and output from XTRAN are untouched.
prc: PROC (dspio1, filio1);
DCL (dspio1, dspio2) FIXED BIN (31);
DCL (filio1, filio2, filio3) FIXED BIN (31);
DCL (bthio1, bthio2) FIXED BIN (31);
DCL (neither1, neither2) FIXED BIN (31);
DCL file1 FILE;
DISPLAY ('First argument is ' || dspio1);
dspio2 = dspio1;
OPEN FILE(file1) INPUT TITLE('foo');
READ FILE(file1) INTO(filio1);
filio2 = filio1 + 1;
bthio1 = bthio1 + filio1;
neither1 = 1;
neither2 = neither1 + 1;
IF (filio2 > filio3) THEN
filio3 = filio2;
bthio1 = dspio1;
bthio2 = filio1 + bthio1;
dspio1 = neither2;
CLOSE FILE(file1);
RETURN;
END prc;
prc: PROCEDURE (dspio1, filio1);
DCL (dspio1, dspio2) FIXED BIN (31);
DCL (filio1, filio2, filio3) FIXED BIN (31);
DCL (bthio1, bthio2) FIXED BIN (31);
DCL (neither1, neither2) FIXED BIN (31);
DCL file1 FILE;
DISPLAY ('First argument is ' || dspio1);
dspio2 = dspio1;
OPEN FILE(file1) INPUT TITLE('foo');
READ FILE(file1) INTO(filio1);
filio2 = filio1 + 1;
bthio1 = bthio1 + filio1;
neither1 = 1;
neither2 = neither1 + 1;
IF filio2 > filio3
THEN
filio3 = filio2;
bthio1 = dspio1;
bthio2 = filio1 +
bthio1;
dspio1 = neither2;
CLOSE FILE(file1);
RETURN;
END prc;
COPYRIGHT 2008; reproduction prohibited without permission. Revised 2007-09-12
XTRAN is a trademark of Pennington Systems Incorporated.
Pennington Systems Incorporated
8655 East
Via de Ventura, Suite G200
Scottsdale, Arizona 85258-3321
Phone: +1(480)626-5503
Fax: +1(480)626-7618
Email: Info@Pennington.com
Web: http://WWW.Pennington.com