GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
cobol

COBOL: Repair edge-case bugs in parsing and validation

Fixes COBOL parser to handle missing quotes/parentheses and improves validation for CORRESPONDING clauses.

This commit addresses several edge-case bugs in the COBOL compiler. It enhances the lexer and parser to correctly handle missing closing parentheses and double or single quotes, improving robustness. Additionally, it tightens validation for ADD CORRESPONDING and SUBTRACT CORRESPONDING statements, rejecting operands that are not groups. A new warning flag, -Wrefmod, is introduced to flag invalid use of reference-modified strings as targets, aligning with ISO standards while accommodating common extensions.

In Details

This patch improves the COBOL frontend's error handling and validation. It fixes the lexer (scan.l, lexio.cc) and parser (parse.y) to gracefully manage missing closing delimiters (parentheses, quotes) in various contexts. A new diagnostic, -Wrefmod, is added to flag reference-modified strings used as targets, which is disallowed by the ISO standard but permitted by some compilers like IBM's and Micro Focus's. The validation for ADD/SUBTRACT CORRESPONDING in parse.y is strengthened to ensure both sender and receiver are group items.

For Context
lexer
The component of a compiler that reads the source code character by character and groups them into meaningful tokens (like keywords, identifiers, operators).
parser
The component of a compiler that takes a stream of tokens from the lexer and builds a hierarchical structure (like an Abstract Syntax Tree) representing the program's syntax.
reference-modified string
A COBOL string where a portion of its content is accessed using start position and length specifiers (e.g., STRING(3:5)).
CORRESPONDING clause
A COBOL clause used with statements like ADD or MOVE to operate on records or groups. It matches elements with the same name in both groups and performs the operation only on those matching elements.
group item
In COBOL, a data item that consists of subordinate items. It is used for organizational purposes and does not hold a value itself, but its subordinate items do.
Filed Under: cobolparserlexervalidationbugfix