Commit Graph

6876 Commits

Author SHA1 Message Date
Akim Demaille
9e9e49224f diagnostics: style changes
* src/complain.h, src/complain.c: Comment changes.
* src/scan-skel.l: Reduce scopes.
* data/skeletons/bison.m4: Factor diagnostic functions.
2019-12-02 19:35:01 +01:00
Akim Demaille
8b53f4e022 glr.c: style changes
* data/skeletons/glr.c (yysplitStack): Reduce scopes.
* tests/atlocal.in: Formatting changes.
2019-12-02 19:34:48 +01:00
Akim Demaille
8c87a62308 c++: get rid of symbol_type::token ()
It is not used.  And its implementation was wrong when api.token.raw
was defined, as it was still mapping to the external token numbers,
instead of the internal ones.  Besides it was provided only when
api.token.constructor is defined, yet always declared.

* data/skeletons/c++.m4 (by_type::token): Remove, useless.
2019-12-01 10:05:48 +01:00
Akim Demaille
478cb5cf12 c++: remove useless cast about user_token_number_max_
Reported by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00016.html

The cast is needed when yytranslate_'s argument type is token_type,
i.e., when api.token.constructor is defined.

    373. types.at:138: testing lalr1.cc api.value.type=variant api.token.constructor ...
    ======== Testing with C++ standard flags: ''
    ../../tests/types.at:138: bison --color=no -fno-caret  -o test.cc test.y
    ../../tests/types.at:138: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    stderr:
    test.cc:966:16: error: result of comparison of constant 257 with
                    expression of type 'yy::parser::token_type'
                   (aka 'yy::parser::token::yytokentype') is always true
                   [-Werror,-Wtautological-constant-out-of-range-compare]
        else if (t <= user_token_number_max_)
                 ~ ^  ~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.

It is because it is expected that when api.token.constructor is
defined, only symbol constructors will be used, that yytranslate_ then
takes a token_type.  But it is wrong: we still allow literal
characters in this case, as demonstrated by test 373 for instance.

    %define api.value.type variant
    %define api.token.constructor
    %token <std::pair<int, int>> '1' '2';
    [...]
    static yy::parser::symbol_type yylex ()
    {
      static char const input[] = "12";
      int res = input[toknum++];
      typedef yy::parser::symbol_type symbol;
      if (res)
        return symbol (res, std::make_pair (res - '0', res - '0' + 1));
      else
        return symbol (res);
    }

So let yytranslate_ always take an int, which makes the cast truly
useless.

* data/skeletons/c++.m4, data/skeletons/lalr1.cc (yytranslate_): here.
2019-12-01 08:53:58 +01:00
Akim Demaille
94f70bd861 c++: clean a few issues wrt special tokens
The C++ implementation of LAC did not skip the $undefined token,
probably because it was not exposed.  Expose it, and use clearer
names.

* data/skeletons/c++.m4: Don't define undef_token_ in yytranslate_,
but...
* data/skeletons/lalr1.cc (yy_undef_token_): here.
Use a more precise type to define yy_undef_token_ and yy_error_token_.
Unfortunately we move from a compile-time value defined via an enum to
a static const member.  Eventually we should make it constexpr.
Make LAC implementation more alike yacc.c's one.
2019-12-01 08:08:19 +01:00
Akim Demaille
9b4f0970fe d, java: improve yytranslate and neighbors
* data/skeletons/lalr1.d, data/skeletons/lalr1.java: Don't expose
yyuser_token_number_max_ and yyundef_token_.  Do as in C++: scope them
into yytranslate_, and only when api.token.raw is not defined.
(yyterror_): Rename as...
(yy_error_token_): this.
* data/skeletons/lalr1.d (token_number_type): New.
Use it.
Can't be done in the Java backend, as Java does not have type aliases.
2019-12-01 07:59:23 +01:00
Akim Demaille
869028a66d d, java: get rid of a useless table
* data/skeletons/lalr1.d, data/skeletons/lalr1.java (yytoken_number_):
Remove, useless.
Was used in ancient C skeletons to support YYPRINT, long obsoleted by
%printer.
2019-12-01 07:38:31 +01:00
Akim Demaille
6f92a7f664 c++, d, java: remove yyerrcode
It is not used at all.  We will remove it also from yacc.c, but
later (see TODO).

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java (yyerrcode_):
Remove.
2019-11-30 17:30:48 +01:00
Akim Demaille
6a61b6b17e c++: improve typing
* data/skeletons/lalr1.cc (yysyntax_error_): symbol_type::type_get
returns a symbol_number_type (which is indeed an int).
2019-11-30 17:30:48 +01:00
Akim Demaille
a4bf7cdf9e c++: remove useless cast about yyeof_
Reported by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00016.html

* data/skeletons/c++.m4 (b4_yytranslate_define): Don't use yyeof_ as
if it had two different types.
It is used once against the input argument, which is the value
returned by yylex, which is an "external token number", typically an
int.  It is also used as output type, an "internal symbol number".
It turns out that in both cases we mean "0", but let's keep yyeof_
only for the case "internal symbol number", i.e., _after_ conversion
by yytranslate.
This frees us from one cast.
2019-11-30 17:30:48 +01:00
Akim Demaille
9471a5ffe9 glr: style change
* data/skeletons/glr.c (YYDPRINTF): Expand into an empty statement,
instead of nothing.
Simplify callers.
2019-11-30 14:41:16 +01:00
Akim Demaille
24c5214ae8 glr: remove useless casts
Reported by GCC's -Wuseless-cast.

* data/skeletons/glr.c: Don't cast to yybool, it's useless.
2019-11-30 14:41:16 +01:00
Akim Demaille
2f7097d1b1 yacc.c, glr.c: fix crash when reporting errors in consistent states
The current code for yysyntax_error for %define parse.error verbose is
fishy (given that YYEMPTY is -2, invalid argument for yytname[]):

    static int
    yysyntax_error ([...])
    {
      YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
    [...]
      if (yytoken != YYEMPTY)

A nearby comment reports

    The only way there can be no lookahead present (in yychar) is if
    this state is a consistent state with a default action.  Thus,
    detecting the absence of a lookahead is sufficient to determine
    that there is no unexpected or expected token to report.  In that
    case, just report a simple "syntax error".

So it _is_ possible to call yysyntax_error with yytoken == YYEMPTY,
albeit quite difficult when meaning to, so virtually impossible by
accident (after all, there was never a bug report about this).

I failed to produce a test case, but Joel E. Denny provided me with
one (added to the test suite below).  The yacc.c skeleton fails on
this, and once fixed dies on a second problem.  The glr.c skeleton was
also dying, but immediately of this second problem.

Indeed we were not allocating space for the error message's final \0.
This was hidden by the fact that we only had error messages with at
least an unexpected token displayed, so with at least one "%s" in the
format string, whose size (2) was included (incorrectly) in the final
size of the message (where the %s have been replaced by the actual
content).

* data/skeletons/glr.c, data/skeletons/yacc.c (yysyntax_error):
Do not invoke yytnamerr on YYEMPTY.
Clarify the computation of the length of the _final_ error message,
with the NUL terminator but without the '%s's.
* tests/conflicts.at (Syntax error in consistent error state):
New, contributed by Joel E. Denny.
2019-11-29 18:21:43 +01:00
Akim Demaille
28369ecb5d tests: avoid creating files whose name collide with standard headers
Having a file named "exception" is risky: the compiler might use that
file in #include.
Reported by 马俊 <majun123@whu.edu.cn>.

* tests/local.at (AT_SKIP_IF_EXCEPTION_SUPPORT_IS_POOR): Generate
'exceptions', not 'exception'.
2019-11-26 08:05:32 +01:00
Akim Demaille
b92f064e9b doc: more details about the test suite
* README-hacking.md: here.
2019-11-22 09:02:06 +01:00
Akim Demaille
98f19578aa maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-11-20 07:49:44 +01:00
Akim Demaille
7d9839c4a8 version 3.4.91
* NEWS: Record release date.
v3.4.91
2019-11-20 07:13:38 +01:00
Akim Demaille
ad32ec64c8 style: pacify syntax-check
* cfg.mk: No need to translate *.md files.
* data/skeletons/glr.c, data/skeletons/yacc.c: Fix space issues.
2019-11-20 07:10:27 +01:00
Akim Demaille
44cdc0f001 gnulib: update 2019-11-19 21:15:00 +01:00
Akim Demaille
ca796220ec doc: don't promote dangling aliases
String literals as tokens serve two distinct purposes: freeing from
having to implement the keyword matching in the scanner, and improving
error messages.  Most of the time both can be achieved at the same
time, but on occasions, it does not work so well.

We promote their use for error messages.  We will also still support
the former case, but it is _not_ the recommended approach.

* doc/bison.texi (Tokens from Literals): Clearly state that we don't
recommend looking up the token types in the list of token names.
2019-11-18 09:15:35 +01:00
Akim Demaille
8a910107b3 diagnostics: complain about undeclared string tokens
String literals, which allow for better error messages, are (too)
liberally accepted by Bison, which might result in silent errors.  For
instance

    %type <exVal> cond "condition"

does not define “condition” as a string alias to 'cond' (nonterminal
symbols do not have string aliases).  It is rather equivalent to

    %nterm <exVal> cond
    %token <exVal> "condition"

i.e., it gives the type 'exVal' to the "condition" token, which was
clearly not the intention.

Introduce -Wdangling-alias to catch this.

* src/complain.h, src/complain.c: Add support for -Wdangling-alias.
(argmatch_warning_args): Sort.
* src/symtab.c (symbol_check_defined): Complain about dangling
aliases.
* doc/bison.texi: Document it.
* tests/input.at (Dangling aliases): New test.
2019-11-17 18:27:42 +01:00
Akim Demaille
28d1ca8f48 diagnostics: yacc reserves %type to nonterminals
On

    %token TOKEN1
    %type  <ival> TOKEN1 TOKEN2 't'
    %token TOKEN2
    %%
    expr:

bison -Wyacc gives

    input.y:2.15-20: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |               ^~~~~~
    input.y:2.29-31: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |                             ^~~
    input.y:2.22-27: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |                      ^~~~~~

The messages appear to be out of order, but they are emitted when the
error is found.

* src/symtab.h (symbol_class): Add pct_type_sym, used to denote
symbols appearing in %type.
* src/symtab.c (complain_pct_type_on_token): New.
(symbol_class_set): Check that %type is not applied to tokens.
(symbol_check_defined): pct_type_sym also means undefined.
* src/parse-gram.y (symbol_decl.1): Set the class to pct_type_sym.
* src/reader.c (grammar_current_rule_begin): pct_type_sym also means
undefined.
* tests/input.at (Yacc's %type): New.
2019-11-17 09:45:25 +01:00
Akim Demaille
1817b475a6 doc: promote %nterm over %type
As an extension to POSIX Yacc, Bison's %type accepts tokens.
Unfortunately with string literals as implicit tokens, this is
misleading, and led some users to write

    %type <exVal> cond "condition"

believing that "condition" would be associated to the 'cond'
nonterminal (see https://github.com/apache/httpd/pull/72).

* doc/bison.texi: Promote %nterm rather than %type to declare the type
of nonterminals.
2019-11-16 12:54:44 +01:00
Akim Demaille
22ca07defa doc: formatting changes
* doc/bison.texi: No visible changes.
2019-11-16 12:54:44 +01:00
Akim Demaille
dbd6975b5c doc: work around warnings when Flex C output is compiled in C++
* doc/bison.texi (calc++/scanner.ll): here.
While at it, clarify clang vs. warnings.
2019-11-16 12:54:44 +01:00
Akim Demaille
cd726fdc4d tests: be robust to old Perl versions on Cygwin
Reported by Denis Excoffier.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00008.html.

* tests/output.at: Be sure to remove back up files.
2019-11-16 12:54:44 +01:00
Akim Demaille
60ebd8e210 regen 2019-11-16 12:54:44 +01:00
kaneko y
3765e3e790 gram.c: Fix condition of aver
* src/gram.c (grammar_dump): Fix condition of aver.
What we want to check is that rhs is followed by its rule.
2019-11-12 08:39:28 +01:00
Akim Demaille
c313360deb doc: clarify build instructions
* README: A few fixes.
Explain how to install color support.
* README-hacking: Rename as...
* README-hacking.md: this, and convert to Markdown.
Improve typography.
Improve explanations about update-test.
2019-11-11 15:59:53 +01:00
Akim Demaille
25698b58c0 gnulib: update 2019-11-11 15:41:29 +01:00
Yuichiro Kaneko
17d34c231b gram.c: also print terminals in grammar_dump
* src/gram.c (grammar_dump): Print terminals likewise non terminals.
* tests/sets.at (Reduced Grammar): Update test case to catch up the
change and add a test case where prec and assoc are used.
2019-11-11 10:37:30 +01:00
Akim Demaille
af000bab11 doc: work around Texinfo 6.7 bug
When @code is used in a @deftype... definition, it issues quotes.
Remove them.
See https://lists.gnu.org/archive/html/help-texinfo/2019-11/msg00004.html.

* doc/local.mk: here.
2019-11-10 14:59:11 +01:00
Akim Demaille
b2347a3c3e doc: formatting changes
* doc/bison.texi: Wrap lines.
No semantical difference.
2019-11-09 07:57:05 +01:00
Akim Demaille
008d927f71 doc: use upper case for tokens
* doc/bison.texi: here.
2019-11-09 07:54:32 +01:00
Akim Demaille
1650c729d9 doc: type-face fixes
* doc/bison.texi: Use @code for types in function definitions.
2019-11-07 07:13:40 +01:00
Akim Demaille
7bdf7246fb c++: expose the type used to store line and column numbers
* data/skeletons/location.cc (position::counter_type)
(location::counter_type): New.
Use them.
* doc/bison.texi (C++ position, C++ location): Adjust.
2019-11-06 18:20:15 +01:00
Akim Demaille
583c193ffa tests: fix comment and adjust to locale names on GNU/Linux
Reported by Denis Excoffier.

* tests/diagnostics.at: here.
2019-11-03 10:32:22 +01:00
Akim Demaille
47b9ada6fa tests: really check complaints from m4
* tests/diagnostics.at (Locations from M4, Tabulations and multibyte
characters from M4): These tests are actually checking a message
coming from C, not from M4.  Replace with...
(Complaints from M4): This.
2019-11-03 10:32:22 +01:00
Akim Demaille
dcd5bb26e3 tests: simplify prologue
* tests/testsuite.h: We no longer load gnulib in the tests.
2019-11-03 10:32:22 +01:00
Akim Demaille
cce6c998b6 diagnostics: add missing translation
* src/muscle-tab.c (muscle_percent_define_check_kind): Here.
2019-11-03 09:24:12 +01:00
Akim Demaille
3398b0fa90 c++: fix old cast warnings
We still have a few old C casts in lalr1.cc, let's get rid of them.
Reported by Frank Heckenbach.

Actually, let's monitor all our casts using easy to grep macros.
Let's use these macros to use the C++ standard casts when we are in
C++.

* data/skeletons/c.m4 (b4_cast_define): New.
* data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, data/skeletons/stack.hh,
* data/skeletons/yacc.c:
Use it and/or its casts.

* tests/actions.at, tests/cxx-type.at,
* tests/glr-regression.at, tests/headers.at, tests/torture.at,
* tests/types.at:
Use YY_CAST instead of C casts.

* configure.ac (warn_cxx): Add -Wold-style-cast.
* doc/bison.texi: Disable it.
2019-11-02 16:40:50 +01:00
Akim Demaille
2bd1d9e20f tests: be robust to tput errors
Reported by Denis Excoffier.

* tests/bison.in: here.
2019-11-01 12:04:13 +01:00
Akim Demaille
1f2546396e git: update ignores
I don't understand what happened in
10acc148bb.
2019-11-01 12:04:13 +01:00
Akim Demaille
809268c1a4 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-10-29 21:58:53 +01:00
Akim Demaille
10acc148bb version 3.4.90
* NEWS: Record release date.
v3.4.90
2019-10-29 21:41:00 +01:00
Akim Demaille
28f1e1546c C++: finish propagating the unsigned->signed conversion in locations
* data/skeletons/location.cc: Remove the u (for unsigned) suffix from
the initial line and column.
* NEWS: AFAICT, only C++ backends have their location types changed.
2019-10-29 09:15:25 +01:00
Akim Demaille
c53b379784 style: fix cpp indentation
Reported by syntax-check.

* src/system.h: here.
2019-10-29 09:00:46 +01:00
Akim Demaille
fead28d9e3 style: glr.c: comment changes
* data/skeletons/glr.c: here.
2019-10-29 08:59:18 +01:00
Akim Demaille
7e0b50c524 CI: pass -O1 to GCC8 with sanitizers
This build never finishes in the 50min credit given by Travis.  See if
with optimizations it works better.

* .travis.yml: here.
2019-10-26 10:39:01 +02:00
Akim Demaille
8228d96d33 reader: reduce the "scope" of global variables
We have too many global variables, adding structure would help.  For a
start, let's hide some of the variables closer to their usage.

* src/getargs.c, src/files.h (current_file): Move to...
* src/scan-gram.c: here.
* src/scan-gram.h (gram_in, gram__flex_debug): Remove, make them
private to the scanner.
* src/reader.h, src/reader.c (reader): Take a grammar file as argument.
Move the handling of scanner variables to...
* src/scan-gram.l (gram_scanner_open, gram_scanner_close): here.
(gram_scanner_initialize): Remove, replaced by gram_scanner_open.
* src/main.c: Adjust.
2019-10-26 10:39:01 +02:00