I have to parse COBOL code in the aim of producing an easy and understandable overview of the program. I would like to use Java for its effienciency/security compromise. I am not aware of all the tools around, but I know having the right tool for this task will make things a lot easier!
So I need a tool to produce the function call graph, to me that means basically writing a parser... I think JavaCC is a good choice, there is also ANTLR... Can these tools creates the function call graph structure?
What's a good way to work with lexical analyzers in the aim of plotting the function call graph? I mean that I don't want to rewrite code that is already implemented in these tools but I am not aware of.
Thank you
Disclaimer: I am the maintainer of ProLeap COBOL parser.
You could use the Java-based ProLeap COBOL parser to extract calls to paragraphs, sections, data description entries etc. The parser will provide you with the call graph, however graphical plotting would have to be added.
So, for example this paragraph call ...
IDENTIFICATION DIVISION.
PROGRAM-ID. SECTIONCLL.
DATA DIVISION.
PROCEDURE DIVISION.
INIT.
PERFORM INIT.
... could be analysed with the following Java code, returning 1 call in this example:
package io.proleap.cobol.asg.call;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import org.junit.Test;
import io.proleap.cobol.CobolTestBase;
import io.proleap.cobol.asg.metamodel.CompilationUnit;
import io.proleap.cobol.asg.metamodel.Program;
import io.proleap.cobol.asg.metamodel.ProgramUnit;
import io.proleap.cobol.asg.metamodel.procedure.Paragraph;
import io.proleap.cobol.asg.metamodel.procedure.ProcedureDivision;
import io.proleap.cobol.asg.runner.impl.CobolParserRunnerImpl;
import io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnum;
public class ParagraphCallTest extends CobolTestBase {
@Test
public void test() throws Exception {
final File inputFile = new File("src/test/resources/io/proleap/cobol/asg/call/ParagraphCall.cbl");
final Program program = new CobolParserRunnerImpl().analyzeFile(inputFile, CobolSourceFormatEnum.TANDEM);
final CompilationUnit compilationUnit = program.getCompilationUnit("ParagraphCall");
final ProgramUnit programUnit = compilationUnit.getProgramUnit();
final ProcedureDivision procedureDivision = programUnit.getProcedureDivision();
final Paragraph paragraph = procedureDivision.getParagraph("Init");
assertNotNull(paragraph);
assertEquals(1, paragraph.getCalls().size());
}
}
The ProLeap COBOL parser is licensed under an open source license, so it can be used for free.