Excellent advice. > The compiler has done 99.9% of the hard work at this point.
And done it exactly the way the compiler does it -- in other words, this moots my last point about the syntactically questionable program. Charles -----Original Message----- From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf Of John McKown Sent: Friday, March 22, 2013 10:54 AM To: [email protected] Subject: Re: Parsing cobol code for copybooks Personally, I'd really prefer to have someone do a compile of the source, using the ADATA compile parameter. Output the ADATA to a sequential data set (or member of a PDS), then read that. The compiler has done 99.9% of the hard work at this point. ADATA reference: http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3PG50/APPENDIX 1.7 On Fri, Mar 22, 2013 at 12:48 PM, Charles Mills <[email protected]> wrote: > As one who has done it as part of a larger product, it is a bear. > > If you don't mind a few false positives, then just parsing for the > word COPY and picking off the next token (as someone else wrote), and > optionally OF ddname, will get you there. > > COBOL syntax is downright ugly, and doing it right is a bear. You have > to > consider: > > - Comments, as the other poster wrote. > - String literals, with their goofy continuation rules. > - Comment paragraphs -- those things like DATE-WRITTEN. > - Maybe some other things -- I would have to look at my code to be sure. > > Rules are slightly different for older versions of COBOL. > > There is also EXEC-SQL INCLUDE which works similarly to COPY but is a > different sequence. > > Oh, also BASIS ... > > Not sure if the Rexx stem variable approach will work -- I have seen > COBOL programs of several hundred thousand lines. I guess that will be okay: > 200,000 80-byte images is only 16 MB LOL. > > And sometimes a shop has programs that seem to be syntactically > invalid but which nonetheless compile without error, and if you can't > handle them, you're the bad guy, not the program, because "it's been > this way for years and was never a problem, and anyway we don't have a > budget to fix it, so you better fix your program." ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
