Skip to content

Translator front-end bake-off: which COBOL parser should the det translator use? #4378

Closed

Description

@squid-protocol

Why

The det COBOL-to-Java translator parses COBOL with the tree-sitter grammar from tree_sitter_language_pack (det/layout.py for the DATA DIVISION, det/stmt.py for statements). Its layouts are byte-proven against GnuCOBOL, so it works where it parses. But on 2026-10-03 the grammar failed on 31 of 149 unported programs (25 in the DATA DIVISION, 6 in the PROCEDURE DIVISION: long continued literals, *> comments, SEARCH ALL, IDMS; #4273's experiment comment). Before the 4th CICS estate (the "one-shot" attempt), we should know whether a better front end exists, and decide it with data rather than swap blindly. The translator is a proven system, so any switch has to prove it is at least as good on everything that already works.

Candidates

Tool License Activity (Oct 2026) What it is Likely role
Eclipse Che4z COBOL LSP EPL-2.0 (weak copyleft; fine as an external, unmodified test tool) very active, Broadcom-backed Industrial IBM Enterprise COBOL parser: CICS, SQL, IDMS, DaCo, copybook preprocessing units, calls, CICS / SQL referee
mapa MIT active, single author ANTLR grammars for IBM Z COBOL, CICS APIs/SPIs and JCL, plus a call-tree tool (CALL, LINK, XCTL, SQL CALL, program inputs/outputs) network-map referee (call tree, CICS, JCL)
Spantree tree-sitter-cobol-enterprise MIT new (Apr 2026) Tree-sitter grammar for IBM Enterprise COBOL; EXEC CICS / SQL parsed into typed nodes; 65/66 CardDemo files parse parser referee; translator front-end candidate
ProLeap MIT stale (last release 2018) ANTLR4 AST + semantic graph (data and control flow); passes NIST COBOL-85; EXEC blocks kept as text data-flow referee
Cobrix Apache-2.0 active Copybook parser + EBCDIC reader: COMP-3, OCCURS DEPENDING ON, REDEFINES record-layout / byte-offset referee
cobol-rekt MIT active Reverse-engineering toolkit: flowcharts, control-flow analysis reachability / dead-code referee
TypeCobol CeCILL-C (LGPL-like) active Incremental IBM Enterprise COBOL 6 parser (C#) dialect-coverage reference
Not permissive: SuperBOL (AGPL), GnuCOBOL (GPL; already our oracle, run as a separate process) leave as is

The most natural drop-in is Spantree tree-sitter-cobol-enterprise: same tree-sitter API, IBM Enterprise COBOL, typed EXEC CICS / SQL nodes. The JVM parsers (Che4z, ProLeap, mapa) and TypeCobol would mean a bigger integration (a JVM or .NET bridge), offset by richer semantics (preprocessing, data / control flow).

Bake-off protocol (proposal)

  1. Corpus: the 149 programs where the current grammar failed or was never tried, the 54 det-ported programs, NIST CCVS85, and estate-crucible v0.3.0+ (incl. the multicultural / DBCS horrors).
  2. Per candidate, measure:
    • parse success (clean / partial / failure) per division;
    • no regression on the 54 ported programs: identical layouts (byte offsets, sizes, usages) and statement trees as today, proven by re-running the equivalence harness;
    • coverage of what the translator needs: EXEC CICS / SQL as typed structures vs text, COPY / REPLACING (today det/source.py expands it itself), nested / sibling programs, DECIMAL-POINT IS COMMA, national / DBCS (COBOL translator: national/DBCS data (USAGE NATIONAL, PIC N, DBCS literals) not modelled by the det port or the oracle register #4272);
    • speed per member (and memory, for ANTLR grammars on large members);
    • integration cost: Python binding vs JVM / .NET bridge, CI cost, maintenance health and license.
  3. Decision table: keep, replace, or hybrid (e.g. one parser for layouts and another for statements, or a fallback chain when the primary fails).

Open questions (brainstorm here)

Related: #4273, #4268-#4272 (translator breadth), #4048 (evidence records: a front-end change must re-prove every port), the referee-panel issue (#4377).

🤖 Generated with Claude Code

Activity

  1. added
    enhancement
    testing
    legacy-modernization
    on Oct 4, 2026
  2. squid-protocol commented on Oct 5, 2026

    @squid-protocol
    OwnerAuthor

    Phase 1 bake-off: measured, no switch

    Full report: /srv/storage_16tb/projects/gitgalaxy/bakeoff/bakeoff.md + bakeoff.json (tooling in bakeoff/tools/, not committed). Engine 575bba16a, language-pack 1.20.0 vs Spantree 86a2c479cb7e, each fed the translator's own DATA / PROC inputs. Nothing under gitgalaxy/tools/cobol_to_java/ changed.

    Programs usable (DATA and PROC both parse without ERROR)

    set current (today) Spantree current, else Spantree current fed proper fixed form (current_w) current_w, else Spantree
    det-ported (54) 54 48 54 54 54
    Oct 3 unported (149) 119 71 124 131 137
    NIST CCVS85 (150) 39 24 39 142 142
    estate-crucible v0.3.0 (23) 13 13 14 13 14
    • No regression in the Spantree DATA DIVISION adapter. The prototype adapter (layout.parse re-targeted to Spantree, about 215 lines) gives 0 diffs on the 54 ported programs: 16,794 items compared on offsets, sizes, usages, PIC, OCCURS / ODO, REDEFINES, VALUEs, 88s and SIGN, and all 54 record images are byte-identical. It is also at 0 diffs on 30,985 items across all four sets.
    • Spantree loses 6 of the 54 ported programs in the PROCEDURE DIVISION. The causes are STRING with a literal delimiter (DBCRFUN), MOVE ALL '9' (CUSTCTRL) and FUNCTION ANNUITY in an expression (epsmpmt).
    • It also breaks on:
      • DECLARATIVES, which wrecks the whole PROCEDURE DIVISION (94 CCVS programs);
      • PERFORM TEST AFTER VARYING;
      • PIC IS, where IS is lexed into the picture (71 CCVS programs);
      • FD RECORD n / LABEL RECORDS;
      • the zECS PROCEDURE DIVISION, even with the CBL card already dropped.
    • Spantree finds the same statements, but not the keywords stmt.py needs. Statement boundaries agree (47 of 48 ported programs give an identical set; paragraph lists are identical). But its keyword tokens are hidden terminals: ELSE, WHEN OTHER, END-x, AT END, THRU, ALL and the figurative constants never appear as nodes. So stmt.py's flat-stream walker would need a re-lexing flattening shim. Estimate: about 1 day for layout.py (the adapter is done), and 3–5 days for stmt.py plus re-proving all 54 ports. The stmt.py work is also blocked on the 6 ported PROC failures, which need grammar patches.
    • What Spantree does better is typed EXEC CICS / SQL: 603 of 603 on ported. Timing is the same for both (about 1 ms per member).
    • Most of today's failures come from the front end, not the grammar. det.source.as_fixed keeps joined continuation lines whole past column 72. Re-wrapping them into proper fixed form (literal continuation with -) lets the current grammar parse 12 of the 30 failing unported programs and 103 of the 111 failing CCVS programs:
      • None of the 54 ported programs has a line past column 72, so their parser input is byte-identical and there is zero regression risk on them.
      • All 355 re-wrapped VALUE literals decode verbatim.
      • Known gap: single-quoted continuations still fail (CBSTM03A).

    Recommendation:

    🤖 Generated with Claude Code

  3. squid-protocol commented on Oct 5, 2026

    @squid-protocol
    OwnerAuthor

    Decision: keep the current tree-sitter grammar. Closing.

    Phase 1 (full results in the comment above) measured:

    • Spantree's tree-sitter-cobol-enterprise parses fewer programs than the current grammar on 3 of 4 corpora.
    • Spantree fails on 6 already-proven ports (STRING delimiters, MOVE ALL, DECLARATIVES).
    • Switching would cost about a week, plus re-proving every port.

    The real lever is the translator's own input: re-wrapping joined continuation lines into proper fixed form in det/source.as_fixed raises current-grammar parses from 119 to 131 of 149 unported programs and from 39 to 142 of 150 NIST programs, with no change to ported-program input. That is tracked in #4412.

    Kept for later:

  4. added
    scope:core
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementlegacy-modernizationscope:coretesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions