Skip to content

Added initial EXEC preprocessor handling logic in pplex and ppparse.#279

Draft
utam-1 wants to merge 4 commits intoOCamlPro:gitside-gnucobol-3.xfrom
utam-1:exec-preprocessor-patch
Draft

Added initial EXEC preprocessor handling logic in pplex and ppparse.#279
utam-1 wants to merge 4 commits intoOCamlPro:gitside-gnucobol-3.xfrom
utam-1:exec-preprocessor-patch

Conversation

@utam-1
Copy link

@utam-1 utam-1 commented Mar 16, 2026

Brief description of PR

The aim of this PR is to add an initial foundation work related to : https://sourceforge.net/p/gnucobol/feature-requests/341/

Changes made

The basic idea behind these changes are to initially detect and raise error for EXEC .... END EXEC block. In order to do so we defined a new state for the compiler <EXEC_STATE>, and necessary grammar rules for parser to handle these blocks, which handle the foreign embedded code.

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

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

that's a good start; missing are: cobc/Changelog and an entry in NEWS with something like

for parsing purposes, EXEC blocks are now recognized and handed with the "unsupported" warning level (defaulting to error) with INCLUDE statements handled as copybooks

along with test cases in syn_extensions.at (test an empty block, an empty SQL block and missing name after INCLUDE so we have a clue if error handling works, then another that from GixSQL's test cases which uses EXEC SQL INCLUDE with sqlca and another copybook, allowing the validation that the include did work correctly)

cobc/pplex.l Outdated

<EXEC_STATE>{
"END-EXEC"([ \t]*\.)? { BEGIN (INITIAL); return END_EXEC; }
"INCLUDE" { return COPY; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add a new token INCLUDE handling it in the parser as that will also be used as part of the internal preprocessor's error messages

cobc/pplex.l Outdated
"END-EXEC"([ \t]*\.)? { BEGIN (INITIAL); return END_EXEC; }
"INCLUDE" { return COPY; }
:[A-Za-z0-9][A-Za-z0-9-]* { pplval.s = cobc_plex_strdup (yytext); return TOKEN; }
[A-Za-z0-9][A-Za-z0-9-]* { pplval.s = cobc_plex_strdup (yytext); return TOKEN; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

we only need the "simple" token (effectively a word) to get that into the parser - the rest like bind variables can be consumed silently here as well

cobc/ppparse.y Outdated
;

exec_statement:
EXEC END_EXEC
Copy link
Collaborator

Choose a reason for hiding this comment

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

as already discussed, the "empty" EXEC block is an error (that will be taken care of the error case below), so drop that part

cobc/ppparse.y Outdated
}
| exec_token_list TOKEN
{
$$ = ppp_list_add ($1, $2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

as we don't want to handle the token list we can just consume it here, which leads to a small definition that will be referenced below

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

cobc/ppparse.y Outdated
}
| EXEC TOKEN COPY copy_source END_EXEC
{
/* EXEC TAG INCLUDE copybook */
Copy link
Collaborator

Choose a reason for hiding this comment

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

the include should be handled as COPY here

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

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

overall a remarkably better commit than the last one; see more notes below

STOP RUN.
])

AT_CHECK([$COBC -fsyntax-only -fdiagnostics-plain-output -Wno-error=unsupported prog.cob], [0], [],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should use $COMPILE_ONLY -Wno-unsupported prog.cob

])

AT_CHECK([$COMPILE_ONLY prog.cob], [1], [],
[prog.cob:5: error: syntax error, unexpected END_EXEC, expecting Word or Literal
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shows that the tolen name END_EXEC should get a literal value "END-EXEC"

Comment on lines +83 to +121
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
EXEC SQL
INCLUDE SQLCA
END-EXEC.
PROCEDURE DIVISION.
DISPLAY SQLCODE.
STOP RUN.
])

AT_CHECK([$COMPILE_ONLY -ffold-copy=LOWER prog.cob], [0], [], [])

AT_CLEANUP


AT_SETUP([EXEC SQL INCLUDE copybook expands correctly])
AT_KEYWORDS([exec sql include copy extensions])

AT_DATA([emprec.cpy], [
01 EMP-TABLE.
03 ENO PIC S9(4) COMP.
03 LNAME PIC X(10).
])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
EXEC SQL
INCLUDE EMPREC
END-EXEC.
PROCEDURE DIVISION.
MOVE 1 TO ENO.
STOP RUN.
])
Copy link
Collaborator

Choose a reason for hiding this comment

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

combine those to into a single test

Copy link
Collaborator

Choose a reason for hiding this comment

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

tests should be moved to the end of syn_definition.at

tests/test84.c Outdated
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

cobc/ChangeLog Outdated

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants