Commit Graph

5276 Commits

Author SHA1 Message Date
Akim Demaille
1fa19a7697 api.value.type: diagnose guaranteed failure with --yacc
Instead of generating invalid C code, generate an error when --yacc and
'%define api.value.type union' are used together.

* data/bison.m4: Issue an error in this case.
* tests/types.at (%yacc vs. %define api.value.type union): New, check this
error.
* doc/bison.texi (Type Generation): Document it.
* tests/output.at: Check that '-o y.tab.c' and '-y' behave equally
wrt generated file names.
* NEWS (Use of YACC='bison -y'): New.
Promote the use of 'bison -o y.tab.c'.
2013-04-09 14:07:52 +02:00
Akim Demaille
d1a07886ee doc: style changes
* doc/bison.texi (Destructor Decl, Printer Decl): Group series of %token
and %type together.
2013-04-09 14:07:52 +02:00
Akim Demaille
71846502ae doc: display locations in error as recommended by GNU Coding Standards
* doc/bison.texi (Actions and Locations): here.
2013-04-09 14:07:52 +02:00
Akim Demaille
90b89dadb2 doc: api.value.type union
* doc/bison.texi (Type Generation): New section.
(Multi-function Calc): Convert to use api.value.type=union.
2013-04-09 14:07:51 +02:00
Akim Demaille
e4d49586b6 doc: move the section about "%union" where types are discussed
* doc/bison.texi (Union Decl): Move to...
(Defining Language Semantics): here.
2013-04-09 14:07:51 +02:00
Akim Demaille
21e3a2b56c doc: deprecate #define YYSTYPE in favor of %define api.value.type
* doc/bison.texi: Convert examples with YYSTYPE to use api.value.type.
Deprecate YYSTYPE.
2013-04-09 14:07:51 +02:00
Akim Demaille
cb8d8bb9b6 value type: accept "->" in type tags
Provide a means to dereference pointers when defining tags.  One
example could be:

  %code requires
  {
    typedef struct ListElementType
    {
      union value
      {
        int intVal;
        float floatVal;
        char* charptrVal;
      } value;

      struct ListElementType* next;
    } ListElementType;
  }

  %union
  {
    ListElementType* list;
  }

  %token <list->value.charptrVal> STRING
  %token <list->value.intVal> INTEGER
  %token <list->value.floatVal> REAL
  %type <list> ElementList LiteralType

* src/scan-code.l, src/scan-gram.l: Accept "->" in tags.
* tests/types.at: Add more test cases to cover this case.
2013-04-09 14:07:51 +02:00
Akim Demaille
e52ddf820b style: simplify the scanning of type tags
* src/scan-gram.l: Remove the rule for simple tags: the "complex" case
subsumes it.  It was more efficient, but duplicated the code for a
negligible benefit.
2013-04-09 14:07:51 +02:00
Akim Demaille
6574576cfb api.value.type: implement proper support, check, and document
* data/c.m4 (b4_symbol_type_register, b4_type_define_tag)
(b4_symbol_value_union, b4_value_type_setup_union)
(b4_value_type_setup_variant, b4_value_type_setup):
New.
(b4_value_type_define): Use it to set up properly the type.
Handle the various possible values of api.value.type.
* data/c++.m4 (b4_value_type_declare): Likewise.
* data/lalr1.cc (b4_value_type_setup_variant): Redefine.

* tests/types.at: New.
Exercise all the C/C++ skeletons with different types of
api.value.type values.
* tests/local.mk, tests/testsuite.at: Use it.

* doc/bison.texi (%define Summary): Document api.value.type.
* NEWS: Advertise it, together with api.token.constructor.
2013-04-09 14:07:51 +02:00
Akim Demaille
dde95ca432 m4: allow the definition of side-effect only macros
* data/bison.m4 (b4_divert_kill, b4_define_silent): New.
* data/c.m4: Comment change.
2013-04-09 14:07:51 +02:00
Akim Demaille
6155db81aa variant: fix inconsistent quotation
* data/variant.hh (b4_char_sizeof): De-overquote.
(b4_value_type_declare): De-underquote.
2013-04-09 14:07:51 +02:00
Akim Demaille
11872a8372 m4: style changes in error messages
* data/bison.m4: Use $0 to denote the current macro's name.
2013-04-09 14:07:50 +02:00
Akim Demaille
eb0e86ac80 api.namespace: demonstrate and use {...} values instead of "..." values
* tests/c++.at, tests/input.at: Use "%define api.namespace {foo}" instead
of using quotes.
* tests/local.at (AT_SETUP_STRIP, AT_NAME_PREFIX): Recognize uses of
braces instead of quotes.
* doc/bison.texi: Use braces for api.namespace's values.
2013-04-05 10:43:44 +02:00
Akim Demaille
57597927ef grammar: do not add a \n at the end of blocks of code
Now that we use "braceless" (which is {...} blocks of code with
initial and final braces stripped) to denote "short" values (such as
api.namespaces), the added end-of-line is a nuisance.  As a matter of
fact, this extra-safety was useless, as every expansion of "braceless"
(aka, "user code") is followed by an end of line.

