Commit Graph

1657 Commits

Author SHA1 Message Date
Akim Demaille
38a169bec1 html: capitalize titles
* data/xslt/xml2xhtml.xsl: Use "State 0", not "state 0".
As we do in text reports.
2020-07-11 12:58:45 +02:00
Akim Demaille
dc77d6500f html: don't define several times the same anchors
Currently when we output useless rules, they appear before the
grammar, but using the same invocation.  As a result, the anchor is
defined twice, and the wrong one, being first, is honored.

* data/xslt/xml2xhtml.xsl (rule): Take a new 'anchor' parameter to
decide whether being an anchor, or a target.
Let it be true when output the grammar.
* tests/report.at: Adjust.
2020-07-11 12:58:44 +02:00
Akim Demaille
8262c7dc22 html: simplify
* data/xslt/xml2xhtml.xsl: Merge two identical when-clauses.
2020-07-11 12:58:44 +02:00
Akim Demaille
44f28d10ee reports: let html reports catch up with --report and --graph
* data/xslt/xml2xhtml.xsl: Show the symbol types.
* tests/report.at: Adjust.
2020-07-11 12:58:44 +02:00
Akim Demaille
44ad466a32 reports: let xml reports catch up with --report and --graph
The text and Dot reports are expected to be identical when generated
directly (--report, --graph) or indirectly (via XML).  The xml
testsuite had not be run for ages, let it catch up a bit.

* src/print-xml.c: Pass the type of the symbols.
* data/xslt/xml2text.xsl
Catch up with the new layout.
Display the symbol types.
Use '•', not '.'
* tests/local.at: Smash '•' to '.' when matching against the direct
text report.
* tests/report.at: Adjust XML expectations.
2020-07-11 12:58:44 +02:00
Akim Demaille
a839f4c461 reports: update html ouput
* data/xslt/xml2xhtml.xsl: Improve indentation.
Use ul/li rather that pre.
2020-07-11 12:58:44 +02:00
Akim Demaille
0820f16ca8 style: update comments
* src/reader.c: action_obstack was removed in 2002...
* src/parse-gram.y: Better names.
* src/scan-code.h: More comments.
2020-07-05 09:59:45 +02:00
Akim Demaille
49f1e5f428 style: update comments in the skeletons
* data/skeletons/c++.m4, data/skeletons/glr.c, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c:
Be more accurate about yychar and yytoken.
Don't name local variables as if they were members.
2020-07-05 09:59:25 +02:00
Akim Demaille
238692ad77 doc: more details about symbols in m4
* data/README.md: here.
* README-hacking.md (Vocabulary): More.
2020-07-05 09:18:27 +02:00
Akim Demaille
156e548341 cex: give more details about -Wcex and -rcex
* data/bison-default.css: Cobalt does not seem to be supported.
* doc/bison.texi (Counterexamples): A new section.
(Understanding): Show the counterexamples as it shows in the report:
with its items.
(Bison Options): Document -Wcex and -rcex.
2020-07-04 11:43:35 +02:00
Akim Demaille
330552ea49 yacc.c: push: don't clear the parser state when accepting/rejecting
Currently when a push parser finishes its parsing (i.e., it did not
return YYPUSH_MORE), it also clears its state.  It is therefore
impossible to see if it had parse errors.

In the context of autocompletion, because error recovery might have
fired, the parser is actually already in a different state.  For
instance on `(1 + + <TAB>` in the bistromathic, because there's a
`exp: "(" error ")"` recovery rule, `1 + +` tokens have already been
popped, replaced by `error`, and autocompletions think we are ready
for the closing ")".  So here, we would like to see if there was a
syntax error, yet `yynerrs` was cleared.

In the case of a successful parse, we still have a problem: if error
recovery succeeded, we won't know it, since, again, `yynerrs` is
clearer.

It seems much more natural to leave the parser state available for
analysis when there is a failure.

To reuse the parser, we should either:

1. provide an explicit means to reinitialize a parser state for future
   parses.

2. automatically reset the parser state when it is used in a new
   parse.

Option 2 requires to check whether we need to reinitialize the parser
each time we call `yypush_parse`, i.e., each time we give a new token.
This seems expensive compared to Option 1, but benchmarks revealed no
difference.  Option 1 is incompatible with the documentation
("After `yypush_parse` returns a status other than `YYPUSH_MORE`, the
parser instance `yyps` may be reused for a new parse.").

So Option 2 wins, reusing the private `yynew` member to record that a
parse was finished, and therefore that the state must reset in the
next call to `yypull_parse`.

While at it, this implementation now reuses the previously enlarged
stacks from one parse to another.

* data/skeletons/yacc.c (yypstate_new): Set up the stacks in their
initial configurations (setting their bottom to the stack array), and
use yypstate_clear to reset them (moving their top to their bottom).
(yypstate_delete): Adjust.
(yypush_parse): At the beginning, clear yypstate if needed, and at the
end, record when yypstate needs to be clearer.

* examples/c/bistromathic/parse.y (expected_tokens): Do not propose
autocompletion when there are parse errors.
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-06-29 19:36:41 +02:00
Akim Demaille
ed10c308fa yacc.c: simplify initialization of push parsers
The previous commit ("yacc.c: declare and initialize and the same
time") made b4_initialize_parser_state_variables useless.

* data/skeletons/yacc.c (b4_initialize_parser_state_variables): Inline
into...
(yypstate_clear): here.
2020-06-29 19:10:05 +02:00
Akim Demaille
29520abb3b yacc.c: declare and initialize and the same time
In order to factor the code of push and pull parsers, the declaration
of the parser's state variable was common (being local variable in
pull parsers, and struct members in push parsers).  This result in
rather poor style in pull parser, with first variable declarations,
and then their initializations.

The initialization is about to differ between push and pull parsers,
so it is no longer worth keeping both cases together.

* data/skeletons/yacc.c (b4_declare_parser_state_variables): Accept an
argument, and when it is set, initialize the variables.
Adjust dependencies.
2020-06-29 19:10:05 +02:00
Akim Demaille
2491de1eef yacc.c: style changes in push mode
* data/skeletons/yacc.c: here.
2020-06-29 19:10:05 +02:00
Akim Demaille
ec207d1bb2 yacc.c: simplify yypull_parse
Currently yypull_parse takes a yypstate* as argument, and accepts it
to be NULL.  This does not seem to make a lot of sense: rather it is
its callers that should do that.

I believe this is historical: yypull_parse was introduced
first (c3d503425f), with yyparse being a
macro.  So yyparse could hardly deal with memory allocation properly.
In 7172e23e8f that yyparse was turned
into a genuine function.  At that point, it should have allocated its
own yypstate*, which would have left yypull_parse deal with only one
single non-null ypstate* argument.

Fortunately, it is nowhere documented that it is valid to pass NULL to
yypull_parse.  It is now forbidden.

* data/skeletons/yacc.c (yypull_parse): Don't allocate a yypstate.
Needs a location to issue the error message.
(yyparse): Allocate the yypstate.
2020-06-29 19:10:05 +02:00
Akim Demaille
160df55c56 doc: overhaul of the readmes
* README-hacking.md (Working from the Repository): Make it first to
make it easier to find the instructions to build from the repo.
(Implementation Notes): New.
* README: Provide more links.
2020-06-28 14:57:41 +02:00
Akim Demaille
e0b0a67b86 java: rename package as api.package
* data/skeletons/lalr1.java: here.
* doc/bison.texi: Update.
* src/muscle-tab.c: Ensure backward compat.
* tests/java.at: Check it.
2020-06-28 09:49:00 +02:00
Akim Demaille
eeafc706e8 c++: by default, use const std::string for file names
Reported by Martin Blais and Yuriy Solodkyy.
https://lists.gnu.org/r/help-bison/2020-05/msg00011.html
https://lists.gnu.org/r/bug-bison/2020-06/msg00038.html

While at it, modernize filename_type as api.filename.type and document
it properly.

* data/skeletons/c++.m4 (filename_type): Rename as...
(api.filename.type): this.
Default to const std::string.
* data/skeletons/location.cc (position, location): Expose the
filename_type type.
Use api.filename.type.
* doc/bison.texi (%define Summary): Document api.filename.type.
(C++ Location Values): Document position::filename_type.
* src/muscle-tab.c (muscle_percent_variable_update): Ensure backward
compatibility.
* tests/c++.at: Check that using const file names is ok.
tests/input.at: Check backward compat.
2020-06-27 10:06:00 +02:00
Akim Demaille
c4b1a2b68f doc: use dot/'•' rather than point/'.'
AFAICT, "dotted rule" is a more frequent synonym of "item" than
"pointed rule".  So let's migrate to using "dot" only.

* doc/bison.texi: Use dot/'•' rather than point/'.'.

* src/print-xml.c (print_core): Use dot rather than point.  This is
not backward compatible, but AFAICT, we don't have actual user of the
XML output (but ourselves).  So...
* data/xslt/xml2dot.xsl, data/xslt/xml2text.xsl,
* data/xslt/xml2xhtml.xsl, tests/report.at: ... adjust.
2020-06-23 07:37:29 +02:00
Akim Demaille
3dd8f2305a cex: use the bullet in HTML
* data/xslt/xml2xhtml.xsl: here.
2020-06-22 07:02:29 +02:00
Akim Demaille
efb65daa36 c++: get rid of global_tokens_and_yystype
This was a hack to make it easier for people to migrate from yacc.c to
lalr1.cc and from glr.c to glr.cc: when set, YYSTYPE and YYLTYPE were
`#defined`.  It was never documented (just mentioned in NEWS for Bison
2.2, 2006-05-19), but was used to simplify the test suite.  Stop that:
adjust the test suite to the skeletons, not the converse.

In C++ use yy::parser::semantic_type, yy::parser::location_type, and
yy::parser::token::MY_TOKEN, instead of YYSTYPE, YYLTYPE and MY_TOKEN.

* data/skeletons/glr.cc, data/skeletons/lalr1.cc: Remove its support.
* tests/actions.at, tests/c++.at, tests/calc.at: Adjust.
2020-06-16 08:14:42 +02:00
Akim Demaille
c662b23735 Merge 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.6.4
  glr.cc: don't leak glr.c/glr.cc scaffolding to the user

Some fixes were needed to adjust to recent changes in glr.cc and
glr.c.

* data/skeletons/glr.cc: Stop messing with the user's epilogue to
insert glr.cc code.  We need that code to be inserted _before_ the
user's epilogue, not after.  So define b4_glr_cc_pre_epilogue.
* data/skeletons/glr.c: Use it.
2020-06-16 07:16:00 +02:00
Akim Demaille
3f4ffea6f2 glr.cc: don't leak glr.c/glr.cc scaffolding to the user
Until we have a decent reimplementation of glr.cc, we have to use
tricks to shoehorn C++ symbols to the C engine of glr.c.  Some of them
are done via #define.  Unfortunately in Bison 3.6 some of these we
done in the header file, which broke valid user code.

Reported by Egor Pugin.
https://lists.gnu.org/r/bug-bison/2020-06/msg00003.html

* data/skeletons/glr.cc: Stop playing tricks with b4_pre_epilogue.
(b4_glr_cc_setup, b4_glr_cc_cleanup): New.
Much cleaner way to instal glr.cc's scaffolding around glr.c.
* data/skeletons/glr.c: Adjust to use them.
2020-06-15 20:18:47 +02:00
Akim Demaille
a53c6026cd api.header.include: document it, and fix its default value
While defining api.header.include worked as expected, its default
value was incorrectly defined.  As a result, by default, the generated
parsers still duplicated the content of the generated header instead
of including it.

* data/skeletons/yacc.c (api.header.include): Fix its default value.
* tests/output.at: Check it.
* doc/bison.texi (%define Summary): Document api.header.include.
While at it, move the definition of api.namespace at the proper
place.
2020-06-09 08:09:26 +02:00
Akim Demaille
ae5edcc23b cex: color the counterexamples
Use colors to show the counterexamples and the derivations in color,
to highlight their structure.  Align the outputs, and add i18n
support. Reduce width by using a one-space separator instead of
two-space.

From

    Example  A  •  B  C
    First  derivation  s ::=[ a ::=[ A  • ]  x ::=[ B  C ] ]
    Second derivation  s ::=[ y ::=[ A  •  B ]  c ::=[ C ] ]

to

    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

with colors.

* data/bison-default.css (cex-dot, cex-0, cex-1, cex-2, cex-3, cex-4)
(cex-5, cex-6, cex-7, cex-step, cex-leaf): New.
* src/derivation.c (derivation_print_styled_impl): New.
(derivation_print, derivation_print_leaves): Use it.
* src/counterexample.c: Reformat the output.
* tests/counterexample.at: Adjust.
2020-06-07 09:18:58 +02:00
Akim Demaille
39be113b1f all: show the rules in comments before the user actions
For instance, in the case of Bison's own parser:

    -  case 40:
    +  case 40:  /* grammar_declaration: "%code" "identifier" "{...}"  */
         {
           muscle_percent_code_grow ((yyvsp[-1].ID), (yylsp[-1]),
                                     translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])),
                                     (yylsp[0]));
           code_scanner_last_string_free ();
         }
         break;

* data/skeletons/c.m4: Modified.
* data/skeletons/d.m4: Modified.
* data/skeletons/java.m4: Modified.
* src/output.c (output_escaped): New.
(quoted_output): Use it, and rename as...
(output_quoted): this.
Adjust dependencies.
(rule_output): New.
(user_actions_output): Use it.
* data/skeletons/c.m4, data/skeletons/d.m4, data/skeletons/java.m4
(b4_case): Add support for $3, an optional comment.
2020-06-07 06:50:58 +02:00
Akim Demaille
7e16bd2cae Merge maint into HEAD
* upstream/maint:
  maint: post-release administrivia
  version 3.6.3
  build: check -Wmissing-prototypes
  tests: show logs
  c++: fix printing of state number on streams
2020-06-03 08:12:10 +02:00
Akim Demaille
52ce2a008b build: check -Wmissing-prototypes
pstate_clear is lacking a prototype.
Reported by Ryan
https://lists.gnu.org/r/bug-bison/2020-05/msg00101.html

Besides, none of the C examples were compiled with the warning flags.

* configure.ac (warn_c): Add -Wmissing-prototypes.
* data/skeletons/yacc.c (pstate_clear): Make it static.
* examples/local.mk (TEST_CFLAGS): New.
* examples/c/bistromathic/local.mk, examples/c/calc/local.mk,
* examples/c/lexcalc/local.mk, examples/c/mfcalc/local.mk,
* examples/c/pushcalc/local.mk, examples/c/reccalc/local.mk,
* examples/c/rpcalc/local.mk:
Use it.

GCC's warn_unused_result is not silenced by a cast to void, so we have
to "use" scanf's result.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

Flex generated code produces too many warnings, including things such
as, with ICC:

    examples/c/lexcalc/scan.c(1088): error #1682: implicit conversion
              of a 64-bit integral type to a smaller integral type (potential portability problem)
    2259                YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
    2260                ^
    2261
    2262

I am tired of trying to fix Flex's output.  The project does not seem
maintained.  We ought to avoid it.  So, for the time being, don't try
to enable warnings with Flex.

* examples/c/bistromathic/parse.y, examples/c/reccalc/scan.l: Fix
warnings.
* doc/bison.texi: Discard scanf's return value to defeat
-Werror=unused-result.
2020-06-01 08:29:53 +02:00
Joshua Watt
dd878d1851 bison: add command line option to map file prefixes
Teaches bison about a new command line option, --file-prefix-map OLD=NEW
(based on the -ffile-prefix-map option from GCC) which causes it to
replace and file path of OLD in the text of the output file with NEW,
mainly for header guards and comments. The primary use of this is to
make builds reproducible with different input paths, and in particular
the debugging information produced when the source code is compiled. For
example, a distro may know that the bison source code will be located at
"/usr/src/bison" and thus can generate bison files that are reproducible
with the following command:

    bison --output=/build/bison/parse.c -d --file-prefix-map=/build/bison/=/usr/src/bison/ parse.y

Importantly, this will change the header guards and #line directives
from:

    #ifndef YY_BUILD_BISON_PARSE_H
    #line 100 "/build/bison/parse.h"

to

    #ifndef YY_USR_SRC_BISON_PARSE_H
    #line 100 "/usr/src/bison/parse.h"

which is reproducible.

See https://lists.gnu.org/r/bison-patches/2020-05/msg00016.html
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>

* src/files.h, src/files.c (spec_mapped_header_file)
(mapped_dir_prefix, map_file_name, add_prefix_map): New.
* src/getargs.c (-M, --file-prefix-map): New option.
* src/output.c (prepare): Define b4_mapped_dir_prefix and
b4_spec_header_file.
* src/scan-skel.l (@ofile@): Output the mapped file name.
* data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, data/skeletons/location.cc,
* data/skeletons/yacc.c:
Adjust.
* doc/bison.texi: Document.
* tests/input.at, tests/output.at: Check.
2020-05-24 15:17:15 +02:00
Akim Demaille
8ece778cb8 c++: fix printing of state number on streams
Avoid this kind of display:

    LAC: checking lookahead identifier: R4 R3 G^B S5

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 18:02:24 +02:00
Akim Demaille
f32ba07f94 c++: fix printing of state number on streams
Avoid this kind of display:

    LAC: checking lookahead identifier: R4 R3 G^B S5

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 17:45:03 +02:00
Akim Demaille
79bae4d6bb kinds: use the symbol kinds where applicable
Instead of generating switch statements with numbers, let's use the
symbol kinds.  Not only is this more readable, it also makes reading
diff easier, as a change in symbol numbers won't have such a large
effect on the implementation of symbol actions.

* data/skeletons/bison.m4 (_b4_symbol_case): Use the symbol kind
rather than its number.
2020-05-23 15:41:29 +02:00
Akim Demaille
23f7554188 kinds: also define the possibly qualified symbol kinds
* data/skeletons/bison.m4 (b4_symbol_kind): Rename as...
(b4_symbol_kind_base): this.
(b4_symbol_kind): New, for fully qualified kind name.
* data/skeletons/lalr1.cc (b4_symbol_kind): New.
Adjust to use b4_symbol_kind where appropriate.
* src/parse-gram.h, src/parse-gram.c: regen.
2020-05-23 15:41:29 +02:00
Akim Demaille
3ff248ebfe m4: simplify useless quotation
* data/skeletons/bison.m4: The result of b4_symbol is "quoted"
already, no need for m4_expand.
2020-05-23 15:40:48 +02:00
Akim Demaille
4e1a5aae96 m4: use m4_shift2 etc.
* data/skeletons/bison.m4 (m4_shift4): New.
Use them where applicable.
2020-05-23 14:59:18 +02:00
Akim Demaille
e7aff57122 style: rename user_token_number as code
This should have been done in 3.6, but I wanted to avoid introducing
conflicts into Vincent's work on counterexamples.  It turns out it's
completely orthogonal.

* data/README.md, data/skeletons/bison.m4, data/skeletons/c++.m4,
* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/java.m4,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/variant.hh, data/skeletons/yacc.c, src/conflicts.c,
* src/derives.c, src/gram.c, src/gram.h, src/output.c,
* src/parse-gram.c, src/parse-gram.y, src/print-xml.c, src/print.c,
* src/reader.c, src/symtab.c, src/symtab.h, tests/input.at,
* tests/types.at:
s/user_token_number/code/g.
Plus minor changes.
2020-05-23 08:43:58 +02:00
Akim Demaille
339d11badf Merge maint into master
* upstream/maint:
  fix generated comments
  traces: provide a means to get short m4 traces
  traces: show the full m4 invocation
2020-05-22 20:35:13 +02:00
Akim Demaille
f80890c4bb fix generated comments
In Bison 3.6.2, the comments with brackets lose their brackets, for
improper m4 quotation.

* data/skeletons/bison.m4 (b4_gsub): New.
* data/skeletons/c-like.m4 (_b4_comment): Use it.
* tests/m4.at: Check b4_gsub.
2020-05-21 20:14:59 +02:00
Akim Demaille
1ebc2ac55c traces: provide a means to get short m4 traces
Let --trace=m4-early dump all the logs from the start (as --trace=m4
used to do), and have --trace=m4 now start traces only when actually
working of the user's grammar.

Can make a big difference in the case of small inputs.  E.g.

    $ bison -S tests/testsuite.dir/001/input.m4 tests/testsuite.dir/001/input.y --trace=m4 |& wc
       3952   19446  251068
    $ bison -S tests/testsuite.dir/001/input.m4 tests/testsuite.dir/001/input.y --trace=m4-early |& wc
      19491  131904 1830495

* data/skeletons/traceon.m4: New.
* src/getargs.h, src/getargs.c: Introduce --trace=m4-early.
* src/output.c (output_skeleton): Adjust for --trace=m4 and --trace=m4-early.
2020-05-21 20:13:04 +02:00
Akim Demaille
8ef0b12eb7 Merge branch 'maint'
* upstream/maint:
  maint: post-release administrivia
  version 3.6.2
  tests: improve update-test
  CI: add GCC 10 and Clang 10
  fix: do not emit nested comments
  todo: update
  examples: use markdown hyperlinks
  tests: don't use == to compare const char *...
  gnulib: update
2020-05-17 09:16:51 +02:00
Akim Demaille
e6d83116ae c: more fixes for _Noreturn
The previous fix was insufficient.

    tests/types.at:366: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    ++ ccache clang++-mp-9.0 -Qunused-arguments -ggdb -Wall -Wextra -Wcast-align -Wchar-subscripts -fparse-all-comments -Wdocumentation -Wformat -Wimplicit-fallthrough -Wnull-dereference -Wno-sign-compare -Wno-tautological-constant-out-of-range-compare -Wpointer-arith -Wshadow -Wwrite-strings -Wextra-semi -Wold-style-cast -Wundefined-func-template -Wweak-vtables -Wunreachable-code -Wundef -pedantic -Wconversion -Wdeprecated -Wsign-compare -Wsign-conversion -Wtautological-constant-out-of-range-compare -fno-color-diagnostics -Wno-keyword-macro -Werror -std=c++98 -I/Users/akim/src/gnu/bison/tests -isystem /opt/gostai/include -isystem /opt/local/include -L/opt/gostai/lib -L/opt/local/lib -o test test.cc /Users/akim/src/gnu/bison/_build/c9d/lib/libbison.a -lintl -Wl,-framework -Wl,CoreFoundation
    stderr:
    test.cc:955:1: error: _Noreturn functions are a C11-specific feature [-Werror,-Wc11-extensions]
    _Noreturn static void
    ^
    test.cc:963:1: error: _Noreturn functions are a C11-specific feature [-Werror,-Wc11-extensions]
    _Noreturn static void
    ^
    2 errors generated.

* data/skeletons/c.m4 (b4_attribute_define): Do not use _Noreturn at
all in C++, clang or not.
2020-05-17 09:16:41 +02:00
Akim Demaille
465babb635 fix: do not emit nested comments
With input such as

    %token<fl> yVL_CLOCK "/*verilator sc_clock*/"

we generate

    yVL_CLOCK = 610,      /* "/*verilator sc_clock*/"  */

which is invalid since the comment will actually be closed on the
first "*/".  Let's turn "*/" into "*\/" to avoid this.  But GCC will
also warn about "/*" inside a comment, so let's "escape" it too.

Reported by Huang Rui.
https://github.com/akimd/bison/issues/38

* data/skeletons/c-like.m4 (_b4_comment): Escape comment delimiters in
comments.
* tests/input.at (Torturing the Scanner): Check thes cases.
* tests/m4.at: New.
2020-05-17 08:28:12 +02:00
Akim Demaille
22c3839168 c: restore definition of _Noreturn as [[noreturn]] in C++
c.m4 contains a definition of _Noreturn which is modeled after
gnulib's lib/_Noreturn.h.  The latter was recently
changed (b61bf2f0e8) to not using
[[noreturn]] at all, because the uses of _Noreturn in gnulib are
sometimes incompatible with the rules of [[noreturn]].

As a result glr.cc started to use _Noreturn in C++, which clang
refuses (all the glr.cc tests currently fail with Clang++).

* data/skeletons/c.m4 (b4_attribute_define): Restore the definition of
_Noreturn as [[noreturn]] in modern C++.
The generated code uses _Noreturn in places where [[noreturn]] is
valid.
2020-05-16 17:29:38 +02:00
Akim Demaille
acba58ac59 Merge branch maint
* maint:
  news: update
  maint: post-release administrivia
  version 3.6.1
  c++: style: reorder generated code
  c++: provide yy::parser::symbol_type::name
  c++: make parser::symbol_name public
  examples: beware of ~/.inputrc
  build: also provide lzip compressed tarballs
  style: minor fixes
  yacc.c: restore ansi-c compatibility
2020-05-10 17:33:12 +02:00
Akim Demaille
b61bf2f0e8 don't use stdnoreturn
Reported by Paul Eggert.

* src/getargs.c: We don't need it anyway, since we use _Noreturn.
* data/skeletons/c.m4: While at it, update the definition of _Noreturn
stolen from gnulib.
2020-05-10 10:46:03 +02:00
Akim Demaille
091943f265 c++: style: reorder generated code
The implementation of yy::parser::symbol_name is emitted even before
the implementation of yy::parser::parser.  This makes little sense.

* data/skeletons/lalr1.cc (symbol_name): Move its implementation in
the same place as in the class definition: after "error" and before
"context".
2020-05-10 10:06:11 +02:00
Akim Demaille
bf98d94f4f c++: provide yy::parser::symbol_type::name
* data/skeletons/c++.m4 (yy::parser::basic_symbol::name): New.
* data/skeletons/lalr1.cc (yy_print_): Use it.
* doc/bison.texi: Document.
* tests/c++.at: Check.
2020-05-10 10:01:35 +02:00
Akim Demaille
6bb37dbe27 c++: make parser::symbol_name public
Reported by Martin Blais <blais@furius.ca>.
https://lists.gnu.org/r/help-bison/2020-05/msg00005.html

* data/skeletons/lalr1.cc (symbol_name): Make it public.
Add a private hidden hook to enable testing of private parts.
* tests/local.at (AT_DATA_GRAMMAR_PROLOGUE): Help Emacs find the right
language mode.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Check that we
can read symbol_name.
2020-05-10 09:42:37 +02:00
Akim Demaille
2da399d15f yacc.c: restore ansi-c compatibility
Reported by neok-m4700.
https://github.com/akimd/bison/issues/37

* data/skeletons/yacc.c: Don't use // comments.
2020-05-09 17:05:03 +02:00
Akim Demaille
d9a9b054ae all: fix the interface of yyexpected_tokens
The user gives yyexpected_tokens a limit: the max number of tokens she
wants to hear about.  That's because an error message that reports a
bazillion of possible tokens is useless.

In that case yyexpected_tokens returned 0, so the user would not know
if there are too many expected tokens or none (yes, that's possible).

There are several ways to tell the user in which situation she's in:

- return some E2MANY, a negative value.  Then it makes the pattern

    int argsize = yypcontext_expected_tokens (ctx, arg, ARGS_MAX);
    if (argsize < 0)
      return argsize;

  no longer valid, as for E2MANY (i) the user must generate the error
  message anyway, and (ii) she should not return E2MANY

- return ARGS_MAX + 1.  Then it makes it dangerous for the user, as
  she has to iterate update `min (ARGS_MAX, argsize)`.

Returning 0 is definitely simpler and safer for the user, as it tells
her "this is not an error, just generate your message without a list
of expecting tokens".  So let's still return 0, but set arg[0] to the
empty token when the list is really empty.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.java
* data/skeletons/yacc.c (yyexpected_tokens): Put the empty symbol
first if there are no possible tokens at all.
* examples/c/bistromathic/parse.y: Demonstrate how to use that.
2020-05-06 08:11:52 +02:00