summaryrefslogtreecommitdiff
path: root/examples
Commit message (Collapse)AuthorAgeFilesLines
* tests: ignore messages from the JVMAkim Demaille2022-09-031-3/+6
| | | | | | | Reported by Giorgos Pap. <https://lists.gnu.org/r/bug-bison/2022-08/msg00002.html> * examples/test: Discard "Picked up _JAVA_OPTIONS:" messages.
* style: enforce GNU-style variable namesAkim Demaille2022-07-311-11/+11
| | | | | | * examples/c/glr/c++-types.y, tests/cxx-type.at (lineNum, colNum): Rename as... (line_num, col_num): these.
* doc: explain why location's "column" are defined vaguelyAkim Demaille2022-06-153-3/+42
| | | | | | | | | | | | | Suuggested by Frank Heckenbach. <https://lists.gnu.org/r/bug-bison/2022-01/msg00000.html> * doc/bison.texi (Location Type): Explain why location's "column" are defined vaguely. Show tab handling in ltcalc and calc++. * examples/c/bistromathic/parse.y: Show tab handling. * examples/c++/calc++/calc++.test, * examples/c/bistromathic/bistromathic.test: Check tab handling.
* package: bump copyrights to 2022Paul Eggert2022-01-1565-65/+65
| | | | Run "make update-copyright".
* tests: address portability issues about strdupAkim Demaille2021-11-062-0/+9
| | | | | | | | | | | | | Reported by Dennis Clarke <https://lists.gnu.org/r/bug-bison/2021-10/msg00005.html>. In particular <https://lists.gnu.org/r/bug-bison/2021-10/msg00023.html>. * doc/bison.texi, examples/c/glr/c++-types.y, * examples/c/bistromathic/parse.y tests/testsuite.h: Define _XOPEN_SOURCE to 600, to get a strdup that works on Solaris. * tests/glr-regression.at: Use strdup freely.
* examples: fix coding styleAkim Demaille2021-11-062-41/+38
| | | | | * examples/c/glr/c++-types.y: Use snake_case identifiers. Prefer strdup to malloc+strcpy.
* tests: make it easier to spot failuresAkim Demaille2021-10-091-11/+26
| | | | * examples/c/glr/c++-types.test: Split in several small test cases.
* c++: demonstrate custom error messages in the examplesAkim Demaille2021-09-125-6/+56
| | | | | | | | | | | Let's use c++/glr to demonstrate custom error messages in C++ (not just in glr2.cc). * examples/c++/glr/c++-types.yy (report_syntax_error): New. * examples/c++/glr/c++-types.test: Adjust. * examples/c/bistromathic/parse.y: Comment changes. * tests/local.at (AT_YYERROR_DEFINE(c++)): Use a nicer way to print the lookakead's name.
* style: rename stmtMerge as stmt_mergeAkim Demaille2021-08-292-13/+13
| | | | | | | Follow the GNU Coding Style. * doc/bison.texi, examples/c++/glr/c++-types.yy, * examples/c/glr/c++-types.y, tests/cxx-type.at: s/stmtMerge/stmt_merge/g.
* examples: don't demonstrate multistart, which is not part of 3.8Akim Demaille2021-08-193-55/+18
| | | | | | | | | Besides, for mysterious reasons, this fails on some environment. Reported by Dagobert Michelsen. <https://lists.gnu.org/archive/html/bug-bison/2021-08/msg00008.html> * examples/c/lexcalc/lexcalc.test, examples/c/lexcalc/parse.y, * examples/c/lexcalc/scan.l: Revert to a single-start example.
* bistromathic: beware of portability issues with readlineAkim Demaille2021-08-082-8/+22
| | | | | | | | | | | | | | | | | In some cases readline emits a trailing spaces after the last suggestion, which results in errors such as: ``` -( - atan cos exp ln number sin sqrt$ +( - atan cos exp ln number sin sqrt $ ``` Reported by Christopher Nielsen <mascguy@github.com>. <https://trac.macports.org/ticket/59927#comment:48> <https://trac.macports.org/attachment/ticket/59927/bison-3.7.6-test-10.13.test-suite.log> * examples/test (run): Add support for -t. * examples/c/bistromathic/bistromathic.test: Use it.
* examples: modernize the example MakefilesAkim Demaille2021-08-0415-98/+28
| | | | | | | | | | | | | | | | | * examples/c++/Makefile, examples/c++/calc++/Makefile, * examples/c++/glr/Makefile, examples/c/bistromathic/Makefile, * examples/c/calc/Makefile, examples/c/glr/Makefile, * examples/c/lexcalc/Makefile, examples/c/mfcalc/Makefile, * examples/c/pushcalc/Makefile, examples/c/reccalc/Makefile, * examples/c/rpcalc/Makefile, examples/d/calc/Makefile, * examples/d/simple/Makefile, examples/java/calc/Makefile, * examples/java/simple/Makefile: Use --html to generate *.html directly. No longer demonstrate --xml. No longer show rules for xml to html. Use --header, not --defines. Use --graph without specifying the output file now that we generate *.gv by default.
* d: minor clean upAkim Demaille2021-07-251-9/+6
| | | | | * doc/bison.texi: Use @samp, not "...", around pieces of code. * examples/d/calc/calc.y: Don't promote %union.
* d: demonstrate the token constructorsAdela Vais2021-06-061-9/+10
| | | | * examples/d/calc/calc.y: Use the token constructors in the 'calc' example.
* d: demonstrate the push parserAdela Vais2021-04-111-1/+5
| | | | | * examples/d/calc/calc.y: Use a parser of type 'push' in the calc example.
* examples: improve some function prototypesAkim Demaille2021-02-093-12/+12
| | | | | | | * examples/c/bistromathic/parse.y, examples/c/glr/c++-types.y, * examples/c/lexcalc/parse.y: Use const where appropriate. Avoid `yy` prefixes where it does not make sense. Avoid the `p` prefix for pointers.
* examples: use YYLOCATION_PRINTAkim Demaille2021-02-093-8/+8
| | | | | | * examples/c/bistromathic/parse.y, examples/c/glr/c++-types.y, * examples/c/lexcalc/parse.y: Don't use the private internal detail `YY_LOCATION_PRINT`, use `YYLOCATION_PRINT`.
* examples: do not rely on YY_LOCATION_PRINTAkim Demaille2021-02-091-0/+24
| | | | | * examples/c/bistromathic/parse.y (location_print): New. Use it.
* graph: output foo.gv by default, instead of *.dotAkim Demaille2021-02-021-1/+1
| | | | | | | | | | That change was started in Bison 3.4. The announcement for 3.7 stated that in Bison 3.8 we would use *.gv by default. * src/files.c (compute_output_file_names): spec_graph_file defaults too *.gv. * doc/bison.texi, examples/c++/calc++/local.mk, tests/output.at: Adjust.
* Update URLs to prefer https: to http:Paul Eggert2021-01-2952-52/+52
| | | | Also, fix a few http: URLs that were no longer working.
* tests: provide check-examples and check-testsAkim Demaille2021-01-271-0/+3
| | | | | | * examples/local.mk (check-examples): New. * tests/local.mk (check-tests): New. * README-hacking.md: Document them.
* bistromathic: use gettext for all the messagesAkim Demaille2021-01-271-2/+2
| | | | * examples/c/bistromathic/parse.y: Add missing calls to _.
* d: examples: reduce scopesAkim Demaille2021-01-171-10/+5
| | | | | | | | * data/skeletons/lalr1.d (YYLocation.step): New. * examples/d/calc/calc.y (Lexer): Reduce scopes to avoid uninitialized varibles. Factor the handling of locations. We don't need lenChars.
* d: examples: calc: remove Value from LexerAdela Vais2021-01-171-5/+4
| | | | | | | The Symbol constructor does not use it, so it is easier to not use Value at all. * examples/d/calc/calc.y: Here.
* d: examples: calc: use of std.conv.parse for locationAdela Vais2021-01-171-6/+20
| | | | | | | From Dlang v2.095.0 onwards, std.conv.parse reports the number of consumed characters. * examples/d/calc/calc.y: Here.
* d: examples: simple: fix styleAdela Vais2021-01-171-6/+6
| | | | * examples/d/simple/calc.y: Formatting changes.
* package: fixesAkim Demaille2021-01-162-3/+6
| | | | | | | * examples/c++/glr/local.mk, examples/c/glr/local.mk (CLEANFILES): Complete to fix distcheck. * src/output.c (merger_output): Obfuscate to pacify syntax-check's sc_space_before_open_paren.
* package: bump copyrights to 2021Akim Demaille2021-01-1665-65/+65
| | | | Run 'make update-copyright'.
* doc: spell checkAkim Demaille2021-01-164-6/+6
| | | | | | | | | | Gettext uses "catalog", not "catalogue". * doc/bison.texi, examples/c/README.md, * examples/c/bistromathic/Makefile, * examples/c/bistromathic/README.md, * examples/c/bistromathic/parse.y: Spell check.
* glr2.cc: add support for api.token.constructorAkim Demaille2021-01-102-56/+66
| | | | | | | * data/skeletons/glr2.cc: Add support for api.token.constructor. * examples/c++/glr/c++-types.yy: Use it. * examples/c++/glr/c++-types.test: Adjust expectations for error messages.
* glr2.cc: example: style changesAkim Demaille2021-01-101-9/+4
| | | | * examples/c++/glr/c++-types.yy: We need C++ 11 (we use shared_ptr).
* glr: examples: fix locationsAkim Demaille2021-01-104-20/+20
| | | | | | | | | | The locations are actually false: they should include the location of the semicolon (we print statements), but they don't. * examples/c++/glr/c++-types.test, examples/c++/glr/c++-types.yy, * examples/c/glr/c++-types.test, examples/c/glr/c++-types.y, * tests/cxx-type.at: Fix locations and adjust expectations.
* d: remove support for parse.error verboseAdela Vais2021-01-072-2/+2
| | | | | | | | | Without the history, D should not support this option. Before the removal, 'detailed' and 'verbose' options generated the same code. * data/skeletons/lalr1.d: Here. * doc/bison.texi: Adapt tests to use 'detailed' instead of 'verbose'. * tests/calc.at: Document it.
* d: add support for %printerAkim Demaille2021-01-071-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently we display the addresses of the semantic values. Instead, print the values. Add support for YY_USE across languages. * data/skeletons/c.m4, data/skeletons/d.m4 (b4_use): New. * data/skeletons/bison.m4 (b4_symbol_actions): Use b4_use to be portable to D. Add support for %printer, and use it. * data/skeletons/d.m4: Instead of duplicating what's already in c-like.m4, include it. (b4_symbol_action): New. Differs from the one in bison.m4 in that it uses yyval/yyloc instead of *yyvaluep and *yylocationp. * data/skeletons/lalr1.d (yy_symbol_print): Avoid calls to formatting, just call write directly. Use the %printer. * examples/d/calc/calc.y: Specify a printer. Enable traces when $YYDEBUG is set. * tests/calc.at: Fix the use of %printer with D.
* glr2.cc: add support for variantsAkim Demaille2021-01-051-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (Bison) Variants are extremely picky, which makes them both annoying (lots of micro-details must be taken care of) and precious (all the micro-details must be taken care of, in particular object lifetime). So (i) each time a semantic value is stored, it must be stored in a place that exists, and (ii) each time a semantic value is discarded, its place must have been emptied. Example of (i) - new (&yys.value ()) value_type (s->value ()); + {]b4_variant_if([[ + new (&yys.value ()) value_type (); + ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)], + [yys.value ()], [copy], [s->value ()])], [[ + new (&yys.value ()) value_type (s->value ());]])[ + } Example of (ii) yyparser.yy_destroy_ ("Error: discarding", - yytoken, &yylval]b4_locations_if([, &yylloc])[); + yytoken, &yylval]b4_locations_if([, &yylloc])[);]b4_variant_if([[ + // Value type destructor. + ]b4_symbol_variant([[YYTRANSLATE (this->yychar)]], [[yylval]], [[template destroy]])])[ this->yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, id)[; However, in some places we must not be "pure". In particular: glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW : is_state_ (other.is_state_) { std::memcpy (raw_, other.raw_, union_size); } still must use memcpy, because the constructor would change pred, and it must not. This constructor is used only when resizing the stack, in which case pred (which is relative) must not be "adjusted". The result works, but is messy. Its verbosity comes from at least two factors: - we don't have support for complete symbols (binding kind, value and location), and we should at least try to have it. That simplified lalr1.cc a lot. - I have not tried to be smart and use 'move' when possible. As a consequence many places have 'copy' and then 'destroy'. That kind of clean up can be done once everything appears to be solid. * data/skeletons/glr2.cc: Be more rigorous in object lifetime. In particular, don't forget to discard the lookahead when we're done with it. Call variant routines where needed. Deal with plenty of details. (b4_call_merger): Add support for variants. Use references in mergers, rather than pointers. * examples/c++/glr/c++-types.yy: Exercise variants.
* glr: example: flush the outputAkim Demaille2021-01-031-4/+6
| | | | | | * examples/c/glr/c++-types.y: Flush stdout so that the logs (on stderr) and the effective output (on stdout) mix correctly. While at it, be a bit more const-correct.
* glr.c: example: use a printerAkim Demaille2021-01-031-0/+2
| | | | * examples/c++/glr/c++-types.yy: Here.
* glr.c: example: use the exact same display as in the C++ exampleAkim Demaille2021-01-022-14/+14
| | | | | * examples/c/glr/c++-types.y: Add a space after the commas. * examples/c/glr/c++-types.test: Adjust expectations.
* glr.c: example: several improvementsAkim Demaille2021-01-023-61/+94
| | | | | | | | | * examples/c/glr/c++-types.y (node_print): New. Use YY_LOCATION_PRINT instead of duplicating it. And actually use it in the action instead of badly duplicating it. (main): Add proper option support. * examples/c/glr/c++-types.test: Adjust expectations on locations. * examples/c++/glr/c++-types.yy: Fix bad iteration.
* glr2.cc: the example requires Bison 3.8Akim Demaille2020-12-311-0/+1
| | | | | | | This will save us from generating the position.hh file. * src/parse-gram.y: Claim we are 3.8. * examples/c++/glr/c++-types.yy: Require 3.8.
* %merge: fix compatibility with api.value.type=unionAkim Demaille2020-12-311-11/+20
| | | | | | | | | | | Reported by Jot Dot. https://lists.gnu.org/r/help-bison/2020-12/msg00014.html * data/skeletons/glr.c, data/skeletons/glr2.cc (b4_call_merger): Use the symbol's slot, not its type. * examples/c/glr/c++-types.y: Use explicit per-symbol typing together with api.value.type=union. (yylex): Use yytoken_kind_t.
* glr2.cc: example: simplifyAkim Demaille2020-12-262-8/+5
| | | | | | * examples/c++/glr/c++-types.yy: Formatting changes. Remove unused support for '@'. * examples/c/glr/c++-types.y: Ditto.
* style: rename semanticVal as valueAkim Demaille2020-12-261-3/+3
| | | | | | | | * data/skeletons/README-D.txt: Remove, now useless and obsolete. * data/skeletons/glr2.cc, examples/d/calc/calc.y, * tests/calc.at, tests/d.at, tests/scanner.at (semanticVal): Replace with... (value): this.
* c++: rename semantic_type as value_typeAkim Demaille2020-12-261-6/+6
| | | | | | | | | | | | | | | We always refer to the triplet "kind, value, location". All of them are nouns, and we support api.value.type and api.location.type. On this regard, "semantic_type" was a poor choice. Make it "value_type". The test suite was not updated to use value_type, on purpose, to enforce backward compatibility. * data/skeletons/c++.m4, data/skeletons/glr.cc, data/skeletons/glr2.cc, * data/skeletons/variant.hh, doc/bison.texi: Define value_type rather than semantic_type. Add a backward compatibility typedef. * examples/c++/glr/c++-types.yy: Migrate.
* d: remove unnecessary methods from the Lexer interfaceAdela Vais2020-12-212-22/+0
| | | | | | | | | | | The complete symbol approach in yylex removes the need for the methods semanticVal, startPos and endPos, which were used when the values were reported separately. * data/skeletons/lalr1.d: Here. * doc/bison.texi: Remove sections about the three methods. * examples/d/calc/calc.y, examples/d/simple/calc.y: Remove the unused methods. * tests/calc.at, tests/d.at, tests/scanner.at: Test it.
* style: address syntax-check diagnosticsAkim Demaille2020-12-211-1/+0
| | | | | | | | * examples/c/glr/c++-types.y: Formatting changes. * po/POTFILES.in: Add missing files. * src/reader.c: Remove useless include. * tests/calc.at: Avoid magic values for exit. Obfuscate calls to error.
* d: create alias Position for YYPositionAdela Vais2020-12-211-2/+2
| | | | | | | | * data/skeletons/d.m4 (b4_public_types_declare): Here. * data/skeletons/lalr1.d: Adjust. * doc/bison.texi: Document it. * examples/d/calc/calc.y: Use it. * tests/calc.at: Test it.
* d: create alias Value for YYSemanticTypeAdela Vais2020-12-212-4/+4
| | | | | | * data/skeletons/d.m4: Here. * data/skeletons/lalr1.d, examples/d/calc/calc.y, examples/d/simple/calc.y: Adjust. * tests/calc.at, tests/d.at, tests/scanner.at: Test it.
* d: create alias Location for YYLocationAdela Vais2020-12-211-2/+2
| | | | | | | * data/skeletons/d.m4: Here. * doc/bison.texi: Document it. * examples/d/calc/calc.y: Adjust. * tests/calc.at: Test it.
* d: reduce verbosity for returning the location from yylex()Adela Vais2020-12-211-21/+20
| | | | | | | * examples/d/calc/calc.y (start, end): Replace by this... (location): new member variable in the Lexer class. Use it. * tests/calc.at: Use the defined location variable.