Skip to content

det SORT / MERGE: EBCDIC and literal COLLATING SEQUENCE alphabets (#4268) - #4540

Merged
squid-protocol merged 4 commits into
mainfrom
feat/4268-sort-cobol
Oct 6, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
feat/4268-sort-cobol

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #4268 (COBOL statement side; the SORT / MERGE / RELEASE / RETURN parsers and SD files already landed in #4286).

What this adds

The det translator refused every SORT / MERGE COLLATING SEQUENCE (and PROGRAM COLLATING SEQUENCE) other than NATIVE / STANDARD-1. Now:

  • STANDARD-2 uses the data's byte order, the same as STANDARD-1 (GnuCOBOL measured identical over all 256 bytes).

  • ALPHABET x IS EBCDIC and literal alphabets (literals, multi-character literals, ascending or descending THRU, ALSO, SPACE / ZERO / QUOTE) now order the alphanumeric keys (alphanumeric, alphabetic, edited and all-character groups) through the new cobolrt/Sort.Collating. Numeric keys (zoned, packed, binary, signed) still compare by value, as IBM and GnuCOBOL both do.

  • Two orders, one answer. Sort.Collating keeps IBM's order and GnuCOBOL's:

    • IBM's order is code page 037. A THRU range and the characters the alphabet doesn't name follow the EBCDIC native order.
    • GnuCOBOL's order is its own EBCDIC table, measured over all 256 bytes, which differs on [ ] ^ | and every byte above X'7F'. For literal alphabets it follows the data's bytes.

    The port sorts by IBM's order. If the two orders put a pair of keys in different order, the run stops with a named error (register D1). Every neighbouring pair is re-checked after the sort, so a proven sort is IBM's order.

  • Refused with a named error: alphabet ordinals (numeric literals), HIGH-VALUE / LOW-VALUE in an alphabet, and a key that holds numeric or national items under an alphabet (packed and binary bytes aren't characters).

  • program.alphabets now keeps each definition's tokens, not just the first word.

Proof (GnuCOBOL oracle, cobc -std=ibm -fsign=EBCDIC)

  • SORTCS: EBCDIC and a literal alphabet over:
    • an alphanumeric key, with duplicates
    • a descending group key
    • a numeric major key with an edited minor key
    • an edited key
  • SORTPC: PROGRAM COLLATING SEQUENCE applied to a SORT that has no COLLATING phrase.
  • Both match GnuCOBOL's output in bytes, typed and groups modes.
  • Run-time refusal tests cover one EBCDIC disagreement (^) and one literal-alphabet disagreement (unnamed A vs z). Translate-time refusals are tested too, along with a parser unit test.
  • Already-landed coverage: SORTIP and SORTUG (USING/GIVING, input/output procedures, multiple keys, descending, duplicates, packed/signed/binary keys, MERGE).
  • Corpus: no mainframe-corpus program uses the SORT verb. The census doesn't measure SORT. The NIST CCVS SORT programs ST1084 and ST1184 translate their SORT statements fully (their only holes are WRITE ADVANCING), and ST3014 has no holes.

Gates

  • pr_gates.py: 7/7 pass.
  • pr_gates.py --ratchets: 6/6 pass (ports, port-surface, estate, fact-crosscheck, completeness, ground-truth), none skipped.
  • proof_sweep.py --det-only --skip-db2: as expected; the baseline is unchanged.
  • The generated text is unchanged for any SORT without a non-byte-order alphabet, so no committed port moves.

Register

  • F4 now says the SORT verbs are translated, and lists what is refused.
  • D1 now describes the alphabet orders.

Next slice (out of scope here)

JCL utility steps, refused by name today (JclSteps.utility):

  • DFSORT / ICETOOL control cards (SORT FIELDS, INCLUDE / OMIT, INREC / OUTREC, SUM)
  • IEBGENER
  • an IDCAMS REPRO / DEFINE subset in the oracle
  • a multi-step job case

Found on the way

#4539: the det translator ignores PROGRAM COLLATING SEQUENCE in alphanumeric relation conditions, silently (repro in the issue).

🤖 Generated with Claude Code

https://claude.ai/code/session_01W3KVtYHQp8KsfKcHsdiPbR

squid-protocol and others added 3 commits October 6, 2026 01:36
)

The det translator refused every SORT / MERGE COLLATING SEQUENCE (and PROGRAM
COLLATING SEQUENCE) other than NATIVE / STANDARD-1. Now:

- STANDARD-2 is the data's byte order, as STANDARD-1.
- ALPHABET ... IS EBCDIC and literal alphabets (literals, multi-character
  literals, THRU ascending or descending, ALSO, SPACE / ZERO / QUOTE) order
  the alphanumeric keys through a new Sort.Collating; numeric keys still
  compare by value.
- Sort.Collating keeps IBM's order (code page 037; THRU and the unnamed
  characters in EBCDIC native order) and GnuCOBOL's (its own EBCDIC table,
  measured over all 256 bytes; the data's bytes), sorts by IBM's, and stops
  the run by name on a pair the two order differently (register D1). Every
  neighbour pair is checked after the sort, whichever pairs TimSort compared.
