[gcc r17-3446] cobol: Resurrect TITLE recognition for -dialect ibm.

"James K. Lowden via Gcc-cvs" <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:5d00c70da384d59f6caf9db5bf95a9355495aea5

commit r17-3446-g5d00c70da384d59f6caf9db5bf95a9355495aea5
Author: James K. Lowden <[email protected]>
Date:   Wed Aug 19 17:30:18 2026 -0400

    cobol: Resurrect TITLE recognition for -dialect ibm.
    
    TITLE had been recognized too much as an obsolete keyword and was
    removed entirely. Restore it for Identification Division only, as
    one-line comment.
    
    gcc/cobol/ChangeLog:
    
            * parse_ante.h (in_procedure_division): Position alphabetically.
            (in_identification_division): New function.
            (in_file_section): Remove void argument declaration.
            * scan.l: Add TITLE pattern and accept as NAME outside ID Division.
            * scan_ante.h (in_procedure_division): Remove void argument declaration.
            (in_environment_division): Same.
            (in_identification_division): Declare new function.

Diff:
---
 gcc/cobol/parse_ante.h | 10 +++++++---
 gcc/cobol/scan.l       | 19 +++++++++++++++++++
 gcc/cobol/scan_ante.h  |  6 ++++--
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h
index c2cb3437d0b7..243f43bbf1e7 100644
--- a/gcc/cobol/parse_ante.h
+++ b/gcc/cobol/parse_ante.h
@@ -256,16 +256,20 @@ is_cobol_charset( const char name[] ) {
 }
 
 bool
-in_procedure_division() {
-  return current_division == procedure_div_e;
+in_identification_division() {
+  return current_division == identification_div_e;
 }
 bool
 in_environment_division() {
   return current_division == environment_div_e;
 }
+bool
+in_procedure_division() {
+  return current_division == procedure_div_e;
+}
 
 static inline bool
-in_file_section(void) { return current_data_section == file_datasect_e; }
+in_file_section() { return current_data_section == file_datasect_e; }
 
 static cbl_refer_t *
 intrinsic_inconsistent_parameter( size_t n, cbl_refer_t *args );
diff --git a/gcc/cobol/scan.l b/gcc/cobol/scan.l
index 27de05d2ac73..3a1c5d376ef6 100644
--- a/gcc/cobol/scan.l
+++ b/gcc/cobol/scan.l
@@ -156,6 +156,8 @@ TIME_FMT   {TIME_FMT_B}|{TIME_FMT_E}
 
 DATETIME_FMT ({DATE_FMT_B}T{TIME_FMT_B})|({DATE_FMT_E}T{TIME_FMT_E})
 
+TITLE    TITLE({EOL}|[^\n[:alnum:]$_-].+)
+
 NAME      [[:alnum:]]+([_-]+[[:alnum:]]+)*
 SUBELEMS  {NAME}({SPC}{NAME})*
 
@@ -274,6 +276,23 @@ PROGRAM-ID{OSPC}{DOTSEP}?	{ yy_push_state(ident_state);
         	          	  yy_push_state(name_state); return PROGRAM_ID; }
 
 <*>{
+  {TITLE} 	{   // In Identification Section TITLE is commentary, else it's a name.
+		    if( in_identification_division() ) {
+                      if( ! dialect_ibm() ) {
+                        warn_msg(yylloc, "ignored TITLE: %qs", yytext);
+                      }
+                    } else {
+		      auto p = std::find_if( yytext, yytext + yyleng,
+		                        []( char ch ) {
+		                          return ! is_name_char(ch);
+		                        } );
+                      auto keep = p - yytext;
+                      myless(keep);
+                      auto s = xstrdup(yytext);
+                      ydflval.string = yylval.string = s;
+                      return NAME;
+                    }
+		}
   PROCEDURE{SPC}DIVISION	{ yy_push_state(procedure_div);
                                   return PROCEDURE_DIV; }
 }
diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h
index 74b5ddd5d30b..39570771f1e4 100644
--- a/gcc/cobol/scan_ante.h
+++ b/gcc/cobol/scan_ante.h
@@ -1140,8 +1140,10 @@ symbol_function_token( const char name[] ) {
   return 0;
 }
 
-bool in_procedure_division(void);
-bool in_environment_division(void );
+bool
+in_identification_division();
+bool in_procedure_division();
+bool in_environment_division();
 
 static const char *
 symbol_lower_name( const symbol_elem_t *e, cbl_name_t lname ) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.