Akim Demaille [Thu, 13 Dec 2001 11:02:21 +0000 (11:02 +0000)]
The computation of nullable is broken: it doesn't handle empty
RHS's properly.
* tests/torture.at (GNU AWK Grammar): New.
* tests/sets.at (Nullable): New.
* src/nullable.c (set_nullable): Instead of blindly looping over
`ritems', loop over the rules, and then over their rhs's.
Work around Autotest bugs.
* src/warshall.c (bitmatrix_print): Don't use `+--+' as table
frame, because Autotest understand lines starting with a `+' as
traces from the shell. Then, they are not processed properly.
Admittedly an Autotest bug, but we don't have time to wait for
Autotest to catch up.
* tests/regression.at (Broken Closure): Adjust to the new table
frames.
Move to...
* tests/sets.at: here.
Akim Demaille [Thu, 13 Dec 2001 11:01:51 +0000 (11:01 +0000)]
* src/print.c (print_actions): Output the handling of `$' as the
traces do: shifting the token EOF. Before EOF was treated as a
nonterminal.
* tests/regression.at: Adjust some tests.
* src/print_graph.c (print_core): Complete the set of items via
closure. The next-to-final and final states are still unsatisfying,
but that's to be addressed elsewhere.
No longer output the rule numbers, but do output the state number.
A single loop for the shifts + gotos is enough, but picked a
distinct color for each.
(print_graph): Initialize and finalize closure.
Akim Demaille [Wed, 12 Dec 2001 11:58:19 +0000 (11:58 +0000)]
Some hosts don't like `/' in includes.
* src/system.h: Include libgettext.h without qualifying the path.
* src/Makefile.am (INCLUDES): Add $(top_srcdir)/intl, remove
$(top_srcdir).
Marc Autret [Tue, 11 Dec 2001 20:10:22 +0000 (20:10 +0000)]
* src/bison.simple: Remove #line just before %%epilogue. It
is now handled in ...
* src/reader.c (read_additionnal_code): Add the output of a
#line for the epilogue.
Marc Autret [Mon, 10 Dec 2001 23:19:09 +0000 (23:19 +0000)]
* src/reader.c (copy_definition): Re-use CPP-outed code which
replace precedent remove.
* src/bison.simple: Remove #line before %%prologue because
%%input-line is wrong at this time.
Akim Demaille [Mon, 10 Dec 2001 09:09:49 +0000 (09:09 +0000)]
Now that states have a complete set of members, the linked list of
shifts is useless: just fill directly the state's shifts member.
* src/state.h (shifts): Remove the `next' member.
* src/LR0.c (first_state, last_state): Remove.
Adjust the callers.
(augment_automaton): Don't look for the shifts that must be added
a shift on EOF: it is those of the state we looked for! But now,
since shifts are attached, it is no longer needed to looking
merely by its id: its number.
Akim Demaille [Mon, 10 Dec 2001 09:09:28 +0000 (09:09 +0000)]
* src/LR0.c (augment_automaton): Better variable locality.
Remove an impossible branch: if there is a state corresponding to
the start symbol being shifted, then there is shift for the start
symbol from the initial state.
Akim Demaille [Mon, 10 Dec 2001 09:09:14 +0000 (09:09 +0000)]
* src/LR0.c (augment_automaton): Call `insert_eof_shifting_state'
only when appropriate: when insert_start_shifting_state' is not
invoked.
* tests/regression.at (Rule Line Numbers): Adjust.
Akim Demaille [Mon, 10 Dec 2001 09:08:09 +0000 (09:08 +0000)]
* src/LR0.c: Attach shifts to states as soon as they are
computed.
* src/lalr.c (set_state_table): Instead of assigning shifts to
state, just assert that the mapping was properly done.
Akim Demaille [Mon, 10 Dec 2001 09:07:55 +0000 (09:07 +0000)]
* src/LR0.c (insert_start_shift): Rename as...
(insert_start_shifting_state): this.
(insert_eof_shifting_state, insert_accepting_state): New.
(augment_automaton): Adjust.
Better locality of the variables.
When looking if the start_symbol is shifted from the initial
state, using `while (... symbol != start_symbol ...)' sounds
better than `while (... symbol < start_symbol ...)': If fail
to see how the order between symbols could be relevant!
Akim Demaille [Mon, 10 Dec 2001 09:06:48 +0000 (09:06 +0000)]
Now that states have a complete set of members, the linked list of
reductions is useless: just fill directly the state's reductions
member.
* src/state.h (struct reductions): Remove member `number' and
`next'.
* src/LR0.c (first_reduction, last_reduction): Remove.
(save_reductions): Don't link the new reductions, store them in
this_state.
* src/lalr.c (set_state_table): No need to attach reductions to
states, it's already done.
* src/output.c (output_actions): No longer free the shifts, then
the reductions, then the states: free all the states and their
members.
Akim Demaille [Mon, 10 Dec 2001 09:06:27 +0000 (09:06 +0000)]
* src/options.c (OPTN, DRTV, BOTH): New.
(option_table): Use them.
* src/muscle_tab.c: Don't include xalloc.h and string.h: that's
the job of system.h.
* src/options.c: Don't include stdio.h and xalloc.h for the same
reasons.
Akim Demaille [Mon, 10 Dec 2001 09:05:47 +0000 (09:05 +0000)]
Clean up GCC warnings.
* src/reader.c (copy_action): `buf' is not used.
(parse_skel_decl): Be static.
* src/muscle_tab.c (mhash1, mhash2, muscle_insert): Preserve `const'.
* src/options.h (create_long_option_table): Have a real prototype.
* lib/hash.c, lib/hash.h (hash_insert, hash_insert_at, hash_delete)
(hash_delete_at): Return const void *.
Adjust casts to preserve the const.
Akim Demaille [Mon, 10 Dec 2001 08:45:22 +0000 (08:45 +0000)]
One structure for states is enough, even though theoretically
there are LR(0) states and LALR(1) states.
* src/lalr.h (state_t): Remove.
(state_table): Be state_t **, not state_t *.
* src/state.h (core, CORE_ALLOC): Rename as...
(state_t, STATE_ALLOC): this.
Add the LALR(1) members: shifts, reductions, errs.
* src/LR0.c (state_table): Rename as...
(state_hash): this, to avoid name clashes with the global
`state_table'.
* src/print_graph.c, src/LR0.c, src/LR0.h, src/conflicts.c
* src/lalr.c, src/lalr.h, src/output.c, src/print.c: Adjust.
Akim Demaille [Mon, 10 Dec 2001 08:44:49 +0000 (08:44 +0000)]
Bison dumps core on bash.y.
Reported by Pascal Bart.
* src/warshall.c (bitmatrix_print): New.
(TC): Use it.
When performing a transitive closure R(i, j) && R(j, k) => R(i, k),
j must be the outer loop.
* tests/regression.at (Broken Closure): New.
Akim Demaille [Wed, 5 Dec 2001 09:43:53 +0000 (09:43 +0000)]
* src/reduce.c (reduce_grammar_tables): No longer disable the
removal of useless rules via CPP but via `if (0)', so that the
compiler still check the code is valid.
For instance, it should have noticed `rline' no longer exists: use
the `line' member of rule_t.
* src/gram.c (dummy, rline): Remove, unused.
Akim Demaille [Wed, 5 Dec 2001 09:41:15 +0000 (09:41 +0000)]
New experimental feature: if --verbose --trace output all the
items of a state, not only its kernel.
* src/print.c (print_core): If `trace_flag', then invoke closure
before outputting the items of the state (print_core is no longer
a correct name them).
(print_results): Invoke new_closure/free_closure if needed.
Akim Demaille [Wed, 5 Dec 2001 09:41:01 +0000 (09:41 +0000)]
* src/LR0.c (new_itemsets): Use nshifts only, not shiftcount.
* src/closure.c, src/closure.h (itemsetsize): Rename as...
(nitemset): for consistency with the rest of the project.
Akim Demaille [Wed, 5 Dec 2001 09:34:55 +0000 (09:34 +0000)]
Pessimize the code to simplify it: from now on, all the states
have a valid SHIFTS, which NSHIFTS is possibly 0.
* src/LR0.c (shifts_new): Be global and move to..
* src/state.c, src/state.h: here.
* src/conflicts, src/lalr.c, src/output.c, src/print.c,
* src/print_graph: Adjust.
Akim Demaille [Wed, 5 Dec 2001 09:32:23 +0000 (09:32 +0000)]
* src/state.h (SHIFT_DISABLE, SHIFT_IS_DISABLED): New.
* src/conflicts.c: Use it.
Restore a few missing `if (!SHIFT_IS_DISABLED)' which were
incorrectly ``simplified''.
Akim Demaille [Wed, 5 Dec 2001 09:32:00 +0000 (09:32 +0000)]
* src/conflicts.c (flush_shift, resolve_sr_conflict): De-obfuscate
using the good o' techniques: arrays not pointers, variable
locality, BITISSET, RESETBIT etc.
Akim Demaille [Wed, 5 Dec 2001 09:31:23 +0000 (09:31 +0000)]
* src/conflicts.c (count_sr_conflicts, count_rr_conflicts)
(print_reductions): De-obfuscate using the good o' techniques:
arrays not pointers, variable locality, BITISSET.
Akim Demaille [Wed, 5 Dec 2001 09:28:27 +0000 (09:28 +0000)]
* src/lalr.c (transpose): Free the memory allocated to the
argument, as it is replaced by the results by the unique caller.
(build_relations): Merely invoke transpose: it handles the memory
deallocation.
Improve variable locality.
Avoid variables used as mere abbreviations.
(compute_lookaheads): Use arrays instead of pointers.
Akim Demaille [Wed, 5 Dec 2001 09:28:00 +0000 (09:28 +0000)]
* src/derives.c (print_derives): Display the ruleno.
* src/lalr.c (initialize_F, transpose): Better variable locality
to improve readability.
Avoid variables used as mere abbreviations.
Akim Demaille [Wed, 5 Dec 2001 09:27:23 +0000 (09:27 +0000)]
Because useless nonterminals are now kept alive (instead of being
`destroyed'), we now sometimes examine them, and store information
related to them. Hence we need to know their number, and adjust
memory allocations.
* src/reduce.c, src/reduce.h (nuseless_nonterminals): No longer
static.
* src/LR0.c (allocate_itemsets): The memory allocated to
`symbol_count' was used for two different purpose: once to count
the number of occurrences of each symbol, and later reassigned to
`shift_symbol', containing the symbol that can be shifted from a
given state.
Deobfuscate, i.e., allocate, use and free `symbol_count' here
only, and...
(new_itemsets): Allocate `shift_symbol' here.
(allocate_itemsets): symbol_count includes useless nonterminals.
Make room for them.
(free_storage): Use `free', not `XFREE', for pointers that cannot
be null.
Akim Demaille [Wed, 5 Dec 2001 09:26:05 +0000 (09:26 +0000)]
* src/gram.c, src/gram.h (ritem_print): New.
* src/gram.c (dummy): Remove, now there is actual code in gram.c.
(This useless function was defined only to work around VMS linkers
that can't handle compilation units with variables only).
* src/reduce.c (dump_grammar): Use it to trace the construction of
ritem.
Paul Eggert [Tue, 4 Dec 2001 14:10:51 +0000 (14:10 +0000)]
* src/bison.simple (union yyalloc): Change member names
to be the same as the stack names.
(yyparse): yyptr is now union yyalloc *, not char *.
(YYSTACK_RELOCATE): Likewise. This avoids a GCC warning,
and may generate better code on some machines.
Paul Eggert [Tue, 4 Dec 2001 14:10:07 +0000 (14:10 +0000)]
(union yyalloc): Change member names to be the same as the stack names.
(YYPOINTER): Remove.
(yyparse): yyptr is now union yyalloc *, not char *.
(YYSTACK_RELOCATE): Likewise. This avoids a GCC warning,
and may generate better code on some machines.
Paul Eggert [Tue, 4 Dec 2001 13:29:59 +0000 (13:29 +0000)]
* src/bison.simple (YYPOINTER): New macro.
(YYSTACK_RELOCATE): Use it to avoid a GCC warning.
(yystpcpy): Use prototype if __STDC__ is defined, not just
if __cplusplus is defined.
Paul Eggert [Tue, 4 Dec 2001 13:29:27 +0000 (13:29 +0000)]
(YYPOINTER): New macro.
(YYSTACK_RELOCATE): Use it to avoid a GCC warning.
(yystpcpy): Use prototype if __STDC__ is defined, not just
if __cplusplus is defined.
Akim Demaille [Fri, 30 Nov 2001 14:25:16 +0000 (14:25 +0000)]
* configure.in (WARNING_CFLAGS): Add -Werror when possible.
(CFLAGS): Do not include the WARNING_CFLAGS here, since GNU
Gettext doesn't compile cleanly, and dies with -Werror.
* src/Makefile.am, lib/Makefile.am, tests/atlocal.in (CFLAGS):
Include WARNING_CFLAGS here.
* lib/xstrdup.c: Include xalloc.h, so that xstrdup be declared
before being defined.
Akim Demaille [Fri, 30 Nov 2001 14:04:24 +0000 (14:04 +0000)]
* lib/quotearg.h (quotearg_n, quotearg_n_style):
First arg is int, not unsigned.
* lib/quotearg.c (quotearg_n, quotearg_n_style): Likewise.
(SIZE_MAX, UINT_MAX): New macros.
(quotearg_n_options): Abort if N is negative.
Avoid overflow check on hosts where size_t is 64 bits and int
is 32 bits, as overflow is impossible there.
Fix off-by-one typo that caused unnecessary reallocation.
Akim Demaille [Fri, 30 Nov 2001 14:00:14 +0000 (14:00 +0000)]
Name space cleanup in generated parser.
* doc/bison.texinfo (Bison Parser): Discuss system headers
and their effect on the user name space.
* src/bison.simple:
(YYSTACK_ALLOC, YYSTACK_FREE, union yyalloc, YYSTACK_GAP_MAX,
YYSTACK_BYTES, YYSTACK_RELOCATE): Do not define unless necessary,
i.e. unless ! defined (yyoverflow) || defined (YYERROR_VERBOSE).
(YYSIZE_T): New macro. Use it instead of size_t, to avoid infringing
on user names when possible.
(YYSTACK_USE_ALLOCA): Do not define; just use any existing defn.
Simplify test for whather <alloca.h> exists.
(<stdlib.h>): Include if we will use malloc, and if standard C or C++.
(<stdio.h>): Include if YYDEBUG.
(yymemcpy): Renamed from __yy_memcpy. Do not define unless
! defined (yyoverflow) && ! defined (yymemcpy).
(yymemcpy, yyparse): Rename local variables as needed so that
they all begin with 'yy'.
(yystrlen, yystpcpy): New functions.
(YY_DECL_NON_LSP_VARIABLES): Renamed from _YY_DECL_VARIABLES.
All uses changed.
(yyparse): size_t -> YYSIZE_T. Use yystrlen and yystpcpy
instead of relying on string.h functions. Use YYSTACK_ALLOC
and YYSTACK_FREE instead of malloc and free.
Akim Demaille [Fri, 30 Nov 2001 10:49:24 +0000 (10:49 +0000)]
Instead of mapping the LHS of unused rules to -1, keep the LHS
valid, but flag the rules as invalid.
* src/gram.h (rule_t): `useful' is a new member.
* src/print.c (print_grammar): Adjust.
* src/derives.c (set_derives): Likewise.
* src/reader.c (packgram, reduce_output): Likewise.
* src/reduce.c (reduce_grammar_tables): Likewise.
* tests/reduce.at (Underivable Rules, Useless Rules): New.
Akim Demaille [Fri, 30 Nov 2001 10:48:14 +0000 (10:48 +0000)]
* src/reduce.c (nonterminals_reduce): Instead of throwing away
useless nonterminals, move them at the end of the symbol arrays.
(reduce_output): Adjust.
* tests/reduce.at (Useless Nonterminals): Adjust.
Paul Eggert [Fri, 30 Nov 2001 02:56:45 +0000 (02:56 +0000)]
* src/bison.simple (YYSTACK_REALLOC): Remove.
(YYSTACK_ALLOC): Resurrect this macro, with its old meaning.
(YYSTACK_FREE, YYSTACK_GAP_MAX, YYSTACK_BYTES, YYSTACK_RELOCATE):
New macros.
(union yyalloc): New type.
(__yy_memcpy): Last arg is size_t, not unsigned int, to remove
an arbitrary restriction on hosts where size_t is wider than int.
(yyparse): Don't dump core if alloca or malloc fails; instead, report
a parser stack overflow. Allocate just one block of memory for all
three stacks, instead of allocating three blocks; this typically is
faster and reduces fragmentation.
Do not limit the number of items in the stack to a value that fits
in 'int', as this is an arbitrary limit on hosts with 64-bit
size_t and 32-bit int.
Paul Eggert [Fri, 30 Nov 2001 02:54:54 +0000 (02:54 +0000)]
(YYSTACK_REALLOC): Remove.
(YYSTACK_ALLOC): Resurrect this macro, with its old meaning.
(YYSTACK_FREE, YYSTACK_GAP_MAX, YYSTACK_BYTES, YYSTACK_RELOCATE):
New macros.
(union yyalloc): New type.
(__yy_memcpy): Last arg is size_t, not unsigned int, to remove
an arbitrary restriction on hosts where size_t is wider than int.
(yyparse): Don't dump core if alloca or malloc fails; instead, report
a parser stack overflow. Allocate just one block of memory for all
three stacks, instead of allocating three blocks; this typically is
faster and reduces fragmentation.
Do not limit the number of items in the stack to a value that fits
in 'int', as this is an arbitrary limit on hosts with 64-bit
size_t and 32-bit int.
Marc Autret [Wed, 28 Nov 2001 21:31:13 +0000 (21:31 +0000)]
* src/output.h: And put its extern declaration here.
* src/output.c (error_verbose): Define here.
(prepare): Echo name modification.
* src/getargs.h: Clean its extern declaration.
* src/getargs.c (error_verbose_flag): Remove.
(getargs): Remove case 'e'.
* src/options.c (option_table): 'error-verbose' is now seen as simple
percent option.
Include output.h.
* src/reader.c (read_declarations): Remove case tok_include.
(parse_include_decl): Remove.
* src/lex.h (token_t): Remove tok_include.
* src/options.c (option_table): 'include' is now a simple command line
option.
Marc Autret [Wed, 28 Nov 2001 20:32:53 +0000 (20:32 +0000)]
* src/bison.simple: Adjust muscle names.
* src/muscle_tab.c (muscle_init): Also rename the muscles.
* src/output.c (prepare): s/_/-/ for the muscles names.
(output_parser): When scanning for a muscle, allow '-' instead of '_'.