cobol: Recognize user-defined words that are almost numeric literals.
GCC's COBOL compiler now correctly parses user-defined words that resemble numeric literals.
This commit enhances the GCC COBOL compiler’s lexical analysis to correctly identify user-defined words that are composed entirely of digits but may contain a single period, distinguishing them from floating-point literals. Previously, such constructs could be misidentified, leading to parsing errors or incorrect tokenization. The change ensures that names like ‘2E0’ are treated as valid user-defined words, not numeric literals, fixing RT 3727.
In Details
COBOL's scanner (scan.l) needs to differentiate between user-defined words and numeric literals. The grammar allows all-numeric user-defined words if they contain at least one letter. This fix addresses cases where a user-defined word is all-numeric with a decimal point (e.g., '2.0'), ensuring it's tokenized as a NAME rather than a floating-point literal when it doesn't conform to the floating-point syntax. This involves changes in scan.l, scan_ante.h, and a new helper function lex_numeric_literal.
- user-defined words
- Identifiers chosen by the programmer in COBOL, such as data item names or procedure names.
- numeric literals
- Constants that represent numerical values, like '123' or '45.67'.
- floating-point literal
- A numeric literal that represents a number in scientific notation, e.g., '2.5E-3'.
- scanner
- The part of a compiler that reads the source code and breaks it down into a sequence of tokens.
- token
- A basic lexical unit of a programming language, such as an identifier, keyword, operator, or literal.