- Refused by name: an alphabet ordinal, HIGH-VALUE / LOW-VALUE in an
  alphabet, a key holding numeric / national items under an alphabet.
- program.alphabets keeps each definition's tokens, not its first word.

Proof: SORTCS (EBCDIC and a literal alphabet over alphanumeric, descending
group, numeric + edited and edited keys) and SORTPC (PROGRAM COLLATING
SEQUENCE) equal GnuCOBOL's output in bytes, typed and groups modes; runtime
refusal tests for an EBCDIC and a literal-alphabet disagreement.

Register F4 updated: the SORT verbs are translated; JCL utility steps stay
refused by name (JclSteps.utility) and are the next slice.

Part of #4268

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01W3KVtYHQp8KsfKcHsdiPbR
@squid-protocol squid-protocol added enhancement New feature, sensor, or structural signature core-engine Modifications to the central physics and parsing engine legacy-modernization COBOL refractor, dead-code extraction, and JCL forging priority: high Core feature broken, but workarounds exist labels Oct 6, 2026
# Conflicts:
#	tests/cobol_mainframe/test_det_programs.py
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol marked this pull request as ready for review October 6, 2026 06:53
@squid-protocol
squid-protocol merged commit 65b4ee7 into main Oct 6, 2026
37 checks passed
@squid-protocol
squid-protocol deleted the feat/4268-sort-cobol branch October 6, 2026 06:53
squid-protocol added a commit that referenced this pull request Oct 6, 2026
…4539) (#4556)

The det translator compared alphanumeric operands in byte order whatever the
program's PROGRAM COLLATING SEQUENCE, silently. Now, under an EBCDIC or a
literal alphabet (#4540's Sort.Collating):

- The nonnumeric comparisons of IF, EVALUATE (conditions and THRU ranges),
  PERFORM UNTIL and condition-names (88 THRU ranges) go through
  Sort.Collating.relation: the shorter operand padded with spaces, IBM's
  order taken, operands IBM and GnuCOBOL order differently stopped by name
  (register D1). Items, literals, figurative constants, typed (lifted) items
  and function results alike.
- Numeric comparisons stay by value; national data is refused by the
  translator already. NATIVE / STANDARD-1 / STANDARD-2 stay byte order.
- An equality consults the alphabet only when it has ALSO (otherwise each
  character has its own position).
- Refused by name: HIGH-VALUE / LOW-VALUE under a literal alphabet (MOVE,
  VALUE -- the program --, comparisons, DISPLAY, STRING, INSPECT), an
  ordering of an item holding packed / binary / signed items, a comparison
  with an ALL literal, an ordinal alphabet.

Proof: PCSEB (EBCDIC), PCSLT (a literal alphabet with ALSO and descending
THRU), PCSS2 (STANDARD-2) and PCSRV (the issue's repro) equal GnuCOBOL's
output in bytes, typed and groups modes; on origin/main PCSEB, PCSLT and
PCSRV differ. Refusal tests at translation and run time.

Closes #4539


Claude-Session: https://claude.ai/code/session_01W3KVtYHQp8KsfKcHsdiPbR

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-engine Modifications to the central physics and parsing engine enhancement New feature, sensor, or structural signature legacy-modernization COBOL refractor, dead-code extraction, and JCL forging priority: high Core feature broken, but workarounds exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant