* src/output.c (froms, tos): Are state_number_t.
(save_column): sp, sp1, and sp2 are state_number_t.
(prepare): Rename `final' as `final_state_number', `nnts' as
`nterms_number', `nrules' as `rules_number', `nstates' as
`states_number', and `ntokens' as `tokens_number'. Remove `nsym',
unused.
* data/yacc.c, data/glr.c, data/lalr1.cc: Adjust.
* data/lalr1.cc (nsym_): Remove, unused.
Fix some memory leaks, and fix a bug: state 0 was examined twice.
* src/LR0.c (new_state): Merge into...
(state_list_append): this.
(new_states): Merge into...
(generate_states): here.
(set_states): Don't ensure a proper `errs' state member here, do it...
* src/conflicts.c (conflicts_solve): here.
* src/state.h, src/state.c: Comment changes.
(state_t): Rename member `shifts' as `transitions'.
Adjust all dependencies.
(errs_new): For consistency, also take the values as argument.
(errs_dup): Remove.
(state_errs_set): New.
(state_reductions_set, state_transitions_set): Assert that no
previous value was assigned.
(state_free): New.
(states_free): Use it.
* src/conflicts.c (resolve_sr_conflict): Don't use an `errs_t' as
temporary storage: use `errs' and `nerrs' as elsewhere.
(set_conflicts): Allocate and free this `errs'.
Akim Demaille [Sun, 30 Jun 2002 17:35:06 +0000 (17:35 +0000)]
Have the GLR tests be `warning' checked, and fix the warnings.
* data/glr.c (YYFPRINTF): Always define it, not only when YYDEBUG
(yyuserAction, yyreportAmbiguity): `Use' all the arguments.
(yyremoveDeletes): `yyi' and `yyj' are size_t.
Use YYFPRINTF when under if (YYDEBUG) to avoid empty `if' bodies.
(yyaddDeferredAction): static.
(yyglrReduce): yyi, yyk, amd yyposn are size_t.
(yyreportParseError): yyprefix is const.
yytokenp is used only when verbose.
(yy__GNUC__): Replace with __GNUC__.
(yypdumpstack): yyi is size_t.
(yypreference): Un-yy local variables and arguments, to avoid
clashes with `yyr1'. Anyway, we are not in the user name space.
(yytname_size): be an int, as is compared with ints.
* tests/testsuite.at (AT_COMPILE, AT_PARSER_CHECK): New.
Use them.
* tests/cxx-gram.at: Use quotation to protect $1.
Use AT_COMPILE to enable warnings hunts.
Prototype yylex and yyerror.
`Use' argc.
Include `string.h', not `strings.h'.
Produce and prototype stmtMerge only when used.
yylex takes a location.
Akim Demaille [Sun, 30 Jun 2002 17:34:52 +0000 (17:34 +0000)]
We spend a lot of time in quotearg, in particular when --verbose.
* src/symtab.c (symbol_get): Store a quoted version of the key.
(symbol_tag_get, symbol_tag_get_n, symbol_tag_print): Remove.
Adjust all callers.
Akim Demaille [Sun, 30 Jun 2002 17:34:31 +0000 (17:34 +0000)]
* src/state.h (reductions_t): Rename member `nreds' as num.
(errs_t): Rename members `nerrs' and `errs' as `num' and `symbols'.
* src/state.c (ERRS_ALLOC, REDUCTIONS_ALLOC): Use the correct types.
Akim Demaille [Sun, 30 Jun 2002 17:33:08 +0000 (17:33 +0000)]
Display items as we display rules.
* src/gram.h, src/gram.c (rule_lhs_print): New.
* src/gram.c (grammar_rules_partial_print): Use it.
* src/print.c (print_core): Likewise.
* tests/conflicts.at (Defaulted Conflicted Reduction),
(Unresolved SR Conflicts): Adjust.
(Unresolved SR Conflicts): Adjust and rename as...
(Resolved SR Conflicts): this, as was meant.
* tests/regression.at (Web2c Report): Adjust.
Akim Demaille [Sun, 30 Jun 2002 17:29:36 +0000 (17:29 +0000)]
Use hash.h for the state hash table.
* src/LR0.c (STATE_HASH_SIZE, state_hash): Remove.
(allocate_storage): Use state_hash_new.
(free_storage): Use state_hash_free.
(new_state, get_state): Adjust.
* src/lalr.h, src/lalr.c (states): Move to...
* src/states.h (state_t): Remove the `link' member, no longer
used.
* src/states.h, src/states.c: here.
(state_hash_new, state_hash_free, state_hash_lookup)
(state_hash_insert, states_free): New.
* src/states.c (state_table, state_compare, state_hash): New.
* src/output.c (output_actions): Do not free states now, since we
still need to know the final_state number in `prepare', called
afterwards. Do it...
* src/main.c (main): here: call states_free after `output'.
Akim Demaille [Sun, 30 Jun 2002 17:27:14 +0000 (17:27 +0000)]
Make the test suite pass with warnings checked.
* tests/actions.at (Printers and Destructors): Improve.
Avoid unsigned vs. signed issues.
* tests/calc.at: Don't exercise the scanner here, do it...
* tests/input.at (Torturing the Scanner): here.
Akim Demaille [Fri, 28 Jun 2002 08:41:45 +0000 (08:41 +0000)]
* src/reader.h: s/grammer_current_rule_merge_set/grammar_.../.
* src/conflicts.c (conflicts_total_count): `i' is unsigned, to
pacify GCC.
* src/output.c (save_row): Initialize all the variables to pacify GCC.
(merger_output): static.
Akim Demaille [Thu, 20 Jun 2002 11:46:59 +0000 (11:46 +0000)]
* data/bison.simple (b4_symbol_actions): New, replaces...
(b4_symbol_destructor, b4_symbol_printer): these.
(yysymprint): Be sure to call YYPRINT only for tokens, and using
user token numbers.
Akim Demaille [Thu, 20 Jun 2002 09:47:44 +0000 (09:47 +0000)]
* data/bison.simple (yysymprint): Don't print the token number,
just its name.
* tests/actions.at (Destructors): Rename as...
(Printers and Destructors): this.
Also exercise %printer.
Akim Demaille [Thu, 20 Jun 2002 09:08:37 +0000 (09:08 +0000)]
* src/symtab.h, src/symtab.c (symbol_t): printer and
printer_location are new members.
(symbol_printer_set): New.
* src/parse-gram.y (PERCENT_PRINTER): New token.
Handle its associated rule.
* src/scan-gram.l: Adjust.
(handle_destructor_at, handle_destructor_dollar): Rename as...
(handle_symbol_code_at, handle_symbol_code_dollar): these.
* src/output.c (symbol_printers_output): New.
(output_skeleton): Call it.
* data/bison.simple (yysymprint): New. Cannot be named yyprint
since there are already many grammar files with a user `yyprint'.
Replace the calls to YYPRINT to calls to yysymprint.
* tests/calc.at: Adjust.
* tests/torture.at (AT_DATA_STACK_TORTURE): Remove YYPRINT: it was
taking advantage of parser very internal details (stack size!).
Akim Demaille [Wed, 19 Jun 2002 12:03:22 +0000 (12:03 +0000)]
* tests/actions.at (Destructors): Augment to test locations.
* data/bison.simple (yydestructor): Pass it the current location
if locations are enabled.
Prototype only when __STDC__ or C++.
Change the argument names to move into the yy name space: there is
user code here.
Akim Demaille [Wed, 19 Jun 2002 08:22:49 +0000 (08:22 +0000)]
Prepare @$ in %destructor, but currently don't bind it in the
skeleton, as %location use is not cleaned up yet.
* src/scan-gram.l (handle_dollar, handle_destructor_at)
(handle_action_at): New.
(handle_at, handle_action_dollar, handle_destructor_dollar): Take
a braced_code_t and a location as additional arguments.
(handle_destructor_dollar): Instead of requiring `b4_eval', just
unquote one when outputting `b4_dollar_dollar'.
Adjust callers.
* data/bison.simple (b4_eval): Remove.
(b4_symbol_destructor): Adjust.
* tests/input.at (Invalid @n): Adjust.
Akim Demaille [Tue, 18 Jun 2002 10:00:36 +0000 (10:00 +0000)]
* data/bison.simple (yyoverflowlab): #ifndef yyoverflow, so that
there are no `label `yyoverflowlab' defined but not used' warnings
when yyoverflow is defined.
Akim Demaille [Tue, 18 Jun 2002 09:55:35 +0000 (09:55 +0000)]
* src/symtab.h, src/symtab.c (symbol_t): destructor_location is a
new member.
(symbol_destructor_set): Adjust.
* src/output.c (symbol_destructors_output): Output the destructor
locations.
Output the symbol name.
* data/bison.simple (b4_symbol_destructor): Adjust.
Akim Demaille [Tue, 18 Jun 2002 09:12:58 +0000 (09:12 +0000)]
and Akim Demaille <akim@epita.fr>
* data/bison.simple.new (yyerrlab1): Be sure to pop and destroy
what's left on the stack when the error recovery hits EOF.
* tests/actions.at (Destructors): Complete to exercise this case.
Akim Demaille [Mon, 17 Jun 2002 08:43:12 +0000 (08:43 +0000)]
* data/m4sugar/m4sugar.m4 (m4_map): Recognize when the list of
arguments is really empty, not only equal to `[]'.
* src/symtab.h, src/symtab.c (symbol_t): `destructor' is a new
member.
(symbol_destructor_set): New.
* src/output.c (symbol_destructors_output): New.
* src/reader.h (brace_code_t, current_braced_code): New.
* src/scan-gram.l (BRACED_CODE): Use it to branch on...
(handle_dollar): Rename as...
(handle_action_dollar): this.
(handle_destructor_dollar): New.
* src/parse-gram.y (PERCENT_DESTRUCTOR): New.
(grammar_declaration): Use it.
* data/bison.simple (yystos): Is always defined.
(yydestructor): New.
* tests/actions.at (Destructors): New.
* tests/calc.at (_AT_CHECK_CALC_ERROR): Don't rely on egrep.
Akim Demaille [Mon, 17 Jun 2002 07:05:12 +0000 (07:05 +0000)]
* src/symlist.h, src/symlist.c (symbol_list_length): New.
* src/scan-gram.l (handle_dollar, handle_at): Compute the
rule_length only when needed.
* src/output.c (actions_output, token_definitions_output): Output
the full M4 block.
* src/symtab.c: Don't access directly to the symbol tag, use
symbol_tag_get.
* src/parse-gram.y: Use symbol_list_free.
Akim Demaille [Mon, 17 Jun 2002 07:04:24 +0000 (07:04 +0000)]
* src/reader.h, src/reader.c (symbol_list_new): Export it.
(symbol_list_prepend): New.
* src/parse-gram.y (%union): `list' is a new member.
(symbols.1): New, replaces...
(terms_to_prec.1, nterms_to_type.1): these.
* src/symtab.h, src/symtab.c (symbol_type_set, symbol_precedence_set)
Take a location as additional argument.
Adjust all callers.
Akim Demaille [Sat, 15 Jun 2002 18:24:08 +0000 (18:24 +0000)]
* src/conflicts.c (log_resolution): Accept the rule involved in
the sr conflicts instead of the lookahead number that points to
that rule.
(flush_reduce): Accept the current lookahead vector as argument,
instead of the index in LA.
(resolve_sr_conflict): Accept the current number of lookahead
bitset to consider for the STATE, instead of the index in LA.
(set_conflicts): Adjust.
* src/lalr.c, src/lalr.h, src/state.h: Comment changes.
Akim Demaille [Sat, 15 Jun 2002 18:23:12 +0000 (18:23 +0000)]
Copy BYacc's nice way to report the grammar.
* src/gram.h, src/gram.c (grammar_rhs_print, grammar_rules_print):
New.
Don't print the rules' location, it is confusing and useless.
(rule_print): Use grammar_rhs_print.
* src/print.c (print_grammar): Use grammar_rules_print.
Akim Demaille [Sat, 15 Jun 2002 18:21:46 +0000 (18:21 +0000)]
Let symbols have a location.
* src/symtab.h, src/symtab.c (symbol_t): Location is a new member.
(getsym): Adjust.
Adjust all callers.
* src/complain.h, src/complain.c (complain_at, fatal_at, warn_at):
Use location_t, not int.
* src/symtab.c (symbol_check_defined): Take advantage of the
location.
* tests/regression.at (Invalid inputs): Adjust.
Akim Demaille [Sat, 15 Jun 2002 18:21:11 +0000 (18:21 +0000)]
* src/parse-gram.y (YYLLOC_DEFAULT, current_lhs_location): New.
(input): Don't try to initialize yylloc here, do it in the
scanner.
* src/scan-gram.l (YY_USER_INIT): Initialize yylloc.
* src/gram.h (rule_t): Change line and action_line into location
and action_location, of location_t type.
Adjust all dependencies.
* src/location.h, src/location.c (empty_location): New.
* src/reader.h, src/reader.c (grammar_start_symbol_set)
(grammar_symbol_append, grammar_rule_begin, grammar_rule_end)
(grammar_current_rule_symbol_append)
(grammar_current_rule_action_append): Expect a location as argument.
* src/reader.c (grammar_midrule_action): Adjust to attach an
action's location as dummy symbol location.
* src/symtab.h, src/symtab.c (startsymbol_location): New.
* tests/regression.at (Web2c Report, Rule Line Numbers): Adjust
the line numbers.
Akim Demaille [Fri, 14 Jun 2002 17:38:14 +0000 (17:38 +0000)]
Grammar declarations may be found in the grammar section.
* src/parse-gram.y (rules_or_grammar_declaration): New.
(declarations): Each declaration may end with a semicolon, not
just...
(grammar_declaration): `"%union"'.
(grammar): Branch to rules_or_grammar_declaration.
Akim Demaille [Fri, 14 Jun 2002 17:36:24 +0000 (17:36 +0000)]
* src/files.c (action_obstack): Remove, unused.
(output_obstack): Remove it, and all its dependencies, as it is no
longer needed.
* src/reader.c (epilogue_set): Build the epilogue in the
muscle_obstack.
* src/output.h, src/output.c (muscle_obstack): Move to...
* src/muscle_tab.h, src/muscle_tab.h: here.
(muscle_init): Initialize muscle_obstack.
(muscle_free): New.
* src/main.c (main): Call it.
Akim Demaille [Fri, 14 Jun 2002 17:29:17 +0000 (17:29 +0000)]
* data/bison.simple, data/bison.c++: Be sure to restore the
current #line when returning to the skeleton contents after having
exposed the input file's #line.