Added initial EXEC preprocessor handling logic in pplex and ppparse.#279
Added initial EXEC preprocessor handling logic in pplex and ppparse.#279utam-1 wants to merge 4 commits intoOCamlPro:gitside-gnucobol-3.xfrom
Conversation
GitMensch
left a comment
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
the include should be handled as COPY here
GitMensch
left a comment
There was a problem hiding this comment.
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], [], |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
This shows that the tolen name END_EXEC should get a literal value "END-EXEC"
| 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. | ||
| ]) |
There was a problem hiding this comment.
combine those to into a single test
There was a problem hiding this comment.
tests should be moved to the end of syn_definition.at
tests/test84.c
Outdated
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
please drop the cobc/ prefix here - as that is the place where that Changelog is
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.