Basic questions regarding Cobol85

37 views
Skip to first unread message

Pedro Lacerda

unread,
Jun 21, 2016, 1:45:38 AM6/21/16
to antlr-di...@googlegroups.com
Hi List,

I need the CICS LINK command support for my analysis tool and tried to define it at Cobol85Preprocessor.g4.

You can see the relevant modifications at:

I this example code:

EXEC CICS LINK
    PROGRAM  ("PROGRAM")
    COMAREA  (WRK-AREA)
    LENGTH   (LENGTH OF WRK-AREA)
END-EXEC

And I'm getting the same error message for both roles execCicsStatement and startRule:
line 2:14 mismatched input '"PROGRAM"' expecting {STRINGLITERAL, IDENTIFIER}

But with different diagnostic trees:

I'm having trouble when matching a STRINGLITERAL, and also the differences between startRule and execCicsStatement as in the pictures.

Isn't a problem but when matching SYSTEMLITERAL alone it doesn't states exceeding characters as errors as seen in the following picture:


Thanks in advance,
Pedro Lacerda

Mike Cargal

unread,
Jun 21, 2016, 8:49:30 AM6/21/16
to ANTLR List
I’ve not followed your links, so forgive me for the quick answer that may miss something you’re already taking into account.

My *suspicion* would be that you’re tripping over “PROGRAM” being a COBOL reserved word, and the Lexer is identifying it as such, and consequently, not seeing it as an “IDENTIFIER” .

For things like the CICS preprocessor, you may need to implement an Island Grammar and switch to it.  (Of course, another alternative might be to handle it like the CICS preprocessor does, and run a parser designed only to recognize the embedded CICS commands and convert them to valid COBOl before handing it off to the COBOL compiler.)

The bottom line is that the “EXEC” … “END-EXEC” is not really valid COBOL and needs to be handled by independent parsing.

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pedro Lacerda

unread,
Jun 21, 2016, 10:50:19 AM6/21/16
to antlr-di...@googlegroups.com
 Island grammars really seems a better approach than mixed rules.

But the grammar is really identifying "PROGRAM" as a cicsName but can't recognize it as STRINGLITERAL or IDENTIFIER. Probably isn't the lexer that is misidentifying it because "OTHERNAME" raises the same error as "PROGRAM".

Another question is how to match a set of optional rules in any order, for a few rules is okay to permutate all options but it quickly grows ulgy:

  ( r1? r2?
  | r2? r1?)

I'm currently using (r1 | r2)* but an option can be present many times and not only one.

Thank you

Mike Cargal

unread,
Aug 20, 2016, 4:30:14 PM8/20/16
to antlr-discussion
Generally for cases like this (r1 | r2)* is just fine for the grammar.  It's common to try to put too much specification in to your grammar.  The main thing to accomplish in the grammar is to get everything properly recognized and categorized.  Then, in your own code you can implement further validation rules (generally providing better error messages than ANTLR would be able to provide if you could code this detail into your grammar.
Reply all
Reply to author
Forward
0 new messages