Hi tech -- I attemped to build a DEBUG version of yacc. gcc gave warnings and clang errored out, so I turned on WARNINGS=yes and fixed all the warnings.
OpenBSD seems to be upstream for this version of byacc, as the other BSDs follow Thomas Dickey's byacc. ~Brian Index: closure.c =================================================================== RCS file: /cvs/src/usr.bin/yacc/closure.c,v retrieving revision 1.14 diff -u -p -u -p -r1.14 closure.c --- closure.c 2 Dec 2014 15:56:22 -0000 1.14 +++ closure.c 15 May 2017 16:56:56 -0000 @@ -43,7 +43,76 @@ static unsigned *first_derives; static unsigned *EFF; -void +#ifdef DEBUG + +static void +print_closure(int n) +{ + short *isp; + + printf("\n\nn = %d\n\n", n); + for (isp = itemset; isp < itemsetend; isp++) + printf(" %d\n", *isp); +} + +static void +print_EFF(void) +{ + int i, j; + unsigned int *rowp; + unsigned int k, word; + + printf("\n\nEpsilon Free Firsts\n"); + + for (i = start_symbol; i < nsyms; i++) { + printf("\n%s", symbol_name[i]); + rowp = EFF + ((i - start_symbol) * WORDSIZE(nvars)); + word = *rowp++; + + k = BITS_PER_WORD; + for (j = 0; j < nvars; k++, j++) { + if (k >= BITS_PER_WORD) { + word = *rowp++; + k = 0; + } + + if (word & (1 << k)) + printf(" %s", symbol_name[start_symbol + j]); + } + } +} + +static void +print_first_derives(void) +{ + int i, j; + unsigned int *rp; + unsigned int k, cword = 0; + + printf("\n\n\nFirst Derives\n"); + + for (i = start_symbol; i < nsyms; i++) { + printf("\n%s derives\n", symbol_name[i]); + rp = first_derives + i * WORDSIZE(nrules); + k = BITS_PER_WORD; + for (j = 0; j <= nrules; k++, j++) { + if (k >= BITS_PER_WORD) { + cword = *rp++; + k = 0; + } + + if (cword & (1 << k)) + printf(" %d\n", j); + } + } + + fflush(stdout); +} + +#endif + + +static void set_EFF(void) { unsigned int *row; @@ -177,72 +246,3 @@ finalize_closure(void) free(ruleset); free(first_derives + ntokens * WORDSIZE(nrules)); } - - -#ifdef DEBUG - -void -print_closure(int n) -{ - short *isp; - - printf("\n\nn = %d\n\n", n); - for (isp = itemset; isp < itemsetend; isp++) - printf(" %d\n", *isp); -} - -void -print_EFF(void) -{ - int i, j; - unsigned int *rowp; - unsigned int k, word; - - printf("\n\nEpsilon Free Firsts\n"); - - for (i = start_symbol; i < nsyms; i++) { - printf("\n%s", symbol_name[i]); - rowp = EFF + ((i - start_symbol) * WORDSIZE(nvars)); - word = *rowp++; - - k = BITS_PER_WORD; - for (j = 0; j < nvars; k++, j++) { - if (k >= BITS_PER_WORD) { - word = *rowp++; - k = 0; - } - - if (word & (1 << k)) - printf(" %s", symbol_name[start_symbol + j]); - } - } -} - -void -print_first_derives(void) -{ - int i, j; - unsigned int *rp; - unsigned int k, cword = 0; - - printf("\n\n\nFirst Derives\n"); - - for (i = start_symbol; i < nsyms; i++) { - printf("\n%s derives\n", symbol_name[i]); - rp = first_derives + i * WORDSIZE(nrules); - k = BITS_PER_WORD; - for (j = 0; j <= nrules; k++, j++) { - if (k >= BITS_PER_WORD) { - cword = *rp++; - k = 0; - } - - if (cword & (1 << k)) - printf(" %d\n", j); - } - } - - fflush(stdout); -} - -#endif Index: lalr.c =================================================================== RCS file: /cvs/src/usr.bin/yacc/lalr.c,v retrieving revision 1.18 diff -u -p -u -p -r1.18 lalr.c --- lalr.c 11 Dec 2015 20:25:47 -0000 1.18 +++ lalr.c 15 May 2017 16:56:56 -0000 @@ -52,7 +52,7 @@ short *goto_map; short *from_state; short *to_state; -short **transpose(); +short **transpose(short **, int); void set_state_table(void); void set_accessing_symbol(void); void set_shift_table(void); @@ -448,7 +448,7 @@ add_lookback_edge(int stateno, int rulen short ** -transpose(short **R, int n) +transpose(short **old_R, int n) { short **new_R, **temp_R, *nedges, *sp; int i, k; @@ -456,7 +456,7 @@ transpose(short **R, int n) nedges = NEW2(n, short); for (i = 0; i < n; i++) { - sp = R[i]; + sp = old_R[i]; if (sp) { while (*sp >= 0) nedges[*sp++]++; @@ -479,7 +479,7 @@ transpose(short **R, int n) free(nedges); for (i = 0; i < n; i++) { - sp = R[i]; + sp = old_R[i]; if (sp) { while (*sp >= 0) *temp_R[*sp++]++ = i; Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/yacc/main.c,v retrieving revision 1.28 diff -u -p -u -p -r1.28 main.c --- main.c 27 Jul 2016 20:53:47 -0000 1.28 +++ main.c 15 May 2017 16:56:56 -0000 @@ -122,7 +122,7 @@ done(int k) void -onintr(int signo) +onintr(__unused int signo) { sigdie = 1; done(1); Index: mkpar.c =================================================================== RCS file: /cvs/src/usr.bin/yacc/mkpar.c,v retrieving revision 1.18 diff -u -p -u -p -r1.18 mkpar.c --- mkpar.c 13 Mar 2014 00:59:34 -0000 1.18 +++ mkpar.c 15 May 2017 16:56:56 -0000 @@ -49,10 +49,10 @@ short final_state; static int SRcount; static int RRcount; -extern action *parse_actions(); -extern action *get_shifts(); -extern action *add_reductions(); -extern action *add_reduce(); +extern action *parse_actions(int); +extern action *get_shifts(int); +extern action *add_reductions(int, action *); +extern action *add_reduce(action *, int, int); short sole_reduction(int); void free_action_row(action *); @@ -98,16 +98,16 @@ get_shifts(int stateno) { action *actions, *temp; shifts *sp; - short *to_state; + short *tto_state; int i, k; int symbol; actions = 0; sp = shift_table[stateno]; if (sp) { - to_state = sp->shift; + tto_state = sp->shift; for (i = sp->nshifts - 1; i >= 0; i--) { - k = to_state[i]; + k = tto_state[i]; symbol = accessing_symbol[k]; if (ISTOKEN(symbol)) { temp = NEW(action); @@ -187,14 +187,14 @@ void find_final_state(void) { int goal, i; - short *to_state; + short *tto_state; shifts *p; p = shift_table[0]; - to_state = p->shift; + tto_state = p->shift; goal = ritem[1]; for (i = p->nshifts - 1; i >= 0; --i) { - final_state = to_state[i]; + final_state = tto_state[i]; if (accessing_symbol[final_state] == goal) break; } Index: reader.c =================================================================== RCS file: /cvs/src/usr.bin/yacc/reader.c,v retrieving revision 1.33 diff -u -p -u -p -r1.33 reader.c --- reader.c 22 Mar 2016 18:24:34 -0000 1.33 +++ reader.c 15 May 2017 16:56:57 -0000 @@ -945,7 +945,7 @@ declare_tokens(int assoc) * %expect requires special handling as it really isn't part of the yacc * grammar only a flag for yacc proper. */ -void +static void declare_expect(int assoc) { int c; @@ -1746,7 +1746,7 @@ void pack_grammar(void) { int i, j; - int assoc, prec; + int assoc, pprec; ritem = reallocarray(NULL, nitems, sizeof(short)); if (ritem == NULL) @@ -1780,11 +1780,11 @@ pack_grammar(void) rlhs[i] = plhs[i]->index; rrhs[i] = j; assoc = TOKEN; - prec = 0; + pprec = 0; while (pitem[j]) { ritem[j] = pitem[j]->index; if (pitem[j]->class == TERM) { - prec = pitem[j]->prec; + pprec = pitem[j]->prec; assoc = pitem[j]->assoc; } ++j; @@ -1792,7 +1792,7 @@ pack_grammar(void) ritem[j] = -i; ++j; if (rprec[i] == UNDEFINED) { - rprec[i] = prec; + rprec[i] = pprec; rassoc[i] = assoc; } } Index: verbose.c =================================================================== RCS file: /cvs/src/usr.bin/yacc/verbose.c,v retrieving revision 1.13 diff -u -p -u -p -r1.13 verbose.c --- verbose.c 9 Oct 2014 03:02:18 -0000 1.13 +++ verbose.c 15 May 2017 16:56:57 -0000 @@ -298,7 +298,7 @@ print_shifts(action * p) void -print_reductions(action * p, int defred) +print_reductions(action * p, int pdefred) { int k, anyreds; action *q; @@ -315,7 +315,7 @@ print_reductions(action * p, int defred) fprintf(verbose_file, "\t. error\n"); else { for (; p; p = p->next) { - if (p->action_code == REDUCE && p->number != defred) { + if (p->action_code == REDUCE && p->number != pdefred) { k = p->number - 2; if (p->suppressed == 0) fprintf(verbose_file, "\t%s reduce %d\n", @@ -323,8 +323,8 @@ print_reductions(action * p, int defred) } } - if (defred > 0) - fprintf(verbose_file, "\t. reduce %d\n", defred - 2); + if (pdefred > 0) + fprintf(verbose_file, "\t. reduce %d\n", pdefred - 2); } } @@ -334,14 +334,14 @@ print_gotos(int stateno) { int i, k; int as; - short *to_state; + short *tto_state; shifts *sp; putc('\n', verbose_file); sp = shift_table[stateno]; - to_state = sp->shift; + tto_state = sp->shift; for (i = 0; i < sp->nshifts; ++i) { - k = to_state[i]; + k = tto_state[i]; as = accessing_symbol[k]; if (ISVAR(as)) fprintf(verbose_file, "\t%s goto %d\n",