Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ProLeap ANTLR4-based parser for COBOL

License

NotificationsYou must be signed in to change notification settings

uwol/proleap-cobol-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is aCOBOL parser based on anANTLR4 grammar,which generates anAbstract Syntax Tree (AST) andAbstract Semantic Graph (ASG) for COBOL code.The AST represents plain COBOL source code in a syntax tree structure.The ASG is generated from the AST bysemantic analysis and provides data and controlflow information (e. g. variable access). EXEC SQL, EXEC SQLIMS and EXEC CICSstatements are extracted as texts.

The parser is developed test-driven, passes theNIST test suite and has successfully beenapplied to numerous COBOL files from banking and insurance. It is used by theProLeap analyzer, interpreter & transformer for COBOL.

💫Star if you like our work.

License: MITProLeap on Twitter

Example

Input: COBOL code

 Identification Division. Program-ID.  HELLOWORLD. Procedure Division.  Display "Hello world".  STOP RUN.

Output: Abstract Syntax Tree (AST)

(startRule  (compilationUnit    (programUnit      (identificationDivision Identification Division .        (programIdParagraph Program-ID .          (programName            (cobolWord HELLOWORLD)) .))      (procedureDivision Procedure Division .        (procedureDivisionBody          (paragraphs            (sentence              (statement                (displayStatement Display                  (displayOperand                    (literal "Hello world")))) .)            (sentence              (statement                (stopStatement STOP RUN))) .)))))) <EOF>)

Getting started

To include the parser in your Maven project build it and add the dependency:

<dependency>  <groupId>io.github.uwol</groupId>  <artifactId>proleap-cobol-parser</artifactId>  <version>4.0.0</version></dependency>

Use the following code as a starting point for developing own code.

Simple: Generate an Abstract Semantic Graph (ASG) from COBOL code

// generate ASG from plain COBOL codejava.io.FileinputFile =newjava.io.File("src/test/resources/io/proleap/cobol/asg/HelloWorld.cbl");io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnumformat =io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnum.TANDEM;io.proleap.cobol.asg.metamodel.Programprogram =newio.proleap.cobol.asg.runner.impl.CobolParserRunnerImpl().analyzeFile(inputFile,format);// navigate on ASGio.proleap.cobol.asg.metamodel.CompilationUnitcompilationUnit =program.getCompilationUnit("HelloWorld");io.proleap.cobol.asg.metamodel.ProgramUnitprogramUnit =compilationUnit.getProgramUnit();io.proleap.cobol.asg.metamodel.data.DataDivisiondataDivision =programUnit.getDataDivision();io.proleap.cobol.asg.metamodel.data.datadescription.DataDescriptionEntrydataDescriptionEntry =dataDivision.getWorkingStorageSection().getDataDescriptionEntry("ITEMS");IntegerlevelNumber =dataDescriptionEntry.getLevelNumber();

Complex: Generate an Abstract Semantic Graph (ASG) and traverse the Abstract Syntax Tree (AST)

// generate ASG from plain COBOL codejava.io.FileinputFile =newjava.io.File("src/test/resources/io/proleap/cobol/asg/HelloWorld.cbl");io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnumformat =io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnum.TANDEM;io.proleap.cobol.asg.metamodel.Programprogram =newio.proleap.cobol.asg.runner.impl.CobolParserRunnerImpl().analyzeFile(inputFile,format);// traverse the ASTio.proleap.cobol.CobolBaseVisitor<Boolean>visitor =newio.proleap.cobol.CobolBaseVisitor<Boolean>() {@OverridepublicBooleanvisitDataDescriptionEntryFormat1(finalio.proleap.cobol.CobolParser.DataDescriptionEntryFormat1Contextctx) {io.proleap.cobol.asg.metamodel.data.datadescription.DataDescriptionEntryentry = (io.proleap.cobol.asg.metamodel.data.datadescription.DataDescriptionEntry)program.getASGElementRegistry().getASGElement(ctx);Stringname =entry.getName();returnvisitChildren(ctx);  }};for (finalio.proleap.cobol.asg.metamodel.CompilationUnitcompilationUnit :program.getCompilationUnits()) {visitor.visit(compilationUnit.getCtx());}

Where to look next

How to cite

Please cite ProLeap COBOL parser in your publications, if it helps your research. Here is an example BibTeX entry:

@misc{wolffgang2018cobol,  title={ProLeap COBOL parser},  author={Wolffgang, Ulrich and others},  year={2018},  howpublished={\url{https://github.com/uwol/proleap-cobol-parser}},}

Features

  • EXEC SQL statements,EXEC SQLIMS statements andEXEC CICS statements are extracted by the preprocessor and provided as texts in the ASG.
  • Passes theNIST test suite.
  • Rigorous test-driven development.
  • To be used in conjunction with the provided preprocessor, which executesCOPY,REPLACE,CBL andPROCESS statements.

Build process

The build process is based on Maven (version 3 or higher). Building requires a JDK 17 and generates a Maven JAR, which can be used in other Maven projects as a dependency.

  • Clone or download the repository.
  • InEclipse import the directory as a anexisting Maven project.
  • To build, run:
$ mvn clean package
  • The test suite executes AST and ASG tests against COBOL test code and NIST test files. NIST test files come fromKoopa repo. Unit tests and parse tree files were generated by classio.proleap.cobol.TestGenerator from COBOL test files. The generator derives the COBOL line format from the containing folder name.
  • You should see output like this:
[INFO] Scanning for projects......------------------------------------------------------- T E S T S-------------------------------------------------------Running io.proleap.cobol.ast.fixed.FixedTestPreprocessing file Fixed.cbl.Parsing file Fixed.cbl.Comparing parse tree with file Fixed.cbl.tree.Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.202 secRunning io.proleap.cobol.ast.fixed.QuotesInCommentEntryTest...Results :Tests run: 680, Failures: 0, Errors: 0, Skipped: 0[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------
  • To install the JAR in your local Maven repository:
$ mvn clean install
  • To only run the tests:
$ mvn clean test

Release process

License

Licensed under the MIT License. See LICENSE for details.

About

ProLeap ANTLR4-based parser for COBOL

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp