Use $accept and $end, as BYacc and BTYacc do, instead of $axiom and $.
* src/symtab.h, src/symtab.c (eoftoken, axiom): Rename as...
(endtoken, accept): these.
* src/reader.c (reader): Set endtoken's default tag to "$end".
Set undeftoken's tag to "$undefined" instead of "$undefined.".
* doc/bison.texinfo (Table of Symbols): Mention $accept and $end.
Adjust.
* src/reduce.c (reduce_grammar): When the language is empty,
complain about the start symbol, not the axiom.
Use its location.
* tests/reduce.at (Empty Language): New.
* src/reader.h, src/reader.c (gram_error): ... can't get
yycontrol without making too strong assumptions on the parser
itself.
* src/output.c (prepare_tokens): Use the real 0th value of
token_translations instead of `0'.
* src/parse-gram.y (yyerror): Don't rely on yycontrol being
visible here.
* data/yacc.c (yyreport_parse_error): Rename yylocation as yylloc
for the time being: %locations ought to provide it to yyerror.
Stop storing rules from 1 to nrules + 1.
* src/LR0.c, src/closure.c, src/derives.c, src/gram.c, src/lalr.c
* src/nullable.c, src/output.c, src/print.c, src/reader.c
* src/reduce.c: Allocate and free from &rules[0], not &rules[1].
Iterate from 0 to nrules.
Use rule_number_as_item_number and item_number_as_rule_number.
Adjust to `derive' now containing possibly 0.
* src/gram.h (rule_number_as_item_number, item_number_as_rule_number):
Handle the `- 1' part in rule numbers from/to item numbers.
* src/conflicts.c (log_resolution): Fix the message which reversed
shift and reduce.
* src/output.c (action_row): Initialize default_rule to -1.
(token_actions): Adjust.
* tests/sets.at (Nullable, Firsts): Fix the previously bogus
expected output.
* tests/conflicts.at (Resolved SR Conflicts): Likewise.
* data/c.m4 (b4_c_function, b4_c_ansi_args, b4_c_ansi_arg)
(b4_c_knr_arg_names, b4_c_knr_arg_name, b4_c_knr_arg_decls)
(b4_c_knr_arg_decl): New.
* data/yacc.c: Use it to define yysymprint, yydestruct, and
yyreport_parse_error.
* src/parse-gram.y (rules_or_grammar_declaration): Add an error
recovery rule, and forbid extensions when --yacc.
(gram_error): Use complain_at.
* src/reader.c (reader): Exit if there were parse errors.
* 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.