Skip to content

Commit

Permalink
Add >>IMP INCLUDE directive
Browse files Browse the repository at this point in the history
  • Loading branch information
engboris committed Apr 25, 2024
1 parent 2e620aa commit 94c0116
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

2024-04-25 Boris Eng <[email protected]>

* cobc.h, pplex.l, ppparse.y: new >>IMP INCLUDE directive to include
multiple header files in the C generated code. Has the same behavior as the
--include compiler option.

2024-03-17 Fabrice Le Fessant <[email protected]>
Emilien Lemaire <[email protected]>

Expand Down
1 change: 1 addition & 0 deletions cobc/cobc.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ extern unsigned int ppparse_verify (const enum cb_support tag,
extern void ppparse_error (const char *);

extern int cobc_deciph_source_format (const char *);
extern int cobc_deciph_header_filename (const char *);
extern void cobc_set_source_format (const enum cb_format);
extern enum cb_format cobc_get_source_format (void) COB_A_PURE;
extern int cobc_get_indicator_column (void) COB_A_PURE;
Expand Down
24 changes: 24 additions & 0 deletions cobc/pplex.l
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ MAYBE_AREA_A [ ]?#?
%x ALNUM_LITERAL_STATE
%x CONTROL_STATEMENT_STATE
%x DISPLAY_DIRECTIVE_STATE
%x IMP_DIRECTIVE_STATE

%%

Expand Down Expand Up @@ -360,6 +361,12 @@ MAYBE_AREA_A [ ]?#?
return CALL_DIRECTIVE;
}

^{MAYBE_AREA_A}[ ]*">>"[ ]?"IMP" {
/* GnuCOBOL 3.3 extension */
BEGIN IMP_DIRECTIVE_STATE;
return IMP_DIRECTIVE;
}

^{MAYBE_AREA_A}[ ]*">>"[ ]*\n {
/* empty 2002+ style directive */
cb_plex_warning (COBC_WARN_FILLER, newline_count,
Expand Down Expand Up @@ -724,6 +731,7 @@ ELSE_DIRECTIVE_STATE,
ENDIF_DIRECTIVE_STATE,
ALNUM_LITERAL_STATE,
CONTROL_STATEMENT_STATE,
IMP_DIRECTIVE_STATE,
COBOL_WORDS_DIRECTIVE_STATE>{
\n {
BEGIN INITIAL;
Expand Down Expand Up @@ -993,6 +1001,14 @@ ENDIF_DIRECTIVE_STATE>{
}
}

<IMP_DIRECTIVE_STATE>{
"INCLUDE" { return INCLUDE; }
{ALNUM_LITERAL} {
pplval.s = cobc_plex_strdup (yytext);
return TOKEN;
}
}

<IF_DIRECTIVE_STATE>{
"IS" { return IS; }
"NOT" { return NOT; }
Expand Down Expand Up @@ -1867,6 +1883,14 @@ int cobc_deciph_source_format (const char *sfname) {
return 1;
}

int cobc_deciph_header_filename (const char *filename) {
size_t n = strlen(filename);
if (filename[n-2] == '.' && filename[n-1] == 'h') {
return 0;
}
return 1;
}

void
plex_clear_vars (void)
{
Expand Down
36 changes: 32 additions & 4 deletions cobc/ppparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@

%expect 0

%defines
%verbose
%error-verbose
%name-prefix="pp"
%define parse.error verbose
%define api.prefix {pp}

/* NOTE:
support without = was added in Bison 2.4 (released 2008-11-02, we currently use 2.3),
Expand Down Expand Up @@ -741,6 +739,9 @@ ppparse_clear_vars (const struct cb_define_struct *p)
%token WITH
%token LOCATION

%token IMP_DIRECTIVE
%token INCLUDE

%token TERMINATOR "end of line"

%token <s> TOKEN "Word or Literal"
Expand Down Expand Up @@ -768,6 +769,7 @@ ppparse_clear_vars (const struct cb_define_struct *p)
%type <l> alnum_equality_list
%type <l> ec_list
%type <s> unquoted_literal
%type <l> imp_include_sources

%type <r> _copy_replacing
%type <r> replacing_list
Expand Down Expand Up @@ -838,6 +840,7 @@ directive:
| TURN_DIRECTIVE turn_directive
| LISTING_DIRECTIVE listing_directive
| LEAP_SECOND_DIRECTIVE leap_second_directive
| IMP_DIRECTIVE imp_directive
| IF_DIRECTIVE
{
current_cmd = PLEX_ACT_IF;
Expand Down Expand Up @@ -1368,6 +1371,30 @@ leap_second_directive:
| OFF
;

imp_directive:
_include imp_include_sources
{
cb_include_file_list = ppp_list_append(cb_include_file_list, $2);
}
;

imp_include_sources:
TOKEN
{
char *f = fix_filename ($1);
if (cobc_deciph_header_filename (f) != 0)
ppp_error_invalid_option ("IMP", f);
$$ = ppp_list_add (NULL, f);
}
| imp_include_sources TOKEN
{
char *f = fix_filename ($2);
if (cobc_deciph_header_filename (f) != 0)
ppp_error_invalid_option ("IMP", f);
$$ = ppp_list_add ($1, f);
}
;

turn_directive:
ec_list CHECKING on_or_off
{
Expand Down Expand Up @@ -1895,5 +1922,6 @@ _printing: | PRINTING ;
_on: | ON ;
_than: | THAN ;
_to: | TO ;
_include: | INCLUDE ;

%%

0 comments on commit 94c0116

Please sign in to comment.