XTRAN Example — Analyze Symbol Usage in COBOL

The following analysis uses two XTRAN rule sets — one to mine code for symbol usage information, and one to report the results.

The code mining rules comprise 137 non-comment lines of XTRAN's rules language ("meta-code"); they analyze all declarations of and references to symbols, for each source file (in this case, only one).

The reporting rules comprise 619 non-coment lines of XTRAN's rules language; they create a cross-reference (both directions) of the symbol usage mined by the first rule set.

Both rule sets are language-independent; they can be used untouched to mine any language XTRAN supports and create the cross-reference report.

The code mining rules for this example can easily be enhanced to produce DSV output that can be interactively queried using existing XTRAN rules.

How can such powerful and generalized code mining and reporting be automated in only 756 total lines of XTRAN rules?  Because there is so much capability already available as part of XTRAN's rules language.  These rules take advantage of the following functionality:

The XTRAN input and output are untouched, except that line numbers have been added to the input for reference.


Process Flowchart

Here is a flowchart for this process, in which the elements are color coded:

data flowchart

Input to XTRAN (sample.cbl):

 1     IDENTIFICATION DIVISION.
 2     PROGRAM-ID.    SAMPLE.
 3     AUTHOR.        ALFRED E. NEUMANN.
 4     INSTALLATION.  SOME COBOL SHOP SOMEWHERE.
 5     DATE-WRITTEN.  APRIL 1993.
 6     DATE-COMPILED.
 7    *REMARKS.  JUST TO SHOW OFF XTRAN.
 8    *
 9     ENVIRONMENT DIVISION.
10     CONFIGURATION SECTION.
11     SOURCE-COMPUTER. IBM-S38.
12     OBJECT-COMPUTER. IBM-S38.
13     DATA DIVISION.
14     WORKING-STORAGE SECTION.
15     01  AMT                    PIC 9(7)V99.
16     01  PAGE-TOTAL             PIC 9(8)V99     VALUE 0.
17     01  DIFF                   PIC 9(7)V99.
18     01  TOTAL                  PIC 9(7)V99.
19     PROCEDURE DIVISION.
20     DO-IT.
21        ADD AMT TO PAGE-TOTAL.
22        SUBTRACT AMT FROM TOTAL GIVING DIFF.
23        STOP RUN.


Output from XTRAN:

                           COBOL Symbol Usage Report
                               Symbol Occurrences

Legend:
        D Occurrence declares symbol nonglobally
        I Occurrence declares symbol as internal global
        E Occurrence declares symbol as external global
        X Occurrence declares symbol as internal or external global
        Q Occurrence equates symbol to a value


AMT
  sample.cbl  15D, 20, 22
DIFF
  sample.cbl  17D, 22
DO-IT
  sample.cbl  20D
PAGE-TOTAL
  sample.cbl  16D, 20
TOTAL
  sample.cbl  18D, 22