GerHobbelt / jison

bison / YACC / LEX in JavaScript (LALR(1), SLR(1), etc. lexer/parser generator)
https://gerhobbelt.github.io/jison/
MIT License
118 stars 20 forks source link

`yylexer.prettyPrintRange()` API: very long prelude is not shortened with (...continued...) a la error area #28

Closed GerHobbelt closed 6 years ago

GerHobbelt commented 6 years ago

Found while quickly looking at the GnuCobol parser.y grammar.

Expected behaviour SHOULD be a '(...continued...)' prelude for such edge cases, a la the second error dump example below.

Notice the extremely long prelude dumping the entire (irrelevant) setup %{...%} code chunk here while reporting on the %token EOF 0 ... error:

            throw err;
            ^

JisonParserError:
declaration list error?

  Erroneous area:
  21: %expect 0
  22:
  23: %defines
  24: %verbose
  25: %error-verbose
  26:
  27: %{
  28: // #include "config.h"
  29: //
  30: // #include <stdlib.h>
  31: // #include <string.h>
  32: //
  33: // #define COB_IN_PARSER 1
  34: // #include "cobc.h"
  35: // #include "tree.h"
  36: //
  37: // #ifndef _STDLIB_H
  38: // #define _STDLIB_H 1
  39: // #endif
  40: //
  41: // #define YYSTYPE   cb_tree
  42: // #define yyerror(x)  cb_error ("%s", x)
  43: //
  44: // #define emit_statement(x) \
  45: // do { \
  46: //   if (!skip_statements) { \
  47: //  CB_ADD_TO_CHAIN (x, current_program->exec_list); \
  48: //   } \
  49: // }  ONCE_COB
  50: //
  51: // #define push_expr(type, node) \
  52: //   current_expr = cb_build_list (cb_int (type), node, current_expr)
  53: //
  54: // /* Statement terminator definitions */
  55: // #define TERM_NONE  0
  56: // #define TERM_ACCEPT  1U
  57: // #define TERM_ADD  2U
  58: // #define TERM_CALL  3U
  59: // #define TERM_COMPUTE  4U
  60: // #define TERM_DELETE  5U
  61: // #define TERM_DISPLAY  6U
  62: // #define TERM_DIVIDE  7U
  63: // #define TERM_EVALUATE  8U
  64: // #define TERM_IF   9U
  65: // #define TERM_MULTIPLY  10U
  66: // #define TERM_PERFORM  11U
  67: // #define TERM_READ  12U
  68: // #define TERM_RECEIVE  13U
  69: // #define TERM_RETURN  14U
  70: // #define TERM_REWRITE  15U
  71: // #define TERM_SEARCH  16U
  72: // #define TERM_START  17U
  73: // #define TERM_STRING  18U
  74: // #define TERM_SUBTRACT  19U
  75: // #define TERM_UNSTRING  20U
  76: // #define TERM_WRITE  21U
  77: // #define TERM_MAX  22U /* Always last entry, used for array size */
  78: //
  79: // #define TERMINATOR_WARNING(x,z) terminator_warning (x, TERM_##z, #z)
  80: // #define TERMINATOR_ERROR(x,z) terminator_error (x, TERM_##z, #z)
  81: // #define TERMINATOR_CLEAR(x,z) terminator_clear (x, TERM_##z)
  82: //
  83: // /* Defines for duplicate checks */
  84: // /* Note - We use <= 16 for common item definitons and */
  85: // /* > 16 for non-common item definitions e.g. REPORT and SCREEN */
  86: // #define SYN_CLAUSE_1  (1U << 0)
  87: // #define SYN_CLAUSE_2  (1U << 1)
  88: // #define SYN_CLAUSE_3  (1U << 2)
  89: // #define SYN_CLAUSE_4  (1U << 3)
  90: // #define SYN_CLAUSE_5  (1U << 4)
  91: // #define SYN_CLAUSE_6  (1U << 5)
  92: // #define SYN_CLAUSE_7  (1U << 6)
  93: // #define SYN_CLAUSE_8  (1U << 7)
  94: // #define SYN_CLAUSE_9  (1U << 8)
  95: // #define SYN_CLAUSE_10  (1U << 9)
  96: // #define SYN_CLAUSE_11  (1U << 10)
  97: // #define SYN_CLAUSE_12  (1U << 11)
  98: // #define SYN_CLAUSE_13  (1U << 12)
  99: // #define SYN_CLAUSE_14  (1U << 13)
 100: // #define SYN_CLAUSE_15  (1U << 14)
 101: // #define SYN_CLAUSE_16  (1U << 15)
 102: // #define SYN_CLAUSE_17  (1U << 16)
 103: // #define SYN_CLAUSE_18  (1U << 17)
 104: // #define SYN_CLAUSE_19  (1U << 18)
 105: // #define SYN_CLAUSE_20  (1U << 19)
 106: // #define SYN_CLAUSE_21  (1U << 20)
 107: // #define SYN_CLAUSE_22  (1U << 21)
 108: // #define SYN_CLAUSE_23  (1U << 22)
 109: // #define SYN_CLAUSE_24  (1U << 23)
 110: // #define SYN_CLAUSE_25  (1U << 24)
 111: // #define SYN_CLAUSE_26  (1U << 25)
 112: // #define SYN_CLAUSE_27  (1U << 26)
 113: // #define SYN_CLAUSE_28  (1U << 27)
 114: // #define SYN_CLAUSE_29  (1U << 28)
 115: // #define SYN_CLAUSE_30  (1U << 29)
 116: // #define SYN_CLAUSE_31  (1U << 30)
 117: // #define SYN_CLAUSE_32  (1U << 31)
 118: //
 119: // #define EVAL_DEPTH  32
 120: // #define PROG_DEPTH  16
 121: //
 122: // /* Global variables */
 123: //
 124: // struct cb_program  *current_program = NULL;
 125: // struct cb_statement  *current_statement = NULL;
 126: // struct cb_label   *current_section = NULL;
 127: // struct cb_label   *current_paragraph = NULL;
 128: // cb_tree    defined_prog_list = NULL;
 129: // int    cb_exp_line = 0;
 130: //
 131: // cb_tree    cobc_printer_node = NULL;
 132: // int    functions_are_all = 0;
 133: // int    non_const_word = 0;
 134: // int    suppress_data_exceptions = 0;
 135: // int    call_line_number;
 136: // unsigned int   cobc_repeat_last_token = 0;
 137: // unsigned int   cobc_in_id = 0;
 138: // unsigned int   cobc_in_procedure = 0;
 139: // unsigned int   cobc_in_repository = 0;
 140: // unsigned int   cobc_force_literal = 0;
 141: // unsigned int   cobc_cs_check = 0;
 142: // unsigned int   cobc_allow_program_name = 0;
 143: //
 144: // /* Local variables */
 145: //
 146: // enum tallying_phrase {
 147: //  NO_PHRASE,
 148: //  FOR_PHRASE,
 149: //  CHARACTERS_PHRASE,
 150: //  ALL_LEADING_TRAILING_PHRASES,
 151: //  VALUE_REGION_PHRASE
 152: // };
 153: //
 154: // static struct cb_statement *main_statement;
 155: //
 156: // static cb_tree   current_expr;
 157: // static struct cb_field  *current_field;
 158: // static struct cb_field  *description_field;
 159: // static struct cb_file  *current_file;
 160: // static struct cb_cd  *current_cd;
 161: // static struct cb_report  *current_report;
 162: // static struct cb_report  *report_instance;
 163: //
 164: // static struct cb_file  *linage_file;
 165: // static cb_tree   next_label_list;
 166: //
 167: // static char   *stack_progid[PROG_DEPTH];
 168: //
 169: // static enum cb_storage  current_storage;
 170: //
 171: // static cb_tree   perform_stack;
 172: // static cb_tree   qualifier;
 173: // static cb_tree   keys_list;
 174: //
 175: // static cb_tree   save_tree;
 176: // static cb_tree   start_tree;
 177: //
 178: // static unsigned int  check_unreached;
 179: // static unsigned int  in_declaratives;
 180: // static unsigned int  in_debugging;
 181: // static unsigned int  current_linage;
 182: // static unsigned int  report_count;
 183: // static unsigned int  first_prog;
 184: // static unsigned int  setup_from_identification;
 185: // static unsigned int  use_global_ind;
 186: // static unsigned int  same_area;
 187: // static unsigned int  inspect_keyword;
 188: // static unsigned int  main_flag_set;
 189: // static int   next_label_id;
 190: // static int   eval_level;
 191: // static int   eval_inc;
 192: // static int   eval_inc2;
 193: // static int   depth;
 194: // static int   first_nested_program;
 195: // static int   call_mode;
 196: // static int   size_mode;
 197: // static cob_flags_t  set_attr_val_on;
 198: // static cob_flags_t  set_attr_val_off;
 199: // static cob_flags_t  check_duplicate;
 200: // static cob_flags_t  check_on_off_duplicate;
 201: // static cob_flags_t  check_pic_duplicate;
 202: // static cob_flags_t  check_line_col_duplicate;
 203: // static unsigned int  skip_statements;
 204: // static unsigned int  start_debug;
 205: // static unsigned int  save_debug;
 206: // static unsigned int  needs_field_debug;
 207: // static unsigned int  needs_debug_item;
 208: // static unsigned int  env_div_seen;
 209: // static cob_flags_t  header_check;
 210: // static unsigned int  call_nothing;
 211: // static enum tallying_phrase previous_tallying_phrase;
 212: // static cb_tree   default_rounded_mode;
 213: //
 214: // static enum cb_display_type display_type;
 215: // static int   is_first_display_item;
 216: // static cb_tree   advancing_value;
 217: // static cb_tree   upon_value;
 218: // static cb_tree   line_column;
 219: //
 220: // static int   term_array[TERM_MAX];
 221: // static cb_tree   eval_check[EVAL_DEPTH][EVAL_DEPTH];
 222: //
 223: // /* Defines for header presence */
 224: //
 225: // #define COBC_HD_ENVIRONMENT_DIVISION (1U << 0)
 226: // #define COBC_HD_CONFIGURATION_SECTION (1U << 1)
 227: // #define COBC_HD_SPECIAL_NAMES  (1U << 2)
 228: // #define COBC_HD_INPUT_OUTPUT_SECTION (1U << 3)
 229: // #define COBC_HD_FILE_CONTROL  (1U << 4)
 230: // #define COBC_HD_I_O_CONTROL  (1U << 5)
 231: // #define COBC_HD_DATA_DIVISION  (1U << 6)
 232: // #define COBC_HD_FILE_SECTION  (1U << 7)
 233: // #define COBC_HD_WORKING_STORAGE_SECTION (1U << 8)
 234: // #define COBC_HD_LOCAL_STORAGE_SECTION (1U << 9)
 235: // #define COBC_HD_LINKAGE_SECTION  (1U << 10)
 236: // #define COBC_HD_COMMUNICATION_SECTION (1U << 11)
 237: // #define COBC_HD_REPORT_SECTION  (1U << 12)
 238: // #define COBC_HD_SCREEN_SECTION  (1U << 13)
 239: // #define COBC_HD_PROCEDURE_DIVISION (1U << 14)
 240: // #define COBC_HD_PROGRAM_ID  (1U << 15)
 241: //
 242: // /* Static functions */
 243: //
 244: // static void
 245: // begin_statement (const char *name, const unsigned int term)
 246: // {
 247: //  if (check_unreached) {
 248: //   cb_warning (cb_warn_unreachable, _("unreachable statement '%s'"), name);
 249: //  }
 250: //  current_paragraph->flag_statement = 1;
 251: //  current_statement = cb_build_statement (name);
 252: //  CB_TREE (current_statement)->source_file = cb_source_file;
 253: //  CB_TREE (current_statement)->source_line = cb_source_line;
 254: //  current_statement->flag_in_debug = in_debugging;
 255: //  emit_statement (CB_TREE (current_statement));
 256: //  if (term) {
 257: //   term_array[term]++;
 258: //  }
 259: //  main_statement = current_statement;
 260: // }
 261: //
 262: // /* create a new statement with base attributes of current_statement
 263: //    and set this as new current_statement */
 264: // static void
 265: // begin_implicit_statement (void)
 266: // {
 267: //  struct cb_statement *new_statement;
 268: //  new_statement = cb_build_statement (NULL);
 269: //  new_statement->common = current_statement->common;
 270: //  new_statement->name = current_statement->name;
 271: //  new_statement->flag_in_debug = !!in_debugging;
 272: //  current_statement = new_statement;
 273: //  main_statement->body = cb_list_add (main_statement->body,
 274: //          CB_TREE (current_statement));
 275: // }
 276: //
 277: // # if 0 /* activate only for debugging purposes for attribs */
 278: // static
 279: // void print_bits (cob_flags_t num)
 280: // {
 281: //  unsigned int  size = sizeof (cob_flags_t);
 282: //  unsigned int max_pow = 1 << (size * 8 - 1);
 283: //  int   i = 0;
 284: //
 285: //  for(; i < size * 8; ++i){
 286: //   /* Print last bit and shift left. */
 287: //   fprintf (stderr, "%u ", num & max_pow ? 1 : 0);
 288: //   num = num << 1;
 289: //  }
 290: //  fprintf (stderr, "\n");
 291: // }
 292: // #endif
 293: //
 294: // static void
 295: // emit_entry (const char *name, const int encode, cb_tree using_list, cb_tree convention)
 296: // {
 297: //  cb_tree  l;
 298: //  cb_tree  label;
 299: //  cb_tree  x;
 300: //  cb_tree  entry_conv;
 301: //  struct cb_field *f, *ret_f;
 302: //  int   param_num;
 303: //  char  buff[COB_MINI_BUFF];
 304: //
 305: //  snprintf (buff, (size_t)COB_MINI_MAX, "E$%s", name);
 306: //  label = cb_build_label (cb_build_reference (buff), NULL);
 307: //  if (encode) {
 308: //   CB_LABEL (label)->name = cb_encode_program_id (name);
 309: //   CB_LABEL (label)->orig_name = name;
 310: //  } else {
 311: //   CB_LABEL (label)->name = name;
 312: //   CB_LABEL (label)->orig_name = current_program->orig_program_id;
 313: //  }
 314: //  CB_LABEL (label)->flag_begin = 1;
 315: //  CB_LABEL (label)->flag_entry = 1;
 316: //  label->source_file = cb_source_file;
 317: //  label->source_line = cb_source_line;
 318: //  emit_statement (label);
 319: //
 320: //  if (current_program->flag_debugging) {
 321: //   emit_statement (cb_build_debug (cb_debug_contents,
 322: //       "START PROGRAM", NULL));
 323: //  }
 324: //
 325: //  param_num = 1;
 326: //  for (l = using_list; l; l = CB_CHAIN (l)) {
 327: //   x = CB_VALUE (l);
 328: //   if (CB_VALID_TREE (x) && cb_ref (x) != cb_error_node) {
 329: //    f = CB_FIELD (cb_ref (x));
 330: //    if (!current_program->flag_chained) {
 331: //     if (f->storage != CB_STORAGE_LINKAGE) {
 332: //      cb_error_x (x, _("'%s' is not in LINKAGE SECTION"), f->name);
 333: //     }
 334: //     if (f->flag_item_based || f->flag_external) {
 335: //      cb_error_x (x, _("'%s' cannot be BASED/EXTERNAL"), f->name);
 336: //     }
 337: //     f->flag_is_pdiv_parm = 1;
 338: //    } else {
 339: //     if (f->storage != CB_STORAGE_WORKING) {
 340: //      cb_error_x (x, _("'%s' is not in WORKING-STORAGE SECTION"), f->name);
 341: //     }
 342: //     f->flag_chained = 1;
 343: //     f->param_num = param_num;
 344: //     param_num++;
 345: //    }
 346: //    if (f->level != 01 && f->level != 77) {
 347: //     cb_error_x (x, _("'%s' not level 01 or 77"), f->name);
 348: //    }
 349: //    if (f->redefines) {
 350: //     cb_error_x (x, _ ("'%s' REDEFINES field not allowed here"), f->name);
 351: //    }
 352: //    /* add a "receiving" entry for the USING parameter */
 353: //    if (cb_listing_xref) {
 354: //     cobc_xref_link (&f->xref, CB_REFERENCE (x)->common.source_line, 1);
 355: //    }
 356: //   }
 357: //  }
 358: //
 359: //
 360: //  if (current_program->returning &&
 361: //   cb_ref (current_program->returning) != cb_error_node) {
 362: //   ret_f = CB_FIELD (cb_ref (current_program->returning));
 363: //   if (ret_f->redefines) {
 364: //    cb_error_x (current_program->returning, _("'%s' REDEFINES field not allowed here"), ret_f->name);
 365: //   }
 366: //  } else {
 367: //   ret_f = NULL;
 368: //  }
 369: //
 370: //  /* Check dangling LINKAGE items */
 371: //  if (cb_warn_linkage) {
 372: //   for (f = current_program->linkage_storage; f; f = f->sister) {
 373: //    if (f == ret_f) {
 374: //     continue;
 375: //    }
 376: //    for (l = using_list; l; l = CB_CHAIN (l)) {
 377: //     x = CB_VALUE (l);
 378: //     if (CB_VALID_TREE (x) && cb_ref (x) != cb_error_node) {
 379: //      if (f == CB_FIELD (cb_ref (x))) {
 380: //       break;
 381: //      }
 382: //     }
 383: //    }
 384: //    if (!l && !f->redefines) {
 385: //     cb_warning (cb_warn_linkage, _("LINKAGE item '%s' is not a PROCEDURE USING parameter"), f->name);
 386: //    }
 387: //   }
 388: //  }
 389: //
 390: //  /* Check returning item against using items when FUNCTION */
 391: //  if (current_program->prog_type == CB_FUNCTION_TYPE && current_program->returning) {
 392: //   for (l = using_list; l; l = CB_CHAIN (l)) {
 393: //    x = CB_VALUE (l);
 394: //    if (CB_VALID_TREE (x) && cb_ref (x) != cb_error_node) {
 395: //     f = CB_FIELD (cb_ref (x));
 396: //     if (ret_f == f) {
 397: //      cb_error_x (x, _("'%s' USING item duplicates RETURNING item"), f->name);
 398: //     }
 399: //    }
 400: //   }
 401: //  }
 402: //
 403: //  for (l = current_program->entry_list; l; l = CB_CHAIN (l)) {
 404: //   if (strcmp ((const char *)name,
 405: //        (const char *)(CB_LABEL(CB_PURPOSE(l))->name)) == 0) {
 406: //    cb_error_x (CB_TREE (current_statement),
 407: //         _("ENTRY '%s' duplicated"), name);
 408: //   }
 409: //  }
 410: //
 411: //  if (convention) {
 412: //   entry_conv = convention;
 413: //  } else {
 414: //   entry_conv = current_program->entry_convention;
 415: //  }
 416: //
 417: //  current_program->entry_list =
 418: //   cb_list_append (current_program->entry_list,
 419: //     CB_BUILD_PAIR (label, CB_BUILD_PAIR(entry_conv, using_list)));
 420: // }
 421: //
 422: // static size_t
 423: // increment_depth (void)
 424: // {
 425: //  if (++depth >= PROG_DEPTH) {
 426: //   cb_error (_("maximum nested program depth exceeded (%d)"),
 427: //      PROG_DEPTH);
 428: //   return 1;
 429: //  }
 430: //  return 0;
 431: // }
 432: //
 433: // static void
 434: // terminator_warning (cb_tree stmt, const unsigned int termid,
 435: //       const char *name)
 436: // {
 437: //  char  terminator[32];
 438: //
 439: //  check_unreached = 0;
 440: //  if (term_array[termid]) {
 441: //   term_array[termid]--;
 442: //  /* LCOV_EXCL_START */
 443: //  } else {
 444: //   cobc_err_msg ("call to '%s' without any open term for %s",
 445: //    "terminator_warning", name);
 446: //   COBC_ABORT ();
 447: //  }
 448: //  /* LCOV_EXCL_END */
 449: //  snprintf (terminator, 32, "END-%s", name);
 450: //  if (is_reserved_word (terminator)) {
 451: //   cb_warning_x (cb_warn_terminator, CB_TREE (current_statement),
 452: //    _("%s statement not terminated by %s"), name, terminator);
 453: //  }
 454: //
 455: //  /* Free tree associated with terminator */
 456: //  if (stmt) {
 457: //   cobc_parse_free (stmt);
 458: //  }
 459: // }
 460: //
 461: // static void
 462: // terminator_error (cb_tree stmt, const unsigned int termid, const char *name)
 463: // {
 464: //  char  terminator[32];
 465: //
 466: //  check_unreached = 0;
 467: //  if (term_array[termid]) {
 468: //   term_array[termid]--;
 469: //  /* LCOV_EXCL_START */
 470: //  } else {
 471: //   cobc_err_msg ("call to '%s' without any open term for %s",
 472: //    "terminator_error", name);
 473: //   COBC_ABORT ();
 474: //  }
 475: //  /* LCOV_EXCL_END */
 476: //  snprintf (terminator, 32, "END-%s", name);
 477: //  if (is_reserved_word (terminator)) {
 478: //   cb_error_x (CB_TREE (current_statement),
 479: //    _("%s statement not terminated by %s"), name, terminator);
 480: //  } else {
 481: //   cb_error_x (CB_TREE (current_statement),
 482: //    _("%s statement not terminated"), name);
 483: //  }
 484: //
 485: //  /* Free tree associated with terminator */
 486: //  if (stmt) {
 487: //   cobc_parse_free (stmt);
 488: //  }
 489: // }
 490: //
 491: // static void
 492: // terminator_clear (cb_tree stmt, const unsigned int termid)
 493: // {
 494: //  struct cb_perform *p;
 495: //  check_unreached = 0;
 496: //  if (term_array[termid]) {
 497: //   term_array[termid]--;
 498: //  /* LCOV_EXCL_START */
 499: //  } else {
 500: //   cobc_err_msg ("call to '%s' without any open term for %s",
 501: //    "terminator_warning", current_statement->name);
 502: //   COBC_ABORT ();
 503: //  }
 504: //  /* LCOV_EXCL_END */
 505: //  if (termid == TERM_PERFORM
 506: //   && perform_stack) {
 507: //   p = CB_PERFORM (CB_VALUE (perform_stack));
 508: //   if (p->perform_type == CB_PERFORM_UNTIL) {
 509: //    cb_terminate_cond ();
 510: //   }
 511: //  }
 512: //  /* Free tree associated with terminator */
 513: //  if (stmt) {
 514: //   cobc_parse_free (stmt);
 515: //  }
 516: // }
 517: //
 518: // static int
 519: // literal_value (cb_tree x)
 520: // {
 521: //  if (x == cb_space) {
 522: //   return ' ';
 523: //  } else if (x == cb_zero) {
 524: //   return '0';
 525: //  } else if (x == cb_quote) {
 526: //   return cb_flag_apostrophe ? '\'' : '"';
 527: //  } else if (x == cb_null) {
 528: //   return 0;
 529: //  } else if (x == cb_low) {
 530: //   return 0;
 531: //  } else if (x == cb_high) {
 532: //   return 255;
 533: //  } else if (CB_TREE_CLASS (x) == CB_CLASS_NUMERIC) {
 534: //   return cb_get_int (x);
 535: //  } else {
 536: //   return CB_LITERAL (x)->data[0];
 537: //  }
 538: // }
 539: //
 540: // static void
 541: // setup_use_file (struct cb_file *fileptr)
 542: // {
 543: //  struct cb_file *newptr;
 544: //
 545: //  if (fileptr->organization == COB_ORG_SORT) {
 546: //   cb_error (_("USE statement invalid for SORT file"));
 547: //  }
 548: //  if (fileptr->flag_global) {
 549: //   newptr = cobc_parse_malloc (sizeof(struct cb_file));
 550: //   *newptr = *fileptr;
 551: //   newptr->handler = current_section;
 552: //   newptr->handler_prog = current_program;
 553: //   if (!use_global_ind) {
 554: //    current_program->local_file_list =
 555: //     cb_list_add (current_program->local_file_list,
 556: //           CB_TREE (newptr));
 557: //   } else {
 558: //    current_program->global_file_list =
 559: //     cb_list_add (current_program->global_file_list,
 560: //           CB_TREE (newptr));
 561: //   }
 562: //  } else {
 563: //   fileptr->handler = current_section;
 564: //  }
 565: // }
 566: //
 567: // static void
 568: // emit_duplicate_clause_message (const char *clause)
 569: // {
 570: //  /* FIXME: replace by a new warning level that is set
 571: //     to warn/error depending on cb_relaxed_syntax_checks */
 572: //  if (cb_relaxed_syntax_checks) {
 573: //   cb_warning (COBC_WARN_FILLER, _("duplicate %s clause"), clause);
 574: //  } else {
 575: //   cb_error (_("duplicate %s clause"), clause);
 576: //  }
 577: // }
 578: //
 579: // static void
 580: // check_repeated (const char *clause, const cob_flags_t bitval, cob_flags_t *already_seen)
 581: // {
 582: //  if (*already_seen & bitval) {
 583: //   emit_duplicate_clause_message (clause);
 584: //  } else {
 585: //   *already_seen |= bitval;
 586: //  }
 587: // }
 588: //
 589: // static void
 590: // setup_occurs (void)
 591: // {
 592: //  check_repeated ("OCCURS", SYN_CLAUSE_7, &check_pic_duplicate);
 593: //  if (current_field->indexes == COB_MAX_SUBSCRIPTS) {
 594: //   cb_error (_ ("maximum OCCURS depth exceeded (%d)"),
 595: //    COB_MAX_SUBSCRIPTS);
 596: //  } else {
 597: //   current_field->indexes++;
 598: //  }
 599: //
 600: //  if (current_field->flag_unbounded) {
 601: //   if (current_field->storage != CB_STORAGE_LINKAGE) {
 602: //    cb_error_x (CB_TREE(current_field), _("'%s' is not in LINKAGE SECTION"),
 603: //     cb_name (CB_TREE(current_field)));
 604: //   }
 605: //  }
 606: //
 607: //  if (current_field->flag_item_based) {
 608: //   cb_error (_ ("%s and %s are mutually exclusive"), "BASED", "OCCURS");
 609: //  } else if (current_field->flag_external) {
 610: //   cb_error (_ ("%s and %s are mutually exclusive"), "EXTERNAL", "OCCURS");
 611: //  }
 612: //  current_field->flag_occurs = 1;
 613: // }
 614: //
 615: // static void
 616: // setup_occurs_min_max (cb_tree occurs_min, cb_tree occurs_max)
 617: // {
 618: //  if (occurs_max) {
 619: //   current_field->occurs_min = cb_get_int (occurs_min);
 620: //   if (occurs_max != cb_int0) {
 621: //    current_field->occurs_max = cb_get_int (occurs_max);
 622: //    if (!current_field->depending) {
 623: //     if (cb_relaxed_syntax_checks) {
 624: //      cb_warning (COBC_WARN_FILLER, _ ("TO phrase without DEPENDING phrase"));
 625: //      cb_warning (COBC_WARN_FILLER, _ ("maximum number of occurences assumed to be exact number"));
 626: //      current_field->occurs_min = 1; /* CHECKME: why using 1 ? */
 627: //     } else {
 628: //      cb_error (_ ("TO phrase without DEPENDING phrase"));
 629: //     }
 630: //    }
 631: //    if (current_field->occurs_max <= current_field->occurs_min) {
 632: //     cb_error (_ ("OCCURS TO must be greater than OCCURS FROM"));
 633: //    }
 634: //   } else {
 635: //    current_field->occurs_max = 0;
 636: //   }
 637: //  } else {
 638: //   current_field->occurs_min = 1; /* CHECKME: why using 1 ? */
 639: //   current_field->occurs_max = cb_get_int (occurs_min);
 640: //   if (current_field->depending) {
 641: //    cb_verify (cb_odo_without_to, _ ("ODO without TO phrase"));
 642: //   }
 643: //  }
 644: // }
 645: //
 646: // static void
 647: // check_relaxed_syntax (const cob_flags_t lev)
 648: // {
 649: //  const char *s;
 650: //
 651: //  switch (lev) {
 652: //  case COBC_HD_ENVIRONMENT_DIVISION:
 653: //   s = "ENVIRONMENT DIVISION";
 654: //   break;
 655: //  case COBC_HD_CONFIGURATION_SECTION:
 656: //   s = "CONFIGURATION SECTION";
 657: //   break;
 658: //  case COBC_HD_SPECIAL_NAMES:
 659: //   s = "SPECIAL-NAMES";
 660: //   break;
 661: //  case COBC_HD_INPUT_OUTPUT_SECTION:
 662: //   s = "INPUT-OUTPUT SECTION";
 663: //   break;
 664: //  case COBC_HD_FILE_CONTROL:
 665: //   s = "FILE-CONTROL";
 666: //   break;
 667: //  case COBC_HD_I_O_CONTROL:
 668: //   s = "I-O-CONTROL";
 669: //   break;
 670: //  case COBC_HD_DATA_DIVISION:
 671: //   s = "DATA DIVISION";
 672: //   break;
 673: //  case COBC_HD_FILE_SECTION:
 674: //   s = "FILE SECTION";
 675: //   break;
 676: //  case COBC_HD_WORKING_STORAGE_SECTION:
 677: //   s = "WORKING-STORAGE SECTION";
 678: //   break;
 679: //  case COBC_HD_LOCAL_STORAGE_SECTION:
 680: //   s = "LOCAL-STORAGE SECTION";
 681: //   break;
 682: //  case COBC_HD_LINKAGE_SECTION:
 683: //   s = "LINKAGE SECTION";
 684: //   break;
 685: //  case COBC_HD_COMMUNICATION_SECTION:
 686: //   s = "COMMUNICATION SECTION";
 687: //   break;
 688: //  case COBC_HD_REPORT_SECTION:
 689: //   s = "REPORT SECTION";
 690: //   break;
 691: //  case COBC_HD_SCREEN_SECTION:
 692: //   s = "SCREEN SECTION";
 693: //   break;
 694: //  case COBC_HD_PROCEDURE_DIVISION:
 695: //   s = "PROCEDURE DIVISION";
 696: //   break;
 697: //  case COBC_HD_PROGRAM_ID:
 698: //   s = "PROGRAM-ID";
 699: //   break;
 700: //  default:
 701: //   s = "Unknown";
 702: //   break;
 703: //  }
 704: //  if (cb_relaxed_syntax_checks) {
 705: //   cb_warning (COBC_WARN_FILLER, _("%s header missing - assumed"), s);
 706: //  } else {
 707: //   cb_error (_("%s header missing"), s);
 708: //  }
 709: // }
 710: //
 711: // /* check if headers are present - return 0 if fine, 1 if missing
 712: //    Lev1 must always be present and is checked
 713: //    Lev2/3/4, if non-zero (forced) may be present
 714: // */
 715: // static int
 716: // check_headers_present (const cob_flags_t lev1, const cob_flags_t lev2,
 717: //          const cob_flags_t lev3, const cob_flags_t lev4)
 718: // {
 719: //  int ret = 0;
 720: //  if (!(header_check & lev1)) {
 721: //   header_check |= lev1;
 722: //   check_relaxed_syntax (lev1);
 723: //   ret = 1;
 724: //  }
 725: //  if (lev2) {
 726: //   if (!(header_check & lev2)) {
 727: //    header_check |= lev2;
 728: //    check_relaxed_syntax (lev2);
 729: //    ret = 1;
 730: //   }
 731: //  }
 732: //  if (lev3) {
 733: //   if (!(header_check & lev3)) {
 734: //    header_check |= lev3;
 735: //    check_relaxed_syntax (lev3);
 736: //    ret = 1;
 737: //   }
 738: //  }
 739: //  if (lev4) {
 740: //   if (!(header_check & lev4)) {
 741: //    header_check |= lev4;
 742: //    check_relaxed_syntax (lev4);
 743: //    ret = 1;
 744: //   }
 745: //  }
 746: //  return ret;
 747: // }
 748: //
 749: // static void
 750: // build_nested_special (const int ndepth)
 751: // {
 752: //  cb_tree  x;
 753: //  cb_tree  y;
 754: //
 755: //  if (!ndepth) {
 756: //   return;
 757: //  }
 758: //
 759: //  /* Inherit special name mnemonics from parent */
 760: //  for (x = current_program->mnemonic_spec_list; x; x = CB_CHAIN (x)) {
 761: //   y = cb_build_reference (cb_name(CB_PURPOSE(x)));
 762: //   if (CB_SYSTEM_NAME_P (CB_VALUE(x))) {
 763: //    cb_define (y, CB_VALUE(x));
 764: //   } else {
 765: //    cb_build_constant (y, CB_VALUE(x));
 766: //   }
 767: //  }
 768: // }
 769: //
 770: // static void
 771: // clear_initial_values (void)
 772: // {
 773: //  perform_stack = NULL;
 774: //  current_statement = NULL;
 775: //  main_statement = NULL;
 776: //  qualifier = NULL;
 777: //  in_declaratives = 0;
 778: //  in_debugging = 0;
 779: //  use_global_ind = 0;
 780: //  check_duplicate = 0;
 781: //  check_pic_duplicate = 0;
 782: //  skip_statements = 0;
 783: //  start_debug = 0;
 784: //  save_debug = 0;
 785: //  needs_field_debug = 0;
 786: //  needs_debug_item = 0;
 787: //  env_div_seen = 0;
 788: //  header_check = 0;
 789: //  next_label_id = 0;
 790: //  current_linage = 0;
 791: //  set_attr_val_on = 0;
 792: //  set_attr_val_off = 0;
 793: //  report_count = 0;
 794: //  current_storage = CB_STORAGE_WORKING;
 795: //  eval_level = 0;
 796: //  eval_inc = 0;
 797: //  eval_inc2 = 0;
 798: //  inspect_keyword = 0;
 799: //  check_unreached = 0;
 800: //  cobc_in_id = 0;
 801: //  cobc_in_procedure = 0;
 802: //  cobc_in_repository = 0;
 803: //  cobc_force_literal = 0;
 804: //  non_const_word = 0;
 805: //  suppress_data_exceptions = 0;
 806: //  same_area = 1;
 807: //  memset ((void *)eval_check, 0, sizeof(eval_check));
 808: //  memset ((void *)term_array, 0, sizeof(term_array));
 809: //  linage_file = NULL;
 810: //  current_file = NULL;
 811: //  current_cd = NULL;
 812: //  current_report = NULL;
 813: //  report_instance = NULL;
 814: //  next_label_list = NULL;
 815: //  default_rounded_mode = cb_int (COB_STORE_ROUND);
 816: // }
 817: //
 818: // /*
 819: //   We must check for redefinitions of program-names and external program names
 820: //   outside of the usual reference/word_list methods as it may have to be done in
 821: //   a case-sensitive way.
 822: // */
 823: // static void
 824: // begin_scope_of_program_name (struct cb_program *program)
 825: // {
 826: //  const char *prog_name = program->program_name;
 827: //  const char *prog_id = program->orig_program_id;
 828: //  const char *elt_name;
 829: //  const char *elt_id;
 830: //  cb_tree  l;
 831: //
 832: //  /* Error if a program with the same name has been defined. */
 833: //  for (l = defined_prog_list; l; l = CB_CHAIN (l)) {
 834: //   elt_name = ((struct cb_program *) CB_VALUE (l))->program_name;
 835: //   elt_id = ((struct cb_program *) CB_VALUE (l))->orig_program_id;
 836: //   if (cb_fold_call && strcasecmp (prog_name, elt_name) == 0) {
 837: //    cb_error_x ((cb_tree) program,
 838: //         _("redefinition of program name '%s'"),
 839: //         elt_name);
 840: //   } else if (strcmp (prog_id, elt_id) == 0) {
 841: //           cb_error_x ((cb_tree) program,
 842: //         _("redefinition of program ID '%s'"),
 843: //         elt_id);
 844: //    return;
 845: //   }
 846: //  }
 847: //
 848: //  /* Otherwise, add the program to the list. */
 849: //  defined_prog_list = cb_list_add (defined_prog_list,
 850: //       (cb_tree) program);
 851: // }
 852: //
 853: // static void
 854: // remove_program_name (struct cb_list *l, struct cb_list *prev)
 855: // {
 856: //  if (prev == NULL) {
 857: //   defined_prog_list = l->chain;
 858: //  } else {
 859: //   prev->chain = l->chain;
 860: //  }
 861: //  cobc_parse_free (l);
 862: // }
 863: //
 864: // /* Remove the program from defined_prog_list, if necessary. */
 865: // static void
 866: // end_scope_of_program_name (struct cb_program *program, const unsigned char type)
 867: // {
 868: //  struct cb_list *prev = NULL;
 869: //  struct cb_list *l = (struct cb_list *) defined_prog_list;
 870: //
 871: //  /* create empty entry if the program has no PROCEDURE DIVISION, error for UDF */
 872: //  if (!program->entry_list) {
 873: //   if (type == CB_FUNCTION_TYPE) {
 874: //    cb_error (_("FUNCTION '%s' has no PROCEDURE DIVISION"), program->program_name);
 875: //   } else {
 876: //    emit_entry (program->program_id, 0, NULL, NULL);
 877: //   }
 878: //  }
 879: //
 880: //  if (program->nested_level == 0) {
 881: //   return;
 882: //  }
 883: //
 884: //  /* Remove any subprograms */
 885: //  l = CB_LIST (defined_prog_list);
 886: //  while (l) {
 887: //   if (CB_PROGRAM (l->value)->nested_level > program->nested_level) {
 888: //    remove_program_name (l, prev);
 889: //   } else {
 890: //    prev = l;
 891: //   }
 892: //   if (prev && prev->chain != NULL) {
 893: //    l = CB_LIST (prev->chain);
 894: //   } else {
 895: //    l = NULL;
 896: //   }
 897: //  }
 898: //
 899: //  /* Remove the specified program, if it is not COMMON */
 900: //  if (!program->flag_common) {
 901: //   l = (struct cb_list *) defined_prog_list;
 902: //   while (l) {
 903: //    if (strcmp (program->orig_program_id,
 904: //         CB_PROGRAM (l->value)->orig_program_id)
 905: //        == 0) {
 906: //     remove_program_name (l, prev);
 907: //     if (prev && prev->chain != NULL) {
 908: //      l = CB_LIST (prev->chain);
 909: //     } else {
 910: //      l = NULL;
 911: //     }
 912: //     break;
 913: //    } else {
 914: //     prev = l;
 915: //     if (l->chain != NULL) {
 916: //      l = CB_LIST (l->chain);
 917: //     } else {
 918: //      l = NULL;
 919: //     }
 920: //    }
 921: //   }
 922: //  }
 923: // }
 924: //
 925: // static void
 926: // setup_program_start (void)
 927: // {
 928: //  if (setup_from_identification) {
 929: //   setup_from_identification = 0;
 930: //   return;
 931: //  }
 932: //  current_section = NULL;
 933: //  current_paragraph = NULL;
 934: //
 935: //  if (depth != 0 && first_nested_program) {
 936: //   check_headers_present (COBC_HD_PROCEDURE_DIVISION, 0, 0, 0);
 937: //  }
 938: //  first_nested_program = 1;
 939: // }
 940: //
 941: // static int
 942: // setup_program (cb_tree id, cb_tree as_literal, const unsigned char type)
 943: // {
 944: //  setup_program_start ();
 945: //
 946: //  if (first_prog) {
 947: //   first_prog = 0;
 948: //  } else {
 949: //   if (!current_program->flag_validated) {
 950: //    current_program->flag_validated = 1;
 951: //    cb_validate_program_body (current_program);
 952: //   }
 953: //
 954: //   clear_initial_values ();
 955: //   current_program = cb_build_program (current_program, depth);
 956: //   build_nested_special (depth);
 957: //   cb_set_intr_when_compiled ();
 958: //   cb_build_registers ();
 959: //  }
 960: //
 961: //  if (CB_LITERAL_P (id)) {
 962: //   stack_progid[depth] = (char *)(CB_LITERAL (id)->data);
 963: //  } else {
 964: //   stack_progid[depth] = (char *)(CB_NAME (id));
 965: //  }
 966: //
 967: //  if (depth != 0 && type == CB_FUNCTION_TYPE) {
 968: //   cb_error (_("functions may not be defined within a program/function"));
 969: //  }
 970: //
 971: //  if (increment_depth ()) {
 972: //   return 1;
 973: //  }
 974: //
 975: //  current_program->program_id = cb_build_program_id (id, as_literal, type == CB_FUNCTION_TYPE);
 976: //  current_program->prog_type = type;
 977: //
 978: //  if (type == CB_PROGRAM_TYPE) {
 979: //   if (!main_flag_set) {
 980: //    main_flag_set = 1;
 981: //    current_program->flag_main = !!cobc_flag_main;
 982: //   }
 983: //  } else { /* CB_FUNCTION_TYPE */
 984: //   current_program->flag_recursive = 1;
 985: //  }
 986: //
 987: //  if (CB_REFERENCE_P (id)) {
 988: //          cb_define (id, CB_TREE (current_program));
 989: //  }
 990: //
 991: //  begin_scope_of_program_name (current_program);
 992: //
 993: //  return 0;
 994: // }
 995: //
 996: // static void
 997: // decrement_depth (const char *name, const unsigned char type)
 998: // {
 999: //  int d;
1000: //
1001: //  if (depth) {
1002: //   depth--;
1003: //  }
1004: //
1005: //  if (!strcmp (stack_progid[depth], name)) {
1006: //   return;
1007: //  }
1008: //
1009: //  if (type == CB_FUNCTION_TYPE) {
1010: //   cb_error (_("END FUNCTION '%s' is different from FUNCTION-ID '%s'"),
1011: //      name, stack_progid[depth]);
1012: //   return;
1013: //  }
1014: //
1015: //  /* Set depth to that of whatever program we just ended, if it exists. */
1016: //  for (d = depth; d >= 0; --d) {
1017: //   if (!strcmp (stack_progid[d], name)) {
1018: //    depth = d;
1019: //    return;
1020: //   }
1021: //  }
1022: //
1023: //  if (depth != d) {
1024: //   cb_error (_("END PROGRAM '%s' is different from PROGRAM-ID '%s'"),
1025: //      name, stack_progid[depth]);
1026: //  }
1027: // }
1028: //
1029: // static void
1030: // clean_up_program (cb_tree name, const unsigned char type)
1031: // {
1032: //  char  *s;
1033: //
1034: //  end_scope_of_program_name (current_program, type);
1035: //
1036: //  if (name) {
1037: //   if (CB_LITERAL_P (name)) {
1038: //    s = (char *)(CB_LITERAL (name)->data);
1039: //   } else {
1040: //    s = (char *)(CB_NAME (name));
1041: //   }
1042: //
1043: //   decrement_depth (s, type);
1044: //  }
1045: //
1046: //  current_section = NULL;
1047: //  current_paragraph = NULL;
1048: //  if (!current_program->flag_validated) {
1049: //   current_program->flag_validated = 1;
1050: //   cb_validate_program_body (current_program);
1051: //  }
1052: // }
1053: //
1054: // static const char *
1055: // get_literal_or_word_name (const cb_tree x)
1056: // {
1057: //  if (CB_LITERAL_P (x)) {
1058: //   return (const char *) CB_LITERAL (x)->data;
1059: //  } else { /* CB_REFERENCE_P (x) */
1060: //   return (const char *) CB_NAME (x);
1061: //  }
1062: // }
1063: //
1064: // /* verify and set picture sign for currency */
1065: // static void
1066: // set_currency_picture_symbol (const cb_tree x)
1067: // {
1068: //  unsigned char *s  = CB_LITERAL (x)->data;
1069: //
1070: //  if (CB_LITERAL (x)->size != 1) {
1071: //   cb_error_x (x, _("PICTURE SYMBOL for CURRENCY must be one character long"));
1072: //   return;
1073: //  }
1074: //  switch (*s) {
1075: //  case '0':
1076: //  case '1':
1077: //  case '2':
1078: //  case '3':
1079: //  case '4':
1080: //  case '5':
1081: //  case '6':
1082: //  case '7':
1083: //  case '8':
1084: //  case '9':
1085: //  case 'A':
1086: //  case 'B':
1087: //  case 'C':
1088: //  case 'D':
1089: //  case 'E':
1090: //  case 'N':
1091: //  case 'P':
1092: //  case 'R':
1093: //  case 'S':
1094: //  case 'V':
1095: //  case 'X':
1096: //  case 'Z':
1097: //  case 'a':
1098: //  case 'b':
1099: //  case 'c':
1100: //  case 'd':
1101: //  case 'e':
1102: //  case 'n':
1103: //  case 'p':
1104: //  case 'r':
1105: //  case 's':
1106: //  case 'v':
1107: //  case 'x':
1108: //  case 'z':
1109: //  case '+':
1110: //  case '-':
1111: //  case ',':
1112: //  case '.':
1113: //  case '*':
1114: //  case '/':
1115: //  case ';':
1116: //  case '(':
1117: //  case ')':
1118: //  case '=':
1119: //  case '\'':
1120: //  case '"':
1121: //  case ' ':
1122: //   cb_error_x (x, _("invalid character '%c' in PICTURE SYMBOL for CURRENCY"), s[0]);
1123: //   return;
1124: //  default:
1125: //   break;
1126: //  }
1127: //  current_program->currency_symbol = s[0];
1128: // }
1129: //
1130: // /* Return 1 if the prototype name is the same as the current function's. */
1131: // static int
1132: // check_prototype_redefines_current_element (const cb_tree prototype_name)
1133: // {
1134: //  const char *name = get_literal_or_word_name (prototype_name);
1135: //
1136: //  if (strcasecmp (name, current_program->program_name) == 0) {
1137: //   cb_warning_x (COBC_WARN_FILLER, prototype_name,
1138: //    _("prototype has same name as current function and will be ignored"));
1139: //   return 1;
1140: //  }
1141: //
1142: //  return 0;
1143: // }
1144: //
1145: // /* Returns 1 if the prototype has been duplicated. */
1146: // static int
1147: // check_for_duplicate_prototype (const cb_tree prototype_name,
1148: //           const cb_tree prototype)
1149: // {
1150: //  cb_tree dup;
1151: //
1152: //  if (CB_WORD_COUNT (prototype_name) > 0) {
1153: //   /* Make sure the duplicate is a prototype */
1154: //   dup = cb_ref (prototype_name);
1155: //   if (!CB_PROTOTYPE_P (dup)) {
1156: //    redefinition_error (prototype_name);
1157: //    return 1;
1158: //   }
1159: //
1160: //   /* Check the duplicate prototypes match */
1161: //   if (strcmp (CB_PROTOTYPE (prototype)->ext_name,
1162: //        CB_PROTOTYPE (dup)->ext_name)
1163: //       || CB_PROTOTYPE (prototype)->type != CB_PROTOTYPE (dup)->type) {
1164: //    cb_error_x (prototype_name,
1165: //         _("duplicate REPOSITORY entries for '%s' do not match"),
1166: //         get_literal_or_word_name (prototype_name));
1167: //   } else {
1168: //    cb_warning_x (COBC_WARN_FILLER, prototype_name,
1169: //           _("duplicate REPOSITORY entry for '%s'"),
1170: //           get_literal_or_word_name (prototype_name));
1171: //   }
1172: //   return 1;
1173: //  }
1174: //
1175: //  return 0;
1176: // }
1177: //
1178: // static void
1179: // setup_prototype (cb_tree prototype_name, cb_tree ext_name,
1180: //     const int type, const int is_current_element)
1181: // {
1182: //  cb_tree prototype;
1183: //  int name_redefinition_allowed;
1184: //
1185: //  if (!is_current_element
1186: //      && check_prototype_redefines_current_element (prototype_name)) {
1187: //   return;
1188: //  }
1189: //
1190: //  prototype = cb_build_prototype (prototype_name, ext_name, type);
1191: //
1192: //  if (!is_current_element
1193: //      && check_for_duplicate_prototype (prototype_name, prototype)) {
1194: //   return;
1195: //  }
1196: //
1197: //  name_redefinition_allowed = type == CB_PROGRAM_TYPE
1198: //   && is_current_element && cb_program_name_redefinition;
1199: //  if (!name_redefinition_allowed) {
1200: //   if (CB_LITERAL_P (prototype_name)) {
1201: //    cb_define (cb_build_reference ((const char *)CB_LITERAL (prototype_name)->data), prototype);
1202: //   } else {
1203: //    cb_define (prototype_name, prototype);
1204: //   }
1205: //
1206: //   if (type == CB_PROGRAM_TYPE) {
1207: //    current_program->program_spec_list =
1208: //     cb_list_add (current_program->program_spec_list, prototype);
1209: //   } else { /* CB_FUNCTION_TYPE */
1210: //    current_program->user_spec_list =
1211: //     cb_list_add (current_program->user_spec_list, prototype);
1212: //   }
1213: //  }
1214: // }
1215: //
1216: // static void
1217: // error_if_invalid_level_for_renames (cb_tree item)
1218: // {
1219: //  int level = CB_FIELD (cb_ref (item))->level;
1220: //
1221: //  if (level == 1 || level == 66 || level == 77) {
1222: //          cb_verify (cb_renames_uncommon_levels,
1223: //       _("RENAMES of 01-, 66- and 77-level items"));
1224: //  } else if (level == 88) {
1225: //   cb_error (_("RENAMES may not reference a level 88"));
1226: //  }
1227: // }
1228: //
1229: // static int
1230: // set_current_field (cb_tree level, cb_tree name)
1231: // {
1232: //  cb_tree x  = cb_build_field_tree (level, name, current_field,
1233: //        current_storage, current_file, 0);
1234: //  cobc_parse_free (level);
1235: //
1236: //  if (CB_INVALID_TREE (x)) {
1237: //          return 1;
1238: //  } else {
1239: //   current_field = CB_FIELD (x);
1240: //   check_pic_duplicate = 0;
1241: //  }
1242: //
1243: //  return 0;
1244: // }
1245: //
1246: // static void
1247: // check_not_both (const cob_flags_t flag1, const cob_flags_t flag2,
1248: //   const char *flag1_name, const char *flag2_name,
1249: //   const cob_flags_t flags, const cob_flags_t flag_to_set)
1250: // {
1251: //  if (flag_to_set == flag1 && (flags & flag2)) {
1252: //   cb_error (_("cannot specify both %s and %s"),
1253: //      flag1_name, flag2_name);
1254: //  } else if (flag_to_set == flag2 && (flags & flag1)) {
1255: //   cb_error (_("cannot specify both %s and %s"),
1256: //      flag1_name, flag2_name);
1257: //
1258: //  }
1259: // }
1260: //
1261: // static COB_INLINE COB_A_INLINE void
1262: // check_not_highlight_and_lowlight (const cob_flags_t flags,
1263: //       const cob_flags_t flag_to_set)
1264: // {
1265: //  check_not_both (COB_SCREEN_HIGHLIGHT, COB_SCREEN_LOWLIGHT,
1266: //    "HIGHLIGHT", "LOWLIGHT", flags, flag_to_set);
1267: // }
1268: //
1269: // static void
1270: // set_screen_attr (const char *clause, const cob_flags_t bitval)
1271: // {
1272: //  if (current_field->screen_flag & bitval) {
1273: //   emit_duplicate_clause_message (clause);
1274: //  } else {
1275: //   current_field->screen_flag |= bitval;
1276: //  }
1277: // }
1278: //
1279: // static void
1280: // emit_conflicting_clause_message (const char *clause, const char *conflicting)
1281: // {
1282: //  if (cb_relaxed_syntax_checks) {
1283: //   cb_warning (COBC_WARN_FILLER, _("cannot specify both %s and %s; %s is ignored"),
1284: //    clause, conflicting, clause);
1285: //  } else {
1286: //   cb_error (_("cannot specify both %s and %s"),
1287: //    clause, conflicting);
1288: //  }
1289: //
1290: // }
1291: //
1292: // static void
1293: // set_attr_with_conflict (const char *clause, const cob_flags_t bitval,
1294: //    const char *confl_clause, const cob_flags_t confl_bit,
1295: //    const int local_check_duplicate, cob_flags_t *flags)
1296: // {
1297: //  if (local_check_duplicate && (*flags & bitval)) {
1298: //   emit_duplicate_clause_message (clause);
1299: //  } else if (*flags & confl_bit) {
1300: //   emit_conflicting_clause_message (clause, confl_clause);
1301: //  } else {
1302: //  *flags |= bitval;
1303: //  }
1304: // }
1305: //
1306: // static COB_INLINE COB_A_INLINE void
1307: // set_screen_attr_with_conflict (const char *clause, const cob_flags_t bitval,
1308: //           const char *confl_clause,
1309: //           const cob_flags_t confl_bit)
1310: // {
1311: //  set_attr_with_conflict (clause, bitval, confl_clause, confl_bit, 1,
1312: //     &current_field->screen_flag);
1313: // }
1314: //
1315: // static COB_INLINE COB_A_INLINE int
1316: // has_dispattr (const cob_flags_t attrib)
1317: // {
1318: //  return current_statement->attr_ptr
1319: //   && current_statement->attr_ptr->dispattrs & attrib;
1320: // }
1321: //
1322: // static void
1323: // attach_attrib_to_cur_stmt (void)
1324: // {
1325: //  if (!current_statement->attr_ptr) {
1326: //   current_statement->attr_ptr =
1327: //    cobc_parse_malloc (sizeof(struct cb_attr_struct));
1328: //  }
1329: // }
1330: //
1331: // static COB_INLINE COB_A_INLINE void
1332: // set_dispattr (const cob_flags_t attrib)
1333: // {
1334: //  attach_attrib_to_cur_stmt ();
1335: //  current_statement->attr_ptr->dispattrs |= attrib;
1336: // }
1337: //
1338: // static COB_INLINE COB_A_INLINE void
1339: // set_dispattr_with_conflict (const char *attrib_name, const cob_flags_t attrib,
1340: //        const char *confl_name,
1341: //        const cob_flags_t confl_attrib)
1342: // {
1343: //  attach_attrib_to_cur_stmt ();
1344: //  set_attr_with_conflict (attrib_name, attrib, confl_name, confl_attrib, 0,
1345: //     &current_statement->attr_ptr->dispattrs);
1346: // }
1347: //
1348: // static void
1349: // bit_set_attr (const cb_tree on_off, const cob_flags_t attr_val)
1350: // {
1351: //  if (on_off == cb_int1) {
1352: //   set_attr_val_on |= attr_val;
1353: //  } else {
1354: //   set_attr_val_off |= attr_val;
1355: //  }
1356: // }
1357: //
1358: // static void
1359: // set_field_attribs (cb_tree fgc, cb_tree bgc, cb_tree scroll,
1360: //      cb_tree timeout, cb_tree prompt, cb_tree size_is)
1361: // {
1362: //  /* [WITH] FOREGROUND-COLOR [IS] */
1363: //  if (fgc) {
1364: //   current_statement->attr_ptr->fgc = fgc;
1365: //  }
1366: //  /* [WITH] BACKGROUND-COLOR [IS] */
1367: //  if (bgc) {
1368: //   current_statement->attr_ptr->bgc = bgc;
1369: //  }
1370: //  /* [WITH] SCROLL UP | DOWN */
1371: //  if (scroll) {
1372: //   current_statement->attr_ptr->scroll = scroll;
1373: //  }
1374: //  /* [WITH] TIME-OUT [AFTER] */
1375: //  if (timeout) {
1376: //   current_statement->attr_ptr->timeout = timeout;
1377: //  }
1378: //  /* [WITH] PROMPT CHARACTER [IS] */
1379: //  if (prompt) {
1380: //   current_statement->attr_ptr->prompt = prompt;
1381: //  }
1382: //  /* [WITH] SIZE [IS] */
1383: //  if (size_is) {
1384: //   current_statement->attr_ptr->size_is = size_is;
1385: //  }
1386: // }
1387: //
1388: // static void
1389: // set_attribs (cb_tree fgc, cb_tree bgc, cb_tree scroll,
1390: //       cb_tree timeout, cb_tree prompt, cb_tree size_is,
1391: //       const cob_flags_t attrib)
1392: // {
1393: //  attach_attrib_to_cur_stmt ();
1394: //  set_field_attribs (fgc, bgc, scroll, timeout, prompt, size_is);
1395: //
1396: //  current_statement->attr_ptr->dispattrs |= attrib;
1397: // }
1398: //
1399: // static void
1400: // set_attribs_with_conflict  (cb_tree fgc, cb_tree bgc, cb_tree scroll,
1401: //        cb_tree timeout, cb_tree prompt, cb_tree size_is,
1402: //        const char *clause_name, const cob_flags_t attrib,
1403: //        const char *confl_name, const cob_flags_t confl_attrib)
1404: // {
1405: //  attach_attrib_to_cur_stmt ();
1406: //  set_field_attribs (fgc, bgc, scroll, timeout, prompt, size_is);
1407: //
1408: //  set_dispattr_with_conflict (clause_name, attrib, confl_name,
1409: //         confl_attrib);
1410: // }
1411: //
1412: // static cob_flags_t
1413: // zero_conflicting_flag (const cob_flags_t screen_flag, cob_flags_t parent_flag,
1414: //     const cob_flags_t flag1, const cob_flags_t flag2)
1415: // {
1416: //  if (screen_flag & flag1) {
1417: //   parent_flag &= ~flag2;
1418: //  } else if (screen_flag & flag2) {
1419: //   parent_flag &= ~flag1;
1420: //  }
1421: //
1422: //  return parent_flag;
1423: // }
1424: //
1425: // static cob_flags_t
1426: // zero_conflicting_flags (const cob_flags_t screen_flag, cob_flags_t parent_flag)
1427: // {
1428: //  parent_flag = zero_conflicting_flag (screen_flag, parent_flag,
1429: //           COB_SCREEN_BLANK_LINE,
1430: //           COB_SCREEN_BLANK_SCREEN);
1431: //  parent_flag = zero_conflicting_flag (screen_flag, parent_flag,
1432: //           COB_SCREEN_ERASE_EOL,
1433: //           COB_SCREEN_ERASE_EOS);
1434: //  parent_flag = zero_conflicting_flag (screen_flag, parent_flag,
1435: //           COB_SCREEN_HIGHLIGHT,
1436: //           COB_SCREEN_LOWLIGHT);
1437: //
1438: //  return parent_flag;
1439: // }
1440: //
1441: // static void
1442: // check_and_set_usage (const enum cb_usage usage)
1443: // {
1444: //  check_repeated ("USAGE", SYN_CLAUSE_5, &check_pic_duplicate);
1445: //  current_field->usage = usage;
1446: // }
1447: //
1448: // static void
1449: // check_preceding_tallying_phrases (const enum tallying_phrase phrase)
1450: // {
1451: //  switch (phrase) {
1452: //  case FOR_PHRASE:
1453: //   if (previous_tallying_phrase == ALL_LEADING_TRAILING_PHRASES) {
1454: //    cb_error (_("FOR phrase cannot immediately follow ALL/LEADING/TRAILING"));
1455: //   } else if (previous_tallying_phrase == FOR_PHRASE) {
1456: //    cb_error (_("missing CHARACTERS/ALL/LEADING/TRAILING phrase after FOR phrase"));
1457: //   }
1458: //   break;
1459: //
1460: //  case CHARACTERS_PHRASE:
1461: //  case ALL_LEADING_TRAILING_PHRASES:
1462: //   if (previous_tallying_phrase == NO_PHRASE) {
1463: //    cb_error (_("missing FOR phrase before CHARACTERS/ALL/LEADING/TRAILING phrase"));
1464: //   } else if (previous_tallying_phrase == CHARACTERS_PHRASE
1465: //       || previous_tallying_phrase == ALL_LEADING_TRAILING_PHRASES) {
1466: //    cb_error (_("missing value between CHARACTERS/ALL/LEADING/TRAILING words"));
1467: //   }
1468: //   break;
1469: //
1470: //  case VALUE_REGION_PHRASE:
1471: //   if (!(previous_tallying_phrase == ALL_LEADING_TRAILING_PHRASES
1472: //         || previous_tallying_phrase == VALUE_REGION_PHRASE)) {
1473: //    cb_error (_("missing ALL/LEADING/TRAILING before value"));
1474: //   }
1475: //   break;
1476: //
1477: //   /* LCOV_EXCL_START */
1478: //  default:
1479: //   /* This should never happen (and therefore doesn't get a translation) */
1480: //   cb_error ("unexpected tallying phrase");
1481: //   COBC_ABORT();
1482: //   /* LCOV_EXCL_END */
1483: //  }
1484: //
1485: //  previous_tallying_phrase = phrase;
1486: // }
1487: //
1488: // static int
1489: // has_relative_pos (struct cb_field const *field)
1490: // {
1491: //  return !!(field->screen_flag
1492: //     & (COB_SCREEN_LINE_PLUS | COB_SCREEN_LINE_MINUS
1493: //        | COB_SCREEN_COLUMN_PLUS | COB_SCREEN_COLUMN_MINUS));
1494: // }
1495: //
1496: // static int
1497: // is_recursive_call (cb_tree target)
1498: // {
1499: //  const char *target_name = "";
1500: //
1501: //  if (CB_LITERAL_P (target)) {
1502: //   target_name = (const char *)(CB_LITERAL(target)->data);
1503: //  } else if (CB_REFERENCE_P (target)
1504: //      && CB_PROTOTYPE_P (cb_ref (target))) {
1505: //   target_name = CB_PROTOTYPE (cb_ref (target))->ext_name;
1506: //  }
1507: //
1508: //  return !strcmp (target_name, current_program->orig_program_id);
1509: // }
1510: //
1511: // static void
1512: // check_not_88_level (cb_tree x)
1513: // {
1514: //  struct cb_field *f;
1515: //
1516: //  if (x == cb_error_node || x->tag != CB_TAG_REFERENCE) {
1517: //   return;
1518: //  }
1519: //
1520: //  f = CB_FIELD (cb_ref (x));
1521: //
1522: //  if (f != (struct cb_field *) cb_error_node && f->level == 88) {
1523: //   cb_error (_("88-level cannot be used here"));
1524: //  }
1525: // }
1526: //
1527: // static int
1528: // is_screen_field (cb_tree x)
1529: // {
1530: //  if (CB_FIELD_P (x)) {
1531: //   return (CB_FIELD (x))->storage == CB_STORAGE_SCREEN;
1532: //  } else if (CB_REFERENCE_P (x)) {
1533: //   return is_screen_field (cb_ref (x));
1534: //  } else {
1535: //   return 0;
1536: //  }
1537: // }
1538: //
1539: // static void
1540: // error_if_no_advancing_in_screen_display (cb_tree advancing)
1541: // {
1542: //  if (advancing != cb_int1) {
1543: //   cb_error (_("cannot specify NO ADVANCING in screen DISPLAY"));
1544: //  }
1545: // }
1546: //
1547: // static cb_tree
1548: // get_default_display_device (void)
1549: // {
1550: //  if (current_program->flag_console_is_crt
1551: //      || cb_console_is_crt) {
1552: //   return cb_null;
1553: //  } else {
1554: //   return cb_int0;
1555: //  }
1556: // }
1557: //
1558: // static COB_INLINE COB_A_INLINE int
1559: // contains_one_screen_field (struct cb_list *x_list)
1560: // {
1561: //  return (cb_tree) x_list != cb_null
1562: //   && cb_list_length ((cb_tree) x_list) == 1
1563: //   && is_screen_field (x_list->value);
1564: // }
1565: //
1566: // static int
1567: // contains_only_screen_fields (struct cb_list *x_list)
1568: // {
1569: //  if ((cb_tree) x_list == cb_null) {
1570: //   return 0;
1571: //  }
1572: //
1573: //  for (; x_list; x_list = (struct cb_list *) x_list->chain) {
1574: //   if (!is_screen_field (x_list->value)) {
1575: //    return 0;
1576: //   }
1577: //  }
1578: //
1579: //  return 1;
1580: // }
1581: //
1582: // static int
1583: // contains_fields_and_screens (struct cb_list *x_list)
1584: // {
1585: //  int field_seen = 0;
1586: //  int screen_seen = 0;
1587: //
1588: //  if ((cb_tree) x_list == cb_null) {
1589: //   return 0;
1590: //  }
1591: //
1592: //  for (; x_list; x_list = (struct cb_list *) x_list->chain) {
1593: //   if (is_screen_field (x_list->value)) {
1594: //    screen_seen = 1;
1595: //   } else {
1596: //    field_seen = 1;
1597: //   }
1598: //  }
1599: //
1600: //  return screen_seen && field_seen;
1601: // }
1602: //
1603: // static enum cb_display_type
1604: // deduce_display_type (cb_tree x_list, cb_tree local_upon_value, cb_tree local_line_column,
1605: //        struct cb_attr_struct * const attr_ptr)
1606: // {
1607: //  int using_default_device_which_is_crt =
1608: //   local_upon_value == NULL && get_default_display_device () == cb_null;
1609: //
1610: //  if (contains_only_screen_fields ((struct cb_list *) x_list)) {
1611: //   if (!contains_one_screen_field ((struct cb_list *) x_list)
1612: //       || attr_ptr) {
1613: //    cb_verify_x (x_list, cb_accept_display_extensions,
1614: //          _("non-standard DISPLAY"));
1615: //   }
1616: //
1617: //   if (local_upon_value != NULL && local_upon_value != cb_null) {
1618: //    cb_error_x (x_list, _("screens may only be displayed on CRT"));
1619: //   }
1620: //
1621: //   return SCREEN_DISPLAY;
1622: //  } else if (contains_fields_and_screens ((struct cb_list *) x_list)) {
1623: //   cb_error_x (x_list, _("cannot mix screens and fields in the same DISPLAY statement"));
1624: //   return MIXED_DISPLAY;
1625: //  } else if (local_line_column || attr_ptr) {
1626: //   if (local_upon_value != NULL && local_upon_value != cb_null) {
1627: //    cb_error_x (x_list, _("screen clauses may only be used for DISPLAY on CRT"));
1628: //   }
1629: //
1630: //   cb_verify_x (x_list, cb_accept_display_extensions,
1631: //         _("non-standard DISPLAY"));
1632: //
1633: //   return FIELD_ON_SCREEN_DISPLAY;
1634: //  } else if (local_upon_value == cb_null || using_default_device_which_is_crt) {
1635: //   /* This is the only format permitted by the standard */
1636: //   return FIELD_ON_SCREEN_DISPLAY;
1637: //  } else if (display_type == FIELD_ON_SCREEN_DISPLAY && local_upon_value == NULL) {
1638: //   /* This is for when fields without clauses follow fields with screen clauses */
1639: //   return FIELD_ON_SCREEN_DISPLAY;
1640: //  } else {
1641: //   return DEVICE_DISPLAY;
1642: //  }
1643: // }
1644: //
1645: // static void
1646: // set_display_type (cb_tree x_list, cb_tree local_upon_value,
1647: //     cb_tree local_line_column, struct cb_attr_struct * const attr_ptr)
1648: // {
1649: //  display_type = deduce_display_type (x_list, local_upon_value, local_line_column, attr_ptr);
1650: // }
1651: //
1652: // static void
1653: // error_if_different_display_type (cb_tree x_list, cb_tree local_upon_value,
1654: //      cb_tree local_line_column, struct cb_attr_struct * const attr_ptr)
1655: // {
1656: //         const enum cb_display_type type =
1657: //   deduce_display_type (x_list, local_upon_value, local_line_column, attr_ptr);
1658: //
1659: //  /* Avoid re-displaying the same error for mixed DISPLAYs */
1660: //  if (type == display_type || display_type == MIXED_DISPLAY) {
1661: //   return;
1662: //  }
1663: //
1664: //  if (type != MIXED_DISPLAY) {
1665: //   if (type == SCREEN_DISPLAY || display_type == SCREEN_DISPLAY) {
1666: //    cb_error_x (x_list, _("cannot mix screens and fields in the same DISPLAY statement"));
1667: //   } else {
1668: //    /*
1669: //      The only other option is that there is a mix of
1670: //      FIELD_ON_SCREEN_DISPLAY and DEVICE_DISPLAY.
1671: //    */
1672: //    cb_error_x (x_list, _("ambiguous DISPLAY; put items to display on device in separate DISPLAY"));
1673: //   }
1674: //  }
1675: //
1676: //  display_type = MIXED_DISPLAY;
1677: // }
1678: //
1679: // static void
1680: // error_if_not_usage_display_or_nonnumeric_lit (cb_tree x)
1681: // {
1682: //  const int is_numeric_literal = CB_NUMERIC_LITERAL_P (x);
1683: //  const int is_field_with_usage_not_display =
1684: //   CB_REFERENCE_P (x) && CB_FIELD (cb_ref (x))
1685: //   && CB_FIELD (cb_ref (x))->usage != CB_USAGE_DISPLAY;
1686: //
1687: //  if (is_numeric_literal) {
1688: //   cb_error_x (x, _("%s is not an alphanumeric literal"), CB_LITERAL (x)->data);
1689: //  } else if (is_field_with_usage_not_display) {
1690: //   cb_error_x (x, _("'%s' is not USAGE DISPLAY"), cb_name (x));
1691: //  }
1692: // }
1693: //
1694: %}
1695:
1696: %token TOKEN_EOF 0 "end of file"
^^^^...................^
1697:
1698: %token ACCEPT

    at Object.parseError (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:20353:15)
    at Object.yyError (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:20509:26)
    at Object.parser__PerformAction (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:17687:14)
    at Object.parse (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:21537:52)
    at Object.parse (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:24377:23)
    at autodetectAndConvertToJSONformat (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:25559:32)
    at new Jison_Generator (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:33713:15)
    at Object.generateParserString (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:34263:25)
    at processInputFile (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:34174:30)
    at Object.cliMain [as main] (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs.js:34252:13)

And here's a (...continued...) example for reference:

                throw err;
                ^

JisonParserError:
production rule action code block does not compile: Line 634: Unexpected token ILLEGAL

  Erroneous area:
613:     : handle prec action
614:         {
^^^..........^^
615:             $$ = [($handle.length ? $handle.join(' ') : '')];
^^^..^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     (...continued...)
---  (---------------)
641:             }
^^^..^^^^^^^^^^^^^^
642:         }
^^^..^^^^^^^^^
643:     | EPSILON action
644:         // %epsilon may only be used to signal this is an empty rule alt;

    at Object.parseError (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:14408:19)
    at Object.yyError (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:14547:30)
    at Object.parser__PerformAction (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:14057:34)
    at Object.parse (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:15518:48)
    at Object.parse (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:17891:23)
    at autodetectAndConvertToJSONformat (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:18965:36)
    at new Jison_Generator (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:24550:15)
    at Object.generateParserString (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:25066:25)
    at processInputFile (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:24977:30)
    at Object.cliMain [as main] (W:\Users\Ger\Projects\sites\library.visyond.gov\80\lib\tooling\jison\dist\cli-cjs-es5.js:25055:13)
make[1]: *** [Makefile:33: build] Error 1
GerHobbelt commented 6 years ago

As observed in #27