Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 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,16 @@ MAYBE_AREA_A [ ]?#?
}
}

<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

:[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

[(),*/<>=+\-] { pplval.s = cobc_plex_strdup (yytext); return TOKEN; }
\n { newline_count++; }
. { /* silently consumed */ }
}

<SUBSTITUTION_SECTION_STATE,
CONTROL_DIVISION_STATE>{
"REPLACE" {
Expand Down
39 changes: 39 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 All @@ -776,6 +779,7 @@ ppparse_clear_vars (const struct cb_define_struct *p)
%type <l> imp_include_sources

%type <r> _copy_replacing
%type <l> exec_token_list
%type <r> replacing_list

%type <ds> object_id
Expand Down Expand Up @@ -830,6 +834,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 +1731,40 @@ replacing_list:
}
;

exec_token_list:
/* empty */
{
$$ = NULL;
}
| 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 */
  }
;

}
;

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

{
/* empty EXEC block — silently ignored */
}
| 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

cb_warning (cb_warn_unsupported,
_("EXEC %s INCLUDE is not yet supported"), $2);
}
| EXEC TOKEN exec_token_list END_EXEC
{
/* EXEC TAG ... END-EXEC — warn and ignore */
cb_warning (cb_warn_unsupported,
_("EXEC %s statement ignored"), $2);
}
| EXEC error END_EXEC
{
yyerrok;
}
;

text_src:
EQEQ token_list EQEQ
{
Expand Down
Loading