A JavaCC grammar for Cobol

15 Jun 2006

While working on my JavaCC book I came across a JavaCC grammar for parsing Cobol programs. It's a pretty hefty grammar file - over 50 KB - with a ton of productions. I ran it through JJDoc and you can see that report as well.

I thought a couple of things were interesting:

  • The global lookahead setting is 4, which is a lot more than you usually see.
  • There are no lexical states (other than DEFAULT, of course).
  • Whitespace seems to be handled entirely through SPECIAL_TOKEN - no SKIP or MORE. I think that results in a lot of extra Token creation... but maybe that sort of thing is not a big deal these days.

I tried to contact the author to see if he would mind me putting the grammar on the JavaCC grammars page, but the email bounced. Bernard Pinon, if you see this, nice work, please drop me a line and let me know if this grammar can live on the JavaCC site :-)

Update 3/30/09: Got an email from Bernard, grammar is here now, and he gave me permission to repost it on the JavaCC example grammars page. Thanks Bernard!