The following analysis used an XTRAN rules file comprising 134 non-comment lines of "meta-code" (XTRAN's rules language) to analyze PL/I code and show any knots it finds.
A knot is the crossing of two GOTOs. It is an important
measure of code quality for two reasons:
GOTOs by imposing IF, ELSE, and
DO statements with equivalent functionality. (Click here for an example using XTRAN to restructure PL/I
code.)Note that the analysis output shows not only the number of knots, but also the actual crossings from which that number was determined.
The XTRAN rules
themselves are not specific to PL/I; they are language-independent, and
therefore usable without change to analyze any 3GL
language that has GOTOs.
The input to and output from XTRAN are untouched, except that line numbers have been added to the PL/I source code for reference.
19 prc: PROCEDURE; 20 DCL i FIXED (31) BIN; 21 /* Nesting Range */ 22 /* ============================ */ 23 24 lbl0: GOTO lbl14; /* >--------------\ lbl0-lbl14 */ 25 lbl1: i = 1; /* <--------\ | */ 26 lbl2: GOTO lbl10; /* >-----\ | | lbl2-lbl10 */ 27 lbl3: i = 3; /* | | | */ 28 lbl4: GOTO lbl1; /* >-----x--/ | lbl1-lbl4 */ 29 lbl5: i = 5; /* <-----x-----\ | */ 30 lbl6: GOTO lbl13; /* >-----x--\ | | lbl6-lbl13 */ 31 lbl7: GOTO lbl9; /* >--\ | | | | lbl7-lbl9 */ 32 lbl8: i = 8; /* | | | | | */ 33 lbl9: i = 9; /* <--/ | | | | */ 34 lbl10: i = 10; /* <-----/ | | | */ 35 lbl11: GOTO lbl5; /* >--------x--/ | lbl5-lbl11 */ 36 lbl12: i = 12; /* | | */ 37 lbl13: i = 13; /* <--------/ | */ 38 lbl14: i = 14; /* <--------------/ */ 39 END prc;
Knots found in source code: demknt-a.pli: GOTO at line 26 crosses GOTO at line 28 demknt-a.pli: GOTO at line 26 crosses GOTO at line 30 demknt-a.pli: GOTO at line 26 crosses GOTO at line 35 demknt-a.pli: GOTO at line 30 crosses GOTO at line 35 demknt-a.pli has 4 knots.
COPYRIGHT 2008; reproduction prohibited without permission. Revised 2008-06-05
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