[antlr-interest] COBOL question

Matt Benson gudnabrsam at yahoo.com
Fri Feb 10 10:38:24 PST 2006


Having worked with COBOL for several years until my
recent emancipation, I don't envy you this task, which
I thought of doing more than once but fortunately
never HAD to.  The column positions sure were
problematical in theory, especially due to the fact
that different circumstances (some of which I still
don't completely understand) make it legal to, for
example, do away entirely with the initial six
characters, leaving not column seven, but column one
as the comment column, and shifting the rest of the
file similarly.  That aside, AFAIU the initial six
columns utilization for line numbers is only a
(widely-used) convention; with that in mind wouldn't
they be any six characters, period?  When I used to
egrep COBOL I would start patterns with "^.{6}[^\*]";
you get the point.  There is a sourceforge project
which uses a... sable? Javacc? can't remember, parser
to generate an XML view of a COBOL copybook... I
haven't looked at it in several months (whew) but last
I checked it had matured quite a bit and could parse
most of what I threw at it... I think it's LGPLd so
you might be able to extend from it, maybe not...
http://sourceforge.net/projects/cb2xml

when searching for cb2xml I found that sourceforge now
hosts another project of similar description, too:
http://sourceforge.net/projects/copybooktoxml

Good luck,
Matt

--- "Putrycz, Erik" <Erik.Putrycz at nrc-cnrc.gc.ca>
wrote:

> I'm trying to adapt the Open COBOL grammar to ANTLR
> and I'm struggling a
> little... My goal is to build an AST of a COBOL
> program. I'm not too
> familiar with lexers/parsers... 
> 
> How can I deal with the line number that starts each
> line?
> 
> It seems in the OpenCobol grammar, it is suppressed
> by a pre-processor
> but I wouldn't mind having it in the AST.
> 
> How to build a Lexer rule for the line number?
> 
> Here is a COBOL line example
> 
> 000010 IDENTIFICATION DIVISION.
> 
> And I want to deal with the starting 6 numbers...
> 
>  
> 
> Thanks,
> 
>  
> 
> Erik Putrycz, Ph.D - Research Associate /
> <mailto:erik.putrycz at nrc-cnrc.gc.ca>
> erik.putrycz at nrc-cnrc.gc.ca / (613)
> 990 0681
> 
> Institute for Information Technology - Software
> Engineering Group
> 
> National Research Council, Canada - Building M-50,
> 1200 Montreal Road
> 
> Ottawa, Ontario, CANADA K1A 0R6
> 
>  
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the antlr-interest mailing list