* src/parse-gram.y, src/parse-gram.c (braceless): Instead of replacing
the final brace by \n, just delete the brace.
2013-04-05 10:42:59 +02:00
Akim Demaille
de5fb744c9 regen 2013-04-04 16:50:55 +02:00
Akim Demaille
14bfd2e9d9 grammar: record the kind of %define variable values
Provide a means to tell the difference between "keyword" values (e.g.,
%define api.pull both), "string" values (e.g., %define file.name
"foo"), and "code" values (e.g., %define api.namespace {calc}).

Suggested by Joel E. Denny.
http://lists.gnu.org/archive/html/bison-patches/2013-03/msg00016.html

* src/muscle-tab.h, src/muscle-tab.c (muscle_kind, muscle_kind_new)
(muscle_kind_string): New.
(muscle_percent_define_insert): Take the kind as new argument.
Insert it in the muscle table.
Adjust callers.
* src/getargs.c: Adjust callers.
* src/parse-gram.y: Ditto.
(content.opt): Remove, replaced by...
(value): this new non-terminal, whose semantics value is stored
in the new "value" union member.
Provide a printer.
Support values in braces in additions to keyword and string values.

fuse me
2013-04-04 16:50:38 +02:00
Akim Demaille
36a17b50b5 style: fix comments
* src/muscle-tab.c (muscle_percent_define_ensure): Update obsolete
comments.
2013-04-04 16:27:54 +02:00
Akim Demaille
8a9283494b regen 2013-04-04 15:48:08 +02:00
Akim Demaille
dac72a91d9 grammar: style changes
* src/parse-gram.y (PARAM_TYPE): Remove useless typedef guard.
There's a header guard.
Use 'yyo' with %printer.
Use a consistent style for %union one-liners.
2013-04-04 15:41:49 +02:00
Akim Demaille
a17c70f876 grammar: split %union to group together related aspects
* src/parse-gram.y (INT): Fuse the %type and %token declaration.
Move its %union right before its introduction.
(%union): Split in several %unions, right before their use.
2013-04-04 15:38:06 +02:00
Akim Demaille
c56d0037d2 muscle: refactor
* src/muscle-tab.c (muscle_lookup, muscle_entry_new): New.
(muscle_insert, muscle_grow, muscle_find_const, muscle_find): Use them.
2013-04-04 15:18:29 +02:00
Akim Demaille
9fb61ca8d8 style: comment changes
* src/muscle-tab.c: Move the documentation of public functions to...
* src/muscle-tab.h: here.
Fix comment consistency issues.
2013-04-03 17:15:50 +02:00
Akim Demaille
3f6e5dd6ac muscle: minor refactoring
* src/muscle-tab.h (MUSCLE_INSERT_C_STRING): Use MUSCLE_INSERT_STRING.
2013-04-03 17:07:22 +02:00
Akim Demaille
2dc8862bab regen 2013-03-06 10:31:55 +01:00
Valentin Tolmer
5202b6ac1d gram: correct token numbering in precedence declarations
In a precedence declaration, when tokens are declared with a litteral
character (e.g., 'a') or with a identifier (e.g., B), Bison behaved
differently: the litteral tokens would be numbered first, and then the
other ones, leading to the following grammar:

  %right A B 'c' 'd'

being numbered as such: 'c' 'd' A B.

* src/parse-gram.y (symbol.prec): Set the symbol number when reading the
symbols.
* tests/conflicts.at (Token declaration order: literals vs. identifiers):
New.

