uwol / proleap-cobol-parser

ProLeap ANTLR4-based parser for COBOL
MIT License
134 stars 72 forks source link

Control Flow Graph #92

Open baltaci-r opened 2 years ago

baltaci-r commented 2 years ago

Can this repo be extended to generate CFGs for COBOL?

uwol commented 2 years ago

Hi @baltaci-r , yes, I think analyzing the control flow of a COBOL program should be possible based on this repo. The abstract semantic graph contains static information about called paragraphs, data description read and write access etc.

This is repo is only the pure parser, i.e. a CFG generator would have to be developed. However, we did something comparable by writing COBOL pattern analysis rules for another project. If interested, let me know and we can take a look.

sundar7D0 commented 11 months ago

Yes, this seems interesting. Can you share more details on a COBOL CFG?

uwol commented 11 months ago

Hello @sundar7D0 ,

yes, in the meantime we published the pattern analysis source code. You can find it in this repo https://github.com/proleap/proleap-cobol

Best

sundar7D0 commented 11 months ago

Thanks for the prompt reply! My use-case is this where I want to convert a COBOL source code in a visualisable control flow graph, similar to this https://github.com/BroadcomMFD/cobol-control-flow. Is it possible with the tool you mentioned?

uwol commented 11 months ago

No, this is not possible with the code mentioned. Instead the code mentioned provides rules, which analyze the sorce code for patterns.

Such functionality is not implemented based on ProLeap, yet. However, it could be done quite easily, as the abstract semantic graph (ASG) contains all relevant information.

sundar7D0 commented 11 months ago

Can it be done even at the level of if-else within a function? What's the lowest level of granularity?

uwol commented 11 months ago

The lowest level of granularity is an individual token of the parser. So, yes, branches of IF statements are definitely contained in the ASG.

sundar7D0 commented 11 months ago

Ok great! I understood what's to be done. But I was looking for a solution which is tightly related to the original code-snippets; creating a control flow graph like described here: https://modeling-languages.com/wp-content/uploads/2013/09/paper-cameraready.pdf

Are you aware of any open-source tools that can already do this?

uwol commented 11 months ago

Hi, no, unfortunately I do not know such tools. I think it would be possible to rebuild the tool from the paper as the complete information is contained in the AST and ASG. In the end one would need to identify all next statements after a statement, and build a flow graph -> quite simply, should be doable in several days including assigning code fragments to the control flow graph nodes. The optical rendering or integration into an IDE would be a separate topic.

In case this is for a company feel free to contact me via email. Perhaps a cloud service or so could be build for this...

sundar7D0 commented 11 months ago

Thanks a lot uwol for your prompt response so far! I will get back to you if required. We are planning something open-source with COBOL modernisation, so will keep you posted

GLJay26 commented 9 months ago

@sundar7D0 did you got any solution for the flow.