Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@

2026-03-16 Uttam Singh Bhadauriya <uttamsinghbhadoriya23@gmail.com>

* cobc/pplex.l: add EXEC_STATE exclusive start condition to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please drop the cobc/ prefix here - as that is the place where that Changelog is

tokenize EXEC <TAG> ... END-EXEC blocks; add AREA_A lookahead
rule for EXEC; return INCLUDE token for INCLUDE keyword,
plain TOKEN for words; consume all other content silently
* cobc/ppparse.y: add exec_statement grammar rule dispatched
from statement_no_replace; EXEC TAG INCLUDE handled as COPY
(full copybook expansion with -I and -ffold-copy support);
all other EXEC TAG blocks warn at "unsupported" level
(defaulting to error) and are ignored; add _exec_token_list
to consume body tokens for parsing purposes only

2025-12-29 Roger Bowler <rbowler@snipix.net>

* tree.c (finalize_file): if file is EXTFH enabled then don't warn for
Expand Down
15 changes: 15 additions & 0 deletions cobc/pplex.l
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ MAYBE_AREA_A [ ]?#?
%x CONTROL_STATEMENT_STATE
%x DISPLAY_DIRECTIVE_STATE
%x IMP_DIRECTIVE_STATE
%X EXEC_STATE

%%

Expand Down Expand Up @@ -501,6 +502,7 @@ MAYBE_AREA_A [ ]?#?
^{AREA_A}[ \n]*/"COPY"[ ,;\n] { count_newlines (yytext); }
^{AREA_A}[ \n]*/"INCLUDE"[ ,;\n] { count_newlines (yytext); }
^{AREA_A}[ \n]*/"REPLACE"[ ,;\n] { count_newlines (yytext); }
^{AREA_A}[ \n]*/"EXEC"[ ,;\n] { count_newlines (yytext); }

"COPY"/[ ,;\n] {
yy_push_state (COPY_STATE);
Expand All @@ -525,6 +527,11 @@ MAYBE_AREA_A [ ]?#?
return REPLACE;
}

"EXEC"/[ ,;\n] {
BEGIN(EXEC_STATE);
return EXEC;
}

^{MAYBE_AREA_A}.{6}[ ]*"*CONTROL" |
^{MAYBE_AREA_A}.{6}[ ]*"*CBL" {
BEGIN CONTROL_STATEMENT_STATE;
Expand Down Expand Up @@ -569,6 +576,14 @@ MAYBE_AREA_A [ ]?#?
}
}

<EXEC_STATE>{
"END-EXEC"([ \t]*\.)? { BEGIN (INITIAL); return END_EXEC; }
"INCLUDE" { return INCLUDE; }
[A-Za-z0-9][A-Za-z0-9-]* { pplval.s = cobc_plex_strdup (yytext); return TOKEN; }
\n { newline_count++; }
. { /* silently consumed */ }
}

<SUBSTITUTION_SECTION_STATE,
CONTROL_DIVISION_STATE>{
"REPLACE" {
Expand Down
32 changes: 32 additions & 0 deletions cobc/ppparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ ppparse_clear_vars (const struct cb_define_struct *p)
%token <s> VARIABLE_NAME "Variable"
%token <s> LITERAL "Literal"

%token EXEC
%token END_EXEC

%type <s> _copy_in
%type <s> copy_source
%type <s> _literal
Expand Down Expand Up @@ -830,6 +833,7 @@ statement:

statement_no_replace:
copy_statement
| exec_statement
| directive TERMINATOR
| listing_statement
| CONTROL_STATEMENT control_options _dot TERMINATOR
Expand Down Expand Up @@ -1726,6 +1730,34 @@ replacing_list:
}
;

_exec_token_list:
/* empty */
| _exec_token_list TOKEN
{
/* should be handled by preparser, ignored
if seen here purely for parsing reasons */
}
;

exec_statement:
EXEC TOKEN INCLUDE copy_source END_EXEC
{
/* EXEC TAG INCLUDE copybook — handle as COPY */
fputc ('\n', ppout);
ppcopy ($4, NULL, NULL);
}
| EXEC TOKEN _exec_token_list END_EXEC
{
/* EXEC TAG ... END-EXEC — warn and ignore */
cb_warning (cb_warn_unsupported,
_("EXEC %s statement ignored - no preprocessor configured"), $2);
}
| EXEC error END_EXEC
{
yyerrok;
}
;

text_src:
EQEQ token_list EQEQ
{
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ testsuite_sources = \
testsuite.src/used_binaries.at \
testsuite.src/configuration.at \
testsuite.src/syn_copy.at \
testsuite.src/syn_extensions.at \
testsuite.src/syn_definition.at \
testsuite.src/syn_file.at \
testsuite.src/syn_functions.at \
Expand Down
205 changes: 205 additions & 0 deletions tests/test84.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and the other C files are unrelated, should be deleted

Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/* Generated by cobc 3.3-dev.0 */
/* Generated from /tmp/test84.cob */
/* Generated at Mar 16 2026 17:05:35 */
/* GnuCOBOL build date Mar 16 2026 06:59:39 */
/* GnuCOBOL package date Mar 16 2026 01:29:28 UTC */
/* Compile command /home/utam1/gnucobol/cobc/.libs/cobc -C -Wno-error=unsupported /tmp/test84.cob */

#include <string.h> /* for memcpy, memcmp and friends */
#define COB_KEYWORD_INLINE inline
#include <libcob.h>

#define COB_SOURCE_FILE "/tmp/test84.cob"
#define COB_PACKAGE_VERSION "3.3-dev"
#define COB_PATCH_LEVEL 0
#define COB_MODULE_FORMATTED_DATE "Mar 16 2026 17:05:35"
#define COB_MODULE_DATE 20260316
#define COB_MODULE_TIME 170535

/* Global variables */
#include "test84.c.h"

/* Function prototypes */

COB_EXT_EXPORT int prog (void);
static int prog_ (const int);
static void prog_module_init (cob_module *module);

/* Functions */

static void gc_module_so_init () __attribute__ ((constructor));
static void gc_module_so_init ()
{
cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL);
}

/* PROGRAM-ID 'prog' */

/* ENTRY 'prog' */

int
prog ()
{
return prog_ (0);
}

static int
prog_ (const int entry)
{
/* Program local variables */
#include "test84.c.l.h"

/* Start of function code */

/* CANCEL callback */
if (unlikely(entry < 0)) {
if (entry == -10)
goto P_dump;
if (entry == -20)
goto P_clear_decimal;
goto P_cancel;
}

/* Check initialized, check module allocated, */
/* set global pointer, */
/* push module stack, save call parameter count */
if (cob_module_global_enter (&module, &cob_glob_ptr, 0, entry, 0))
return -1;

/* Set address of module parameter list */
module->cob_procedure_params = cob_procedure_params;

/* Set frame stack pointer */
frame_ptr = frame_stack;
frame_ptr->perform_through = 0;
frame_ptr->return_address_ptr = &&P_cgerror;

/* Initialize rest of program */
if (unlikely(initialized == 0)) {
goto P_initialize;
}
P_ret_initialize:

/* Increment module active */
module->module_active++;

/* Entry dispatch */
goto l_2;

/* PROCEDURE DIVISION */

/* Line: 5 : Entry prog : /tmp/test84.cob */
l_2:;

/* Line: 5 : STOP RUN : /tmp/test84.cob */
cob_stop_run (b_2);

/* Program exit */

/* Decrement module active count */
if (module->module_active) {
module->module_active--;
}

/* Pop module stack */
cob_module_leave (module);

/* Program return */
return b_2;
P_cgerror:
cob_fatal_error (COB_FERROR_CODEGEN);


/* Program initialization */
P_initialize:

prog_module_init (module);

module->collating_sequence = NULL;
module->crt_status = NULL;
module->cursor_pos = NULL;
module->xml_code = NULL;
module->xml_event = NULL;
module->xml_information = NULL;
module->xml_namespace = NULL;
module->xml_namespace_prefix = NULL;
module->xml_nnamespace = NULL;
module->xml_nnamespace_prefix = NULL;
module->xml_ntext = NULL;
module->xml_text = NULL;
module->json_code = NULL;
module->json_status = NULL;

/* Initialize cancel callback */
cob_set_cancel (module);

/* Initialize WORKING-STORAGE */
/* initialize field RETURN-CODE */
b_2 = 0;


if (0 == 1) goto P_cgerror;
initialized = 1;
goto P_ret_initialize;

P_dump:
return 0;


/* CANCEL callback handling */
P_cancel:

if (!initialized)
return 0;
if (module && module->module_active)
cob_fatal_error (COB_FERROR_CANCEL);

b_2 = 0;
cob_module_free (&module);

initialized = 0;

P_clear_decimal:
return 0;

}

/* End PROGRAM-ID 'prog' */

/* Initialize module structure for prog */
static void prog_module_init (cob_module *module__)
{
module__->module_name = "prog";
module__->module_formatted_date = COB_MODULE_FORMATTED_DATE;
module__->module_source = COB_SOURCE_FILE;
module__->gc_version = COB_PACKAGE_VERSION;
module__->module_entry.funcptr = (void *(*)())prog;
module__->module_cancel.funcptr = (void *(*)())prog_;
module__->module_ref_count = NULL;
module__->module_path = &cob_module_path;
module__->module_active = 0;
module__->module_date = COB_MODULE_DATE;
module__->module_time = COB_MODULE_TIME;
module__->module_type = 0;
module__->module_param_cnt = 0;
module__->ebcdic_sign = 0;
module__->decimal_point = '.';
module__->currency_symbol = '$';
module__->numeric_separator = ',';
module__->flag_filename_mapping = 1;
module__->flag_binary_truncate = 1;
module__->flag_pretty_display = 1;
module__->flag_host_sign = 0;
module__->flag_no_phys_canc = 0;
module__->flag_main = 0;
module__->flag_fold_call = 0;
module__->flag_exit_program = 0;
module__->flag_debug_trace = 0;
module__->flag_dump_ready = 0;
module__->xml_mode = 1;
module__->module_stmt = 0;
module__->module_sources = NULL;
}

/* End functions */

13 changes: 13 additions & 0 deletions tests/test84.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Generated by cobc 3.3-dev.0 */
/* Generated from /tmp/test84.cob */
/* Generated at Mar 16 2026 17:05:35 */
/* GnuCOBOL build date Mar 16 2026 06:59:39 */
/* GnuCOBOL package date Mar 16 2026 01:29:28 UTC */
/* Compile command /home/utam1/gnucobol/cobc/.libs/cobc -C -Wno-error=unsupported /tmp/test84.cob */


/* Module path */
static const char *cob_module_path = NULL;

/* Number of call parameters */
static int cob_call_params = 0;
41 changes: 41 additions & 0 deletions tests/test84.c.l.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Generated by cobc 3.3-dev.0 */
/* Generated from /tmp/test84.cob */
/* Generated at Mar 16 2026 17:05:35 */
/* GnuCOBOL build date Mar 16 2026 06:59:39 */
/* GnuCOBOL package date Mar 16 2026 01:29:28 UTC */
/* Compile command /home/utam1/gnucobol/cobc/.libs/cobc -C -Wno-error=unsupported /tmp/test84.cob */

/* Program local variables for 'prog' */

/* Module initialization indicator */
static unsigned int initialized = 0;

/* Module structure pointer */
static cob_module *module = NULL;

/* Global variable pointer */
cob_global *cob_glob_ptr;


/* LINKAGE SECTION (Items not referenced by USING clause) */
static unsigned char *b_9 = NULL; /* XML-NAMESPACE */
static unsigned char *b_10 = NULL; /* XML-NAMESPACE-PREFIX */
static unsigned char *b_11 = NULL; /* XML-NNAMESPACE */
static unsigned char *b_12 = NULL; /* XML-NNAMESPACE-PREFIX */
static unsigned char *b_13 = NULL; /* XML-NTEXT */
static unsigned char *b_14 = NULL; /* XML-TEXT */


/* Call parameters */
cob_field *cob_procedure_params[1];

/* Perform frame stack */
struct cob_frame *frame_ptr;
struct cob_frame frame_stack[255];


/* Data storage */
static int b_2; /* RETURN-CODE */

/* End of local data storage */

1 change: 1 addition & 0 deletions tests/testsuite.at
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ m4_include([configuration.at])
AT_BANNER([Syntax tests])

m4_include([syn_copy.at])
m4_include([syn_extensions.at])
m4_include([syn_definition.at])
m4_include([syn_subscripts.at]) # 8.4.1.2 Subscripts
m4_include([syn_occurs.at]) # 13.16.36 OCCURS clause
Expand Down
Loading
Loading