399 Commits

Author SHA1 Message Date
Akim Demaille
cda1934606 yacc.c: add custom error message generation
When parse.error is custom, let users define a yyreport_syntax_error
function, and use it.

* data/skeletons/bison.m4 (b4_error_verbose_if): Accept 'custom'.
* data/skeletons/yacc.c: Implement it.
* examples/c/calc/calc.y: Experiment with it.
2020-01-17 06:49:59 +01:00
Akim Demaille
c67daa9a97 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-10 19:16:23 +01:00
Akim Demaille
8036635251 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-05 10:26:35 +01:00
Akim Demaille
7f01adced9 tests: don't fail if seq is no available
As is the case on Solaris.
Reported by Dennis Clarke.
https://lists.gnu.org/archive/html/bug-bison/2019-12/msg00011.html

* examples/c/reccalc/reccalc.test: Skip if there is no seq.
2019-12-14 17:19:53 +01:00
Akim Demaille
719395c9cd examples: fix missing dependencies
Reported by Thomas Petazzoni.
https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00000.html

* examples/c/reccalc/local.mk: Complete dependencies, including for
earlier versions of Automake (for sake of our CI, on top of Ubuntu
Xenial/Bionic, which feature only Automake 1.15).
(%D%/scan.c %D%/scan.h): Upgrade to the full version provided in
Automake's documentation.
2019-10-24 18:01:53 +02:00
Akim Demaille
17e21f6158 gitignore: update 2019-10-23 23:09:56 +02:00
Paul Eggert
41e84cddc7 Port lexcalc scan.l to Solaris 10
* examples/c/lexcalc/scan.l: Include errno.h.
2019-10-05 01:19:39 -07:00
Paul Eggert
133edcd248 Prefer signed to unsigned integers
This patch contains more fixes to prefer signed to unsigned
integer types, as modern tools like 'gcc -fsanitize=undefined'
can check for signed integer overflow but not unsigned overflow.
* NEWS: Document the API change.
* boostrap.conf (gnulib_modules): Add intprops.
* data/skeletons/glr.c: Include stddef.h and stdint.h,
since this skeleton can assume C99 or later.
(YYSIZEMAX): Now signed, and the minimum of SIZE_MAX and PTRDIFF_MAX.
(yybool) [!__cplusplus]: Now signed (which is how bool behaves).
(YYTRANSLATE): Avoid use of unsigned, and make the macro
safe even for values greater than UINT_MAX.
(yytnamerr, struct yyGLRState, struct yyGLRStateSet, struct yyGLRStack)
(yyaddDeferredAction, yyinitStateSet, yyinitGLRStack)
(yyexpandGLRStack, yymarkStackDeleted, yyremoveDeletes)
(yyglrShift, yyglrShiftDefer, yy_reduce_print, yydoAction)
(yyglrReduce, yysplitStack, yyreportTree, yycompressStack)
(yyprocessOneStack, yyreportSyntaxError, yyrecoverSyntaxError)
(yyparse, yy_yypstack, yypstack, yypdumpstack):
* tests/input.at (Torturing the Scanner):
Prefer ptrdiff_t to size_t.
* data/skeletons/c++.m4 (b4_yytranslate_define):
* src/AnnotationList.c (AnnotationList__computePredecessorAnnotations):
* src/AnnotationList.h (AnnotationIndex):
* src/InadequacyList.h (InadequacyListNodeCount):
* src/closure.c (closure_new):
* src/complain.c (error_message, complains, complain_indent)
(complain_args, duplicate_directive, duplicate_rule_directive):
* src/gram.c (nritems, ritem_print, grammar_dump):
* src/ielr.c (ielr_compute_ritem_sees_lookahead_set)
(ielr_item_has_lookahead, ielr_compute_annotation_lists)
(ielr_compute_lookaheads):
* src/location.c (columns, boundary_print, location_print):
* src/muscle-tab.c (muscle_percent_define_insert)
(muscle_percent_define_check_values):
* src/output.c (prepare_rules, prepare_actions):
* src/parse-gram.y (id, handle_require):
* src/reader.c (record_merge_function_type, packgram):
* src/reduce.c (nuseless_productions, nuseless_nonterminals)
(inaccessable_symbols):
* src/relation.c (relation_print):
* src/scan-code.l (variant, variant_table_size, variant_count)
(variant_add, get_at_spec, show_sub_message, show_sub_messages)
(parse_ref):
* src/scan-gram.l (<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>)
(scan_integer, convert_ucn_to_byte, handle_syncline):
* src/scan-skel.l (at_complain):
* src/symtab.c (complain_symbol_redeclared)
(complain_semantic_type_redeclared, complain_class_redeclared)
(symbol_class_set, complain_user_token_number_redeclared):
* src/tables.c (conflict_tos, conflrow, conflict_table)
(conflict_list, save_row, pack_vector):
* tests/local.at (AT_YYLEX_DEFINE(c)):
Prefer signed to unsigned integer.
* data/skeletons/lalr1.cc (yy_lac_check_):
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR):
* tests/local.at (AT_YYLEX_DEFINE(c)):
Omit now-unnecessary casts.
* data/skeletons/location.cc (b4_location_define):
* doc/bison.texi (Mfcalc Lexer, C++ position, C++ location):
Prefer int to unsigned for line and column numbers.
Change example to abort explicitly on memory exhaustion,
and fix an off-by-one bug that led to undefined behavior.
* data/skeletons/stack.hh (stack::operator[]):
Also allow ptrdiff_t indexes.
(stack::pop, slice::slice, slice::operator[]):
Index arg is now ptrdiff_t, not int.
(stack::ssize): New method.
(slice::range_): Now ptrdiff_t, not int.
* data/skeletons/yacc.c (b4_state_num_type): Remove.
All uses replaced by b4_int_type.
(YY_CONVERT_INT_BEGIN, YY_CONVERT_INT_END): New macros.
(yylac, yyparse): Use them around conversions that -Wconversion
would give false alarms about. 	Omit unnecessary casts.
(yy_stack_print): Use int rather than unsigned, and omit
a cast that doesn’t seem to be needed here any more.
* examples/c++/variant.yy (yylex):
* examples/c++/variant-11.yy (yylex):
Omit no-longer-needed conversions to unsigned.
* src/InadequacyList.c (InadequacyList__new_conflict):
Don’t assume *node_count is unsigned.
* src/output.c (muscle_insert_unsigned_table):
Remove; no longer used.
2019-10-02 17:11:33 -07:00
Akim Demaille
453639dfac git: update ignores 2019-09-22 07:48:10 +02:00
Akim Demaille
92124d27c1 d: remove useless imports
* examples/d/calc.y, tests/calc.at: here.
2019-08-29 07:26:33 -05:00
Akim Demaille
21aa4b2713 style: comment changes
* examples/c/lexcalc/local.mk, examples/c/reccalc/local.mk:
Here.
2019-06-27 07:57:21 +02:00
Akim Demaille
df77a98edf d: style changes
* data/skeletons/lalr1.d: here.
* examples/d/calc.y: Remove incorrect support for decimal numbers.
Formatting changes.
2019-06-20 06:57:27 +02:00
Akim Demaille
66ac4acc6c java: style changes
* data/skeletons/lalr1.java: Use more conventional function names for
Java.
Prefer < and <= to => and >.
Use the same approach for m4 quotation as in the other skeletons.
Fix indentation issues.

* tests/calc.at, tests/java.at, tests/javapush.at: Fix quotation style.
(main): Use 'args', not 'argv', the former seems more conventional and
is used elsewhere in Bison.
Prefer character literals to integers to denote characters.
* examples/java/Calc.y: Likewise.
2019-06-19 19:15:26 +02:00
Akim Demaille
1dcd6068dd tests: take SHELL into account
Reported by Dennis Clarke.
http://lists.gnu.org/archive/html/bug-bison/2019-05/msg00053.html

* examples/local.mk, tests/local.mk: here.
2019-05-26 15:29:37 +02:00
Akim Demaille
1934304acf examples: don't run those that require f?lex when it's not available
Reported by Bruno Haible.
http://lists.gnu.org/archive/html/bug-bison/2019-05/msg00026.html

* configure.ac (FLEX_WORKS): New.
* examples/c/lexcalc/local.mk, examples/c/reccalc/local.mk: Use it.
2019-05-19 18:41:59 +02:00
Akim Demaille
3ac95de01a examples: fix srcdir/builddir issues
* examples/d/local.mk, examples/java/local.mk: here.
2019-05-18 13:22:58 +02:00
Akim Demaille
3f25104caf build: do not use $< in plain rules
It works only in implicit rules (or with GNU Make, but not with
Solaris Make).

Reported by Bruno Haible.
http://lists.gnu.org/archive/html/bug-bison/2019-05/msg00009.html
Diagnosed thanks to Kiyoshi Kanazawa.

* examples/c/reccalc/local.mk, examples/d/local.mk,
* examples/java/local.mk: Don't use $< in non implicit rules.
2019-05-13 22:16:23 +02:00
Akim Demaille
02a1600994 package: add missing CLEANFILES
* examples: here.
2019-04-28 11:39:10 +02:00
Akim Demaille
0cc04eaa2a package: don't ship the sources generated from the parser
Because some of our examples use

    %C%_reccalc_SOURCES = %D%/parse.y

Automake ships parse.y and parse.c, and possibly parse.h when it
"understands" that there is one.  This is not what we want: ship only
parser.y.  Yet we still want to use Automake to compile the sources
from parser.y.  The easiest seems to use

    nodist_%C%_reccalc_SOURCES = %D%/parse.y

together with

    dist_reccalc_DATA = %D%/parse.y %D%/scan.l %D%/Makefile %D%/README.md

which guarantees that parse.y is indeed shipped.

* examples/c/calc/local.mk, examples/c/lexcalc/local.mk,
* examples/c/reccalc/local.mk: Always use nodist_*SOURCES for parsers,
let the dist_*_DATA rules do their job.
2019-04-28 11:39:10 +02:00
Akim Demaille
57290d63fd package: various fixes for syntax-check
* cfg.mk: Disable checks where needed (e.g., we do want to check the
behavior with tabs).
(sc_at_parser_check): Remove.  Unfortunately since
a11c144609 we no longer use the './'
prefix to run programs in the current directory.  That was so that we
could run Java programs like the other, although they are no run with
the `./` prefix (see 967a59d2c0).
As a consequence this sc check no longer makes sense.
However, since now AT_PARSER_CHECK passes the `./` prefix itself, this
sc-check was superfluous.
* examples/c/reccalc/scan.l: Use memcpy, not strncpy.
* src/ielr.c, src/reader.c: Obfuscate "lr(0)" so that the sc-check for
"space before paren" does not fire.
* tests/diagnostics.at: Avoid space-tab, use tab-tab.
2019-04-28 08:24:31 +02:00
Akim Demaille
4e19ab9fcd yacc.c: provide a means to include the header in the implementation
Currently when --defines is used, we generate a header, and paste an
exact copy of it into the generated parser implementation file.  Let's
provide a means to #include it instead.

We don't do it by default because of the Autotools' ylwrap.  This
program wraps invocations of yacc (that uses a fixed output name:
y.tab.c, y.tab.h, y.output) to support a more modern naming
scheme (dir/foo.y -> dir/foo.tab.c, dir/foo.tab.h, etc.).  It does
that by renaming the generated files, and then by running sed to
propagate these renamings inside the files themselves.

Unfortunately Automake's Makefiles uses Bison as if it were Yacc (with
--yacc or with -o y.tab.c) and invoke bison via ylwrap.  As a
consequence, as far as Bison is concerned, the output files are
y.tab.c and y.tab.h, so it emits '#include "y.tab.h"'.  So far, so
good.  But now ylwrap processes this '#include "y.tab.h"' into
'#include "dir/foo.tab.h"', which is not guaranteed to always work.

So, let's do the Right Thing when the output file is not y.tab.c, in
which case the user should %define api.header.include.  Binding this
behavior to --yacc is tempting, but we recently told people to stop
using --yacc (as it also enables the Yacc warnings), but rather to use
-o y.tab.c.

Yacc.c is the only skeleton concerned: all the others do include their
header.

* data/skeletons/yacc.c (b4_header_include_if): New.
(api.header.include): Provide a default value when the output is not
y.tab.c.
* src/parse-gram.y (api.header.include): Define.
2019-03-17 16:36:05 +01:00
Akim Demaille
bb0310a353 d: simplify the API to build the scanner of the example
* examples/d/calc.y (calcLexer): Add an overload for File.
Use it.
2019-03-02 09:56:41 +01:00
H. S. Teoh
f8408562f8 d: modernize the scanner of the example
https://lists.gnu.org/archive/html/bison-patches/2019-02/msg00121.html

* examples/d/calc.y (CalcLexer): Stop shoehorning C's API into D: use
a range based approach in the scanner, rather than some imitation of
getc/ungetc.
(main): Adjust.
2019-03-01 21:56:06 +01:00
Akim Demaille
b12f9c76e2 dlang: initial changes to run the calc tests on it
* configure.ac (DCFLAGS): Define.
* tests/atlocal.in: Receive it.
* data/skeletons/d.m4 (api.parser.class): Remove spurious YY.
* data/skeletons/lalr1.d (yylex): Return an int instead of a
YYTokenType, so that we can use characters as tokens.
* examples/d/calc.y: Adjust.
* tests/local.at: Initial support for D.
(AT_D_IF, AT_DATA_GRAMMAR(D), AT_YYERROR_DECLARE(d))
(AT_YYERROR_DECLARE_EXTERN(d), AT_YYERROR_DEFINE(d))
(AT_MAIN_DEFINE(d), AT_COMPILE_D, AT_LANG_COMPILE(d), AT_LANG_EXT(d)):
New.
* tests/calc.at: Initial support for D.
* tests/headers.at
2019-02-26 18:27:13 +01:00
Akim Demaille
575b814119 d: improve the example
* examples/d/calc.y: Exit with failure on errors.
Remove useless operators (=, !) meant for the test suite.
Add unary + for symmetry.
* examples/d/calc.test: Adjust expectations.
2019-02-26 08:42:24 +01:00
Akim Demaille
5230e610fc style: minor changes
* examples/c/calc/calc.y, src/lalr.c: Reduce scope.
* src/gram.c: Prefer < to >.
2019-02-24 19:08:01 +01:00
Akim Demaille
1e76448ced examples: remove stray examples
* examples/c/reentrant-calc: Remove.
I did not mean to include this example, it was replaced by
examples/c/reccalc.
2019-02-23 11:42:55 +01:00
Akim Demaille
6289d673a0 examples: add an example with a reentrant parser in Flex+Bison
Suggested by Eric S. Raymond.
https://lists.gnu.org/archive/html/bison-patches/2019-02/msg00066.html

* examples/c/reentrant-calc/Makefile, examples/c/reentrant-calc/README.md,
* examples/c/reentrant-calc/parse.y, examples/c/reentrant-calc/scan.l
* examples/c/reentrant-calc/lexcalc.test,
* examples/c/reentrant-calc/local.mk:
New.
2019-02-17 11:31:51 +01:00
Akim Demaille
0adda755a2 examples: fixes in lexcalc
* examples/c/lexcalc/parse.y: Formatting/comment changes.
(line): Don't return a value.
Print the result here, which avoids printing a value for lines with an
error.
(yyerror): Be sure to increment the pointed, not the pointer...
* examples/c/lexcalc/lexcalc.test: Check errors.
* examples/c/lexcalc/local.mk: Fix a dependency.
2019-02-16 16:51:15 +01:00
Akim Demaille
8cbf3ce22c examples: depend on Bison's sources
* examples/c/calc/local.mk, examples/c/lexcalc/local.mk,
* examples/c/mfcalc/local.mk, examples/c/rpcalc/local.mk:
Regenerate the files if dependencies have changed.
2019-02-12 06:19:10 +01:00
Akim Demaille
40fc688765 examples: add a simple infix calculator in C
Currently we have no simple example: rpcalc in reverse Polish, mfcalc
has functions, and lexcalc is using lex.

* examples/c/calc/Makefile, examples/c/calc/calc.y,
* examples/c/calc/calc.test, examples/c/calc/local.mk: New.
2019-02-10 17:44:23 +01:00
Akim Demaille
30f61b0549 examples: fix annoying off-by-one errors
* examples/extexi: Since we issue #lines only at the beginning of
@example, leave empty line when removing content (such as @comment
lines), otherwise the lines that follow have incorrect source line
location.  This leaves ugly empty lines, but they are removed when you
tidy the output for the end user: sequences of \n are mapped to at
most two sucessive \n.
2019-02-10 16:41:50 +01:00
Akim Demaille
76366e8e5c make: regenerate the example parsers when bison changes
* Makefile.am (dependencies): Also depend on Bison's sources.
2019-02-02 17:31:58 +01:00
Kiyoshi Kanazawa
83ebc8bdb6 tests: don't depend on the user's definition of SHELL
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00031.html

* examples/test (SHELL): Set it to /bin/sh.
2019-01-27 07:06:44 +01:00
Akim Demaille
3355ee32f0 style: formatting clean up
* data/skeletons/d.m4, examples/d/calc.y, src/output.c,
* src/parse-gram.y:
No tab, no trailing spaces.
Reported by syntax-check.
2019-01-12 09:41:10 +01:00
Akim Demaille
2471733f1a package: bump copyrights to 2019 2019-01-05 14:58:05 +01:00
Akim Demaille
c0c45cfa38 java/d: rename some %define variables for consistency
See 890ee8a1fd and
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00024.html.

* data/skeletons/d.m4, data/skeletons/java.m4
(abstract, annotations, extends, final, implements, public, strictfp):
Rename as...
(api.parser.abstract, api.parser.annotations, api.parser.extends)
(api.parser.final, api.parser.implements, api.parser.public)
(api.parser.strictfp):
these.

* src/muscle-tab.c (muscle_percent_variable_update): Ensure backward
compatibility.

* doc/bison.texi, examples/d/calc.y, examples/java/Calc.y,
tests/input.at: Adjust.
2019-01-05 12:28:55 +01:00
Akim Demaille
9ec93d4e34 examples: clean up the Java/D examples
* examples/java/Calc.y: Fix indentation.
Sort.
Don't use %name-prefix, since api.parser.class is already defined.
* examples/d/calc.y: Likewise.
2019-01-03 09:02:37 +01:00
Akim Demaille
890ee8a1fd rename parser_class_name as api.parser.class
The previous name was historical and inconsistent.

* src/muscle-tab.c (define_directive): Use the proper value passing
syntax, based on the muscle kind.
(muscle_percent_variable_update): Use the right value passing syntax.
Migrate from parser_class_name to api.parser.class.

* data/skeletons: Migrate from parser_class_name to api.parser.class.

* doc/bison.texi (%define Summary): Document both parser_class_name
and api.parser.class.
Promote the latter over the former.
2019-01-02 19:14:32 +01:00
Akim Demaille
50285ff066 examples: fix dependencies
Commit 112ccb5ed7 moved the skeletons
from dist_pkgdata_DATA to dist_skeletons_DATA, hence broke the dependencies.

* Makefile.am (dependencies): New.
Use it where appropriate.
2018-12-26 08:44:01 +01:00
Akim Demaille
afdefecab6 examples: simplify computation of yydebug
* examples/c/lexcalc/parse.y: here.
2018-12-11 06:53:25 +01:00
Akim Demaille
d657da9fb4 examples: add a simple Flex+Bison example in C
Suggested by Askar Safin.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00003.html

* examples/c/lexcalc/Makefile, examples/c/lexcalc/README.md,
* examples/c/lexcalc/lexcalc.test, examples/c/lexcalc/local.mk,
* examples/c/lexcalc/parse.y, examples/c/lexcalc/scan.l:
New.
2018-12-09 15:30:25 +01:00
Akim Demaille
85d303b713 examples: sort them per language and complete them
Convert some of the READMEs to Markdown, which is now more common, and
nicely displayed in some git hosting services.

Add missing READMEs and Makefiles.  Generate XML, HTML and Dot files.  Be
sure to ship the test files.  Complete CLEANFILES to remove all generated
files.

* examples/calc++: Move into...
* examples/c++: here.
* examples/mfcalc, examples/rpcalc: Move into...
* examples/c: here.

* examples/README.md, examples/c++/calc++/Makefile, examples/c/local.mk,
* examples/c/mfcalc/Makefile, examples/c/rpcalc/Makefile,
* examples/d/README.md, examples/java/README.md:
New files.

* examples/test (medir): Be robust to deeper directory nesting.
2018-12-09 13:55:05 +01:00
Akim Demaille
9a5c12f160 java, d: add a Makefile for the example
* examples/java/Makefile, examples/d/Makefile: New.
2018-12-06 05:19:09 +01:00
Akim Demaille
f15382f7d7 d: add an example
* examples/d/calc.test, examples/d/calc.y, examples/d/local.mk:
2018-12-04 20:43:01 +01:00
Akim Demaille
c20dd6279f examples: regenerate them when version.texi changes
When we extract the examples from the documentation, %require
"@value{VERSION}" is replaced with the current version.  If we change
the git branch, without changing the documentation, the generated
examples will %require a version of Bison that differs from the actual
version.

* examples/local.mk (extracted.stamp): Depend on doc/version.texi.
2018-12-04 08:36:52 +01:00
Akim Demaille
1a27d0bf28 java: make sure the build dir exists
* examples/java/local.mk (%D%/Calc.java): here.
2018-12-03 05:45:11 +01:00
Akim Demaille
d2386a35f5 java: add an example
* examples/java/Calc.y: New, based on test 495: "Calculator
parse.error=verbose %locations".
* examples/java/Calc.test, examples/java/local.mk: New.

* configure.ac (ENABLE_JAVA): New.
* examples/test (prog): Be ready to run Java programs.
2018-12-01 11:13:08 +01:00
Akim Demaille
cc050fd321 warning: avoid warnings about unreachable code
Reported by Uxio Prego.
https://lists.gnu.org/archive/html/help-bison/2018-11/msg00031.html

We also need to move the unreachable 'goto' to a reachable place,
otherwise clang complains about the code being unreachable anyway.
See also https://bugs.llvm.org/show_bug.cgi?id=39736.

Interestingly, we don't have to apply that trick to
`#define YYCDEBUG if (false) std::cerr`, clang does not warn when the
code comes from macro expansion.

* configure.ac: Use -Wunreachable-code when supported.
* data/lalr1.cc, data/yacc.c: Pacify clang's warning about `if (0)`
by using a macro.
Another possibility was to move this statement to a reachable place.
* tests/actions.at, tests/c++.at: Avoid generating unreachable code.
2018-11-25 11:22:31 +01:00
Akim Demaille
8ff6ff3ab0 examples: remove useless includes
* examples/c++/variant-11.yy, examples/c++/variant.yy: here.
Fix warning when storing a long into an int.
2018-11-13 06:53:21 +01:00