COBOL: Questions on how to interact with a method

63 views
Skip to first unread message

Dov Rosenberg

unread,
Jun 30, 2015, 11:52:52 AM6/30/15
to antlr-di...@googlegroups.com
I am using the ANTLR4 COBOL85 grammar. Below is a snippet of a COBOL file. I am trying to figure a few things about interacting with the file that I was hoping people can help me understand:

  1. How could I extract this whole block of code from the larger file? 
    • 200-IDENTIFY-TXNID seems to correspond to the PerformProcedureStatement listener. I cant seem to figure out how to get the text from all of the other rules that will be fired. seems like i need to deal with the children of PerformProcedure. Some sort of code snippet would be helpful to get an example of processing the text inside of each the various listeners
  2. It seems like the following triggers would occur, can someone confirm my understanding
    • PerformProcedure
    • EvaluateStatement (how do I get the stuff inside the WHEN argument?)
    • PerformProcedure
    • MoveStatement (how do I get the stuff inside the MOVE statement?)
My goal is I would like to be able be to grab chunks of code associated with the various statements. I just havent figured out the mojo required to grab the data I am looking for. Any pointers would be appreciated


 200-IDENTIFY-TXNID.
       >* *******************
       
       >* EVALUATE NOW IN HIGH-TO-LOW ORDER BY FREQUENCY
       >* WAJ - 4/02/2012
       
       EVALUATE A-TRAN-ID
       WHEN 'TS'
       PERFORM 7000-PROCESS-TS-TXN THRU
       7000-PROCESS-TS-TXN-EXIT
       WHEN 'MW'
       PERFORM 3000-PROCESS-MW-TXN THRU
       3000-PROCESS-MW-TXN-EXIT
       ...
       END-EVALUATE.
       
       MOVE FUNCTION CURRENT-DATE (9:6) TO W-TIME.
       DISPLAY W-TIME ','
       A-TRAN-ID ','
       WS-RECNUM.
       
       200-IDENTIFY-TXNID-EXIT.
       EXIT.

Raz Friman

unread,
Jun 30, 2015, 11:21:22 PM6/30/15
to antlr-di...@googlegroups.com
I believe you can use a visitor and manipulate the context for each of the rules you want to extra.

So when you visit the EvaluateStatement, you can access the context and call:
context.statement() to get a list of all the statement contexts that are children of the evaluateStatement.


If you are looking to get all the text associated with the paragraph 200-IDENTITY-TXNID, implement the part for the visitor of the paragraph rule and then you can access:
context.paragraphName()  and context.sentence(). Then for each sentence you can call the sentence.statement() contexts.

Hope that helps a bit
Reply all
Reply to author
Forward
0 new messages