[antlr-interest] COBOL question

Andy Tripp antlr at jazillian.com
Sat Feb 11 14:33:42 PST 2006


Putrycz, Erik 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 / 
> ****erik.putrycz at nrc-cnrc.gc.ca** 
> <mailto: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
>
I recently started a ANTLR COBOL grammar.
It's derived from this sorta-BNF grammar:
http://www.cs.vu.nl/grammars/vs-cobol-ii/#gdef:data-description-entry
It compiles with ANTLR, but gets zillions of ambiguity warnings, so
needs some major left-factoring. I'd be happy to collaborate if
anyone wants to, just send me email. I don't have any plans to
go further with it.

As for your question about lexing line numbers, yes, I think you'll need to
do that "by hand" first. You could check out Cobol for GCC:
http://cobolforgcc.sourceforge.net/
...or, what appears to be better...OpenCOBOL:
http://www.opencobol.org


More information about the antlr-interest mailing list