Skip to content

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

Open
utam-1 wants to merge 9 commits into
OCamlPro:gitside-gnucobol-3.xfrom
utam-1:exec-preprocessor-patch
Open

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

Conversation

@utam-1

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

Copy link
Copy Markdown

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.

@GitMensch GitMensch left a comment

Copy link
Copy Markdown
Collaborator

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)

Comment thread cobc/pplex.l Outdated
Comment thread cobc/pplex.l Outdated
Comment thread cobc/ppparse.y Outdated
Comment thread cobc/ppparse.y Outdated
Comment thread cobc/ppparse.y Outdated

@GitMensch GitMensch left a comment

Copy link
Copy Markdown
Collaborator

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

Comment thread tests/testsuite.src/syn_extensions.at Outdated
Comment thread tests/testsuite.src/syn_extensions.at Outdated
])

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

Copy link
Copy Markdown
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 thread tests/testsuite.src/syn_extensions.at Outdated
Comment thread tests/testsuite.src/syn_extensions.at Outdated
Comment thread tests/test84.c Outdated
Comment thread cobc/ChangeLog Outdated
@utam-1 utam-1 requested a review from GitMensch May 2, 2026 02:54

@GitMensch GitMensch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi Uttam,

that PR is nearly ready to go upstream. Please have a look at the following comments, push your changes again (should pass CI) and I'll commit it.

This provides the baseline for the preprocessor config file.

Side note: I've added you to "contrib devs" on SF, so you can commit to the contrib svn repo and have the GnuCOBOL project in the associations under your SF profile.

Comment thread cobc/ppparse.y Outdated
Comment thread tests/testsuite.src/syn_definition.at Outdated
Comment thread tests/testsuite.src/syn_definition.at
Comment thread tests/testsuite.src/syn_definition.at Outdated
Comment thread tests/testsuite.src/syn_definition.at Outdated
Comment thread tests/testsuite.src/syn_definition.at
Comment thread cobc/pplex.l Outdated
Comment thread cobc/ppparse.y Outdated
Comment thread tests/testsuite.src/syn_definition.at
Comment thread tests/testsuite.src/syn_definition.at
Comment thread tests/testsuite.src/syn_definition.at
@utam-1

utam-1 commented May 30, 2026

Copy link
Copy Markdown
Author

Hello Simon,
I identified the issue related to the typo test cases which stalled the compiler, making it stuck in an infinite loop. To fix the same I used cb_source_line++ for \n which tracks the actual line numbers, and also added a check in the global <<EOF>> rule for <EXEC_STATE>.
Apart from this I have also added the test case for the scenario in which emprec.cpy is deleted. Do let me know if I should make some other modifications.

@GitMensch GitMensch marked this pull request as ready for review May 30, 2026 21:56

@GitMensch GitMensch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That looks nice!

Just a minor thing: replace leading spaces by tab (I could do that on upstream-merge otherwise).

Some more things I've stumbled over now in the review comments below.

Question: Should we start a target branch here + then create one PR against that according to the GSoC proposal - or have a single new one where we do everything until we consider the external preprocessor handling finished?

INCLUDE SQLCA
END-EXEC.
EXEC SQL
INCLUDE EMPREC

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've missed that before, we also need an example like INCLUDE "EMPREC" -> literal and ideally also INCLUDE SQLCA.cpy -> embedded perioid

Comment thread cobc/pplex.l Outdated
<EXEC_STATE>{
"END-EXEC"([ \t]*\.)? { BEGIN (INITIAL); return END_EXEC; }
"INCLUDE" { return INCLUDE; }
{WORD} { pplval.s = cobc_plex_strdup (yytext); return TOKEN; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

distinguish between a new SUBSYSTEM "subsytem" token and "common" TOKEN, which will improve diagnostics;
that may either be done with a new EXEC_STATE_START or with a static variable

@utam-1

utam-1 commented May 31, 2026

Copy link
Copy Markdown
Author

Just a minor thing: replace leading spaces by tab (I could do that on upstream-merge otherwise).

Yes that would be nice, I tried to replace them with sed but maybe it may not have worked.

Question: Should we start a target branch here + then create one PR against that according to the GSoC proposal - or have a single new one where we do everything until we consider the external preprocessor handling finished?

I think keeping this as the baseline target branch and then creating a PR against that makes sense.

@GitMensch

Copy link
Copy Markdown
Collaborator

sounds like a plan; I'd consider that branch fine now, so you may start with the next steps per your original GSoC plan (I only leave a minor change request, but that's really minor)

Comment thread cobc/pplex.l Outdated
Comment on lines +590 to +593
if (!exec_subsystem_seen) {
exec_subsystem_seen = 1;
return SUBSYSTEM;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just always go with TOKEN here, that's no valid SUBSYSTEM

Comment thread tests/testsuite.src/syn_definition.at Outdated


AT_SETUP([EXEC SQL INCLUDE sqlca and copybook])
AT_KEYWORDS([exec sql include sqlca extensions])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

all words in the test name are automatically added to the keywords and all keywords are case-senstive, so please cleanup the duplicates in all tests' keyywords; thanks

Comment thread tests/testsuite.src/syn_definition.at Outdated
Comment on lines +3014 to +3015
03 ENO PIC S9(4) COMP.
03 LNAME PIC X(10).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

COBOL85 ruleset would not compile that; area A (columns 8-11) should have the level 01+77 + most "boilerplate", column 12+ have higher levels (like these) and all coded statements, see below

Comment thread tests/testsuite.src/syn_definition.at Outdated
Comment on lines +3030 to +3032
DISPLAY SQLCODE.
MOVE 1 TO ENO.
STOP RUN.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

these are statements and start ideally at col12+(area b); also if there are statements then you should have a section or paragraph definition (those go to area a) - the easiest thing is go with MAIN.

Note: this does work "as is" but keeping a portable coding style is a good trait, so I suggest to go over those things for the test.

@utam-1

utam-1 commented Jun 1, 2026

Copy link
Copy Markdown
Author

sounds like a plan; I'd consider that branch fine now, so you may start with the next steps per your original GSoC plan (I only leave a minor change request, but that's really minor)

Thank you!
A small follow-up question from my side: Should this PR be merged into the main branch, so that the baseline be established at first, then I can rebase and make next set of incremental changes for subsequent stages? ( I think it will make the subsequent PRs easier to review and may potentially help in case if a merge conflict arises )

@GitMensch

Copy link
Copy Markdown
Collaborator

PR should be merged upstream, then I'll create a rebased branch that you can work from. I still wait for the FSF attorney to send the signed papers (will ping them mid/end of this week if I don't see any response, I'm actually waiting on multiple ones this time).

... but you can already start with that work, just don't push to this branch (either a separate one based on that or push later).

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