Signed-off-by: Akim Demaille <akim@lrde.epita.fr>
2013-03-06 10:31:47 +01:00
Akim Demaille
02879b4e81 maint: update autoconf submodule
* submodules/autoconf: Up to master.
No significant changes in the files we use (m4sugar.m4 and foreach.m4).
2013-03-04 18:26:25 +01:00
Akim Demaille
f24695eff9 diagnostics: no longer include the yacc category in -Wall
It would be a pity to warn the users against Bison features...
http://lists.gnu.org/archive/html/bison-patches/2013-02/msg00107.html

* src/complain.h, src/complain.c (Wall): Disable Wyacc.
(Weverything): New (hidden so far) category which really denotes all
the categories (what used to be Wall).
(warnings_args, warnings_types): Adjust.
(warning_argmatch): Now !none = Weverything and conversely, no longer Wall.
* NEWS, doc/bison.texi, src/getargs.c: Adjust the documentation.
* tests/input.at (-Werror is not affected by -Wnone and -Wall): Adjust
by not using a -Wyacc type of warning.
2013-03-04 18:21:44 +01:00
Akim Demaille
05e25f2384 grammar: no longer detect and cure missing semicolon at end of actions
Bison 3.0 is already breaking backward compatibility with other
features.  It is an appropriate time to drop this feature.  Note that
it was disabled when --yacc is passed.  See
http://lists.gnu.org/archive/html/bison-patches/2013-02/msg00102.html

Basically, revert e8cd1ad655.

* src/scan-code.l (braces_level, need_semicolon, in_cpp): Remove.
Remove every rule needed to detect and add missing semicolon.
* tests/actions.at (Fix user actions without a trailing semicolon):
Remove.
* NEWS: Adjust.
2013-03-04 08:29:18 +01:00
Akim Demaille
f1526426cd build: stop using bison -y
* Makefile.am (YACC): Pass -o y.tab.c, so that ylwrap is happy, and
yet we don't pass --yacc to bison.
(AM_YFLAGS): Disable Yacc warnings.
2013-03-04 08:25:32 +01:00
Akim Demaille
7601a471f5 c++: rename b4_semantic_type_declare as b4_value_type_declare
This is to match the names used in C and api.value.type, even if the
parser actually defines semantic_type.

* data/c++.m4 (b4_semantic_type_declare): Rename as...
(b4_value_type_declare): this.
* data/variant.hh: Likewise.
2013-02-23 16:16:15 +01:00
Akim Demaille
6c7022f7d3 news: typo
* NEWS: here.
2013-02-23 16:16:15 +01:00
Akim Demaille
edd3280b69 style: space changes in the tests
* tests/local.at: here.
2013-02-23 16:16:15 +01:00
Akim Demaille
fe65b14424 style: formatting changes in the doc
* doc/bison.texi: Use @file where appropriate.
2013-02-22 13:18:39 +01:00
Akim Demaille
e39fcdda38 tests: fix invalid C++11 code
* tests/c++.at (Object): Somehow instances of Object were assigned
YY_NULL, which is 0 most of the time (that case passes), but is
nullptr in C++11, and there is nothing in Object to support such an
assignment (failure).  Use 0 as value, and provide the needed
assignment operator.
Also, use a more natural order within the class definition.
2013-02-19 17:47:13 +01:00
Akim Demaille
5ae8eb3202 tests: fix failures with G++ 4.8 in Flex scanner
* configure.ac (WARN_NO_NULL_CONVERSION_CXXFLAGS): Rename as...
(FLEX_SCANNER_CXXFLAGS): this.
Pass -Wno-zero-as-null-pointer-constant to G++ if it supports it.
* examples/calc++/local.mk: Adjust.
2013-02-19 17:42:33 +01:00
Akim Demaille
bbed3fdef6 regen 2013-02-19 10:07:37 +01:00
Akim Demaille
42fef01256 gnulib: update 2013-02-19 09:51:38 +01:00
Akim Demaille
29248b4c13 style: rename variant private members
* data/variant.hh (buffer, tname, as_, raw, align_me): Rename as...
(yybuffer_, yytname_,yyas_, yyraw, yyalign_me): these.
2013-02-19 09:51:38 +01:00
Akim Demaille
361444e419 style: space changes
* data/variant.hh: Be sure to leave a space before arguments in function
calls.
2013-02-19 09:51:38 +01:00
Akim Demaille
85bc7f5466 variant: fix G++ 4.4 warnings
The changes by Théophile Ranquet about type punning issues need
to be extend to in-place new to please G++ 4.4.7.

* data/variant.hh (variant::as_): New, factors the casts that avoid
compiler warnings.
(as, build): Use them.
2013-02-19 09:51:38 +01:00
Akim Demaille
1282c12476 news: spell fixes
* NEWS: here.
2013-02-18 14:30:19 +01:00
Akim Demaille
0fe5a72a26 diagnostics: factor and enhance messages about duplicate rule directives
When reporting a duplicate directive on a rule, point to its first
occurrence:

one.y:11.10-15: error: only one %empty allowed per rule
   %empty {} %empty
             ^^^^^^
one.y:11.3-8: previous declaration
   %empty {} %empty
   ^^^^^^

And consistently discard the second one.

* src/complain.h, src/complain.c (duplicate_directive): New.
* src/reader.c: Use it where appropriate.
* src/symlist.h, src/symlist.c (symbol_list): Add a dprec_location member.
* tests/actions.at: Adjust expected output.
2013-02-18 10:01:29 +01:00
Akim Demaille
4c9b8f1318 style: no longer use backquotes
* tests/actions.at, tests/atlocal.in, tests/c++.at, tests/calc.at,
* tests/conflicts.at, tests/existing.at, tests/glr-regression.at,
* tests/input.at, tests/java.at, tests/local.at, tests/sets.at,
* tests/synclines.at, doc/bison.texi, lib/libiberty.h, lib/timevar.h:
Use single quotes.
2013-02-18 10:01:28 +01:00
Akim Demaille
45eebca42d style: no longer use backquotes
* README, REFERENCES, TODO, configure.ac, data/README, data/bison.m4,
* data/c++.m4, data/c.m4, data/java.m4, data/lalr1.cc,
* data/lalr1.java, data/yacc.c, doc/local.mk, etc/bench.pl.in,
* src/conflicts.c, src/files.c, src/getargs.c, src/gram.h, src/lalr.c,
* src/location.c, src/location.h, src/muscle-tab.c, src/muscle-tab.h,
* src/output.c, src/parse-gram.c, src/parse-gram.y, src/print-xml.c,
* src/print.c, src/reader.c, src/reduce.c, src/scan-skel.l,
* src/symtab.h, src/system.h, src/tables.c:
Use single quotes, as currently recommended by the GNU Coding Standards.
2013-02-18 10:01:28 +01:00
Akim Demaille
d49751602c style: no longer use backquotes in messages
* src/getargs.c (usage): Use single quotes.
2013-02-18 10:01:28 +01:00
Akim Demaille
6240346aa0 doc: use %empty instead of /* empty */
* doc/bison.texi: Change the comments into explicit %empty.
2013-02-18 10:01:28 +01:00
Akim Demaille
09add9c24f doc: introduce %empty and -Wempty-rule
* doc/bison.texi (Grammar Rules): Make it a @section which
contains...
(Rules Syntax): this new subsection (with the previous contents of
"Grammar Rules".
(Empty Rules): New subsection, extracted from the former
"Grammar Rules".
Document %empty.
(Recursion): New a subsection of "Grammar Rules".
Complete a few index entries.
(Bison Options): Document -Wempty-rule.
2013-02-18 10:01:28 +01:00
Akim Demaille
8b807f1177 report: use %empty to denote empty rules
* src/gram.c (rule_rhs_print): Use %empty for empty rules.
* tests/conflicts.at, tests/regression.at, tests/sets.at: Adjust.
2013-02-18 10:01:28 +01:00
Akim Demaille
42d101da8d diagnostics: %empty enables -Wempty-rule
* src/complain.h, src/complain.c (warning_is_unset): New.
* src/reader.c (grammar_current_rule_empty_set): If enabled -Wempty-rule,
if not disabled.
* tests/actions.at (Implicitly empty rule): Check this feature.
Also check that -Wno-empty-rule does disable this warning.
2013-02-18 10:01:28 +01:00
Akim Demaille
f68a49ed49 -Wempty-rule: diagnose empty rules without %empty
* src/complain.h, src/complain.c (warning_empty_rule, Wempty_rule):
New warning category.
(warnings_args, warnings_types): Adjust.
* src/reader.c (grammar_rule_check): Check the empty rules are
flagged by %empty.
* tests/actions.at (Implicitly empty rule): New.
* tests/existing.at: Add expected warnings.
2013-02-18 10:01:27 +01:00