COBREX is a tool to extract business rules from a COBOL program. The business logic incorporated in the source code is known as business rules. Understanding these business rules can aid with source code comprehension. An essential stage in legacy system migration is extracting business rules from existing COBOL systems. To this end, we developed COBREX, an open-source tool for building the CFG of an input COBOL program and extracting the embedded business rules. COBOL developers can use COBREX to extract business rules of a COBOL program and can analyze the extracted business rules to comprehend the COBOL program. These extracted business rules can also aid COBOL developers in bug location and resolution in turn helping them in maintenance of COBOL legacy systems.
Create and activate a new python3 virtual environment:
python(3) -m venv
<path_to_env/env_name></path_to_env>
Clone or download this github repository:
git clone
https://github.com/rishalab/COBREX-CLI.git
Get into the main directory:
cd COBREX-CLI
Install the requirements:
pip install -r requirements.txt
Install GnuCOBOL .
Install Graphviz .
Run COBREX:
python(3) extractor.py input_cobol_file_path
COBREX has been developed using Python using the following approach:
COBREX can be divided into three main phases as illustrated in the above figure.
In the first phase, ANTLR4 is used to create a COBOL parser using the COBOL85 grammar. The input COBOL program is preprocessed using the GnuCOBOL pre-processor. Then, the pre-processed file is processed by the parser to produce the AST.
In the next phase, we override the AST node visitor methods present in the visitor class created by ANTLR4. We utilise these AST node visitor methods to perform COBOL data division analysis, identify business variables and construct the Control Flow Graph(CFG). We also identify the context statements for each COBOL statement present in the input COBOL program.
In this phase, we extract the business rules of the input business variables using the constructed CFG. All statements and their corresponding context statements of a business variable are added to a Rules set. Depth First Search (DFS) is performed on the CFG to identify and add the control flow between the statements present in the Rules set.
The business rules in the above figure show that new-eff-in and old-eff-in are taken as input from the user using the accept statement. They are then processed to produce new-eff and old-eff, respectively. A series of checks are performed on both new-eff and old-eff variables. The numerator is then calculated by subtracting old-eff from new-eff. The numerator is divided by new-eff to calculate pcteff. Then, pcteff is multiplied by 100 and moved to pct-eff-out, which represents the percentage of fuel savings. By analyzing the extracted business rules, we can comprehend the business result the COBOL code in FUELSAVE.cbl is calculating. We can also use the business rules to identify the statements that are potentially causing a bug. For example, assume that the statement "divide numerator by new-eff giving pcteff rounded" causes a divide-by-zero exception during FUELSAVE.cbl execution. In this situation, we can examine the business rule of the new-eff variable to determine the possible cause of the exception and the COBOL statements that caused it.