summaryrefslogtreecommitdiff
path: root/examples
Commit message (Collapse)AuthorAgeFilesLines
* examples: use markdown hyperlinksAkim Demaille2020-05-103-11/+11
| | | | | * examples/c++/README.md, examples/c++/calc++/README.md, * examples/c/README.md: here.
* style: minor fixesAkim Demaille2020-05-091-4/+4
| | | | * examples/c/README.md: here.
* examples: beware of portability issue on WindowsAkim Demaille2020-05-082-10/+26
| | | | | | | | | | | Reported by Jannick. https://lists.gnu.org/r/bug-bison/2020-05/msg00040.html https://lists.gnu.org/r/bug-bison/2020-05/msg00066.html * examples/test (diff_opts): Use --strip-trailing-cr if supported, to avoid \n vs. \r\n issues. * examples/c/bistromathic/bistromathic.test: When on MSYS, don't try to check autocompletion.
* all: fix the interface of yyexpected_tokensAkim Demaille2020-05-062-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* examples: fix handling of syntax errorsAkim Demaille2020-05-052-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The shell grammar does not allow empty statements in then/else part of an if, but examples/test failed to catch the syntax errors from the script it ran. So exited with success anyway. You would expect 'set -e' to suffice, but with bash 3.2 actually it does not. As a matter of fact, I could find a way to have this behave properly: $ cat test.sh set -e cleanup () { status=$? echo "cleanup: $status" exit $status } trap cleanup 0 1 2 13 15 . $1 s=$? echo "test.sh: $s" exit $s $ cat bistro.test if true; then fi $ /bin/sh ./test.sh ./bistro.test ./bistro.test: line 2: syntax error near unexpected token `fi' cleanup: 0 $ echo $? 0 Remove the set -e (or the trap), and tada, it works... So we have to deal with the error by hand. * examples/test ($exit): Replace with... ($status): this. Preserve the exit status of the test case. * examples/c/bistromathic/bistromathic.test: Fix syntax error.
* examples: beware of strnlen portability issuesAkim Demaille2020-05-041-1/+3
| | | | | | | | | | | | | | | | One function missing on Solaris 10 Sparc: CCLD examples/c/bistromathic/bistromathic Undefined first referenced symbol in file strnlen examples/c/bistromathic/bistromathic-parse.o ld: fatal: symbol referencing errors. No output written to examples/c/bistromathic/bistromathic Reported by Dagobert Michelsen. https://lists.gnu.org/r/bug-bison/2020-05/msg00048.html * examples/c/bistromathic/parse.y (xstrndup): Don't use strnlen. xstrndup is assembled from gnulib's xstrndup, strndup and strnlen...
* examples: beware of portability issues with sh's trapAkim Demaille2020-05-043-3/+16
| | | | | | | | | | | | | | On AIX 7.2, when invoking "exit 77", we actually exit with 127. The "cleanup" function, called via trap, received an incorrect exit status, something described in Autoconf's doc. Reported by Bruno Haible. https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00029.html https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00047.html * examples/test (skip): New. * examples/c/bistromathic/bistromathic.test, * examples/c/reccalc/reccalc.test: Use it, to ensure $? is set to 77 when the trap is called.
* bistromathic: beware of portability issues of readline on AIXAkim Demaille2020-05-031-4/+16
| | | | | | | | | Readline may emit escape sequences before the prompt. Reported by Bruno Haible. https://lists.gnu.org/r/platform-testers/2020-05/msg00001.html. * examples/c/bistromathic/bistromathic.test: Trust readline _only_ if we get what we expect on some reference computation.
* examples: beware of portability issues with cmpAkim Demaille2020-05-031-1/+1
| | | | | | | | | As someone wrote nearly 20 years ago in Autoconf's documentation, don't use cmp to compare text files, but diff. https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=abad4f0576a7dc361e5385e19c7681449103cdb1 Reported by Jannick. * examples/test: Use diff, not cmp.
* build: fix warnings (shown on IRIX)Akim Demaille2020-05-032-2/+2
| | | | | | | | | | | | Appearing on IRIX with gcc -mabi=n32. Reported by Bruno Haible. https://lists.gnu.org/r/bug-bison/2020-05/msg00039.html * examples/c++/variant-11.yy, examples/c/bistromathic/parse.y: Don't give chars to isdigit, cast them to unsigned char before. * src/complain.c: Use c_isdigit. * src/fixits.c (fixits_run): Avoid casts. * src/lalr.c (goto_print): Use %zu for a size_t.
* bistromathic: beware of portability issues with strndupAkim Demaille2020-05-031-8/+23
| | | | | | | | Reported by Dagobert Michelsen. https://lists.gnu.org/r/bug-bison/2020-05/msg00026.html * examples/c/bistromathic/parse.y (xstrndup): New. Use it.
* bistromathic: beware of portability of readlineAkim Demaille2020-05-032-11/+14
| | | | | | | | | | Don't try to build bistromathic if we don't have readline. Reported by Bruno Haible. https://lists.gnu.org/r/bug-bison/2020-05/msg00028.html * configure.ac (ENABLE_BISTROMATHIC): New. * examples/c/bistromathic/local.mk: Use it. * examples/c/bistromathic/bistromathic.test: Exit 77 for skip.
* tests: beware of portability issues of shAkim Demaille2020-05-031-1/+1
| | | | | | | | | "foo || bar" does not invoke bar on AIX 7.2 when foo does not exist. It just dies. Reported by Bruno Haible. https://lists.gnu.org/r/bug-bison/2020-05/msg00029.html * examples/c/reccalc/reccalc.test: Check for seq in a subshell.
* java: demonstrate push parsersAkim Demaille2020-05-032-14/+28
| | | | | | | | | * data/skeletons/lalr1.java (Location): Make it a static class. (Lexer.yylex, Lexer.getLVal, Lexer.getStartPos, Lexer.getEndPos): These are not needed in push parsers. * examples/java/calc/Calc.y: Demonstrate push parsers in the Java. * doc/bison.texi: Push parsers have been supported for a long time, remove incorrect statements stating the opposite.
* examples: beware of intl portability issuesAkim Demaille2020-05-032-2/+3
| | | | | | | | | Reported by Horst von Brand. https://lists.gnu.org/r/bug-bison/2020-04/msg00033.html * examples/c/bistromathic/Makefile: libintl might not be needed, but libm probably is. * examples/c/bistromathic/parse.y: Include locale.h.
* examples: beware of portability issues with readlineAkim Demaille2020-05-031-4/+22
| | | | | | | | | | On OpenBSD 6.5, the prompt is repeated, but not the actual command line... Don't try to cope with that. Reported by Bruno Haible. https://lists.gnu.org/r/bug-bison/2020-05/msg00015.html * examples/c/bistromathic/bistromathic.test: Skip when readline behave this way.
* examples: beware of the portability of flex --header-fileAkim Demaille2020-05-032-2/+4
| | | | | | | | | | | | | | The option --header was introduced in version 2.5.6. The option --header-file was introduced in version 2.6.4. Reported by Bruno Haible. https://lists.gnu.org/r/bug-bison/2020-05/msg00013.html So use --header, and do bother with versions that don't support it. * m4/flex.m4: Check whether flex supports --header. * configure.ac (FLEX_WORKS, FLEX_CXX_WORKS): Set to false if it doesn't. * * examples/c/reccalc/local.mk, examples/c/reccalc/Makefile: Use --header rather than --header-file.
* java: comment changesAkim Demaille2020-05-011-5/+20
| | | | * data/skeletons/lalr1.java, examples/java/calc/Calc.y: here.
* doc: document YYEOF, YYUNDEF and YYerrorAkim Demaille2020-04-291-3/+3
| | | | | * doc/bison.texi (Special Tokens): New. * examples/c/bistromathic/parse.y: Formatting changes.
* tests: beware of portability of readlineAkim Demaille2020-04-291-1/+2
| | | | * examples/test: here.
* java: clean up the definition of token kindsAkim Demaille2020-04-282-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From public interface Lexer { /* Token kinds. */ /** Token number, to be returned by the scanner. */ static final int YYEOF = 0; /** Token number, to be returned by the scanner. */ static final int YYERRCODE = 256; /** Token number, to be returned by the scanner. */ static final int YYUNDEF = 257; /** Token number, to be returned by the scanner. */ static final int BANG = 258; ... /** Deprecated, use b4_symbol(0, id) instead. */ public static final int EOF = YYEOF; to public interface Lexer { /* Token kinds. */ /** Token "end of file", to be returned by the scanner. */ static final int YYEOF = 0; /** Token error, to be returned by the scanner. */ static final int YYerror = 256; /** Token "invalid token", to be returned by the scanner. */ static final int YYUNDEF = 257; /** Token "!", to be returned by the scanner. */ static final int BANG = 258; ... /** Deprecated, use YYEOF instead. */ public static final int EOF = YYEOF; * data/skeletons/java.m4 (b4_token_enum): Display the symbol's tag in comment. * data/skeletons/lalr1.java: Address overquotation issue. * examples/java/calc/Calc.y, examples/java/simple/Calc.y: Use YYEOF, not EOF.
* error: rename the error token from YYERRCODE to YYerrorAkim Demaille2020-04-282-2/+2
| | | | | | | | | | | See https://lists.gnu.org/r/bison-patches/2020-04/msg00162.html. * data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.cc, * data/skeletons/lalr1.java, doc/bison.texi, * examples/c/bistromathic/parse.y, src/scan-gram.l, src/symtab.c (YYERRCODE): Rename as... (YYerror): this. Adjust dependencies.
* c: don't emit an error message when the scanner returns YYERRCODEAkim Demaille2020-04-263-16/+153
| | | | | | | | | | | | | | | | | | | * data/skeletons/yacc.c (yyparse): When the scanner returns YYERRCODE, go directly to error recovery (yyerrlab1). However, don't keep the error token as lookahead, that token is too special. * data/skeletons/lalr1.cc: Likewise. * examples/c/bistromathic/parse.y (yylex): Use that feature to report nicely invalid characters. * examples/c/bistromathic/bistromathic.test: Check that. * examples/test: Neutralize gratuitous differences such as rule position. * tests/calc.at: Check that case in C only. The other case seem to be working, but that's an illusion that the next commit will address (in fact, they can enter endless loops, and report the error several times anyway).
* examples: bistromathic: demonstrate error recoveryAkim Demaille2020-04-264-3/+21
| | | | | | * examples/c/bistromathic/parse.y: here. * examples/c/bistromathic/bistromathic.test: Check it. Included a stupid case where the error is actually ignored.
* examples: bistromathic: when quitting, close the current lineAkim Demaille2020-04-263-26/+45
| | | | | | | | | | | When the user ctrl-d the line, we left the cursor not at col 0. Let's fix that. This revealed a few short-comings in the testing framework. * examples/test (run): Also display the diffs. And support -n. * examples/c/bistromathic/bistromathic.test * examples/c/bistromathic/parse.y
* examples: bistromathic: comment changesAkim Demaille2020-04-261-1/+8
| | | | * examples/c/bistromathic/parse.y: here.
* style: minor fixesAkim Demaille2020-04-251-1/+0
| | | | | * data/skeletons/bison.m4, doc/bison.texi: Spell check. * examples/c/bistromathic/parse.y (N_): Remove, now useless.
* examples: bistromathic: shorten token descriptionAkim Demaille2020-04-242-8/+6
| | | | | * examples/c/bistromathic/parse.y: "number" is enough. * doc/bison.texi: Likewise.
* examples: bistromathic: demonstrate internationalizationAkim Demaille2020-04-245-38/+110
| | | | | | | | | | | | | | | | | | | | Currently it was only using stubs. Let's actually translate the strings using gettext. * examples/c/bistromathic/local.mk: Define LOCALEDIR, BISON_LOCALEDIR and link with libintl. * examples/c/bistromathic/parse.y: Use them. Remove useless includes. Take ENABLE_NLS into account. (error_format_string): New. (yyreport_syntax_error): Rewrite to rely on a format string, which is more appropriate for internationalization. * examples/c/bistromathic/Makefile: We no longer use Flex. We need readline and intl. * doc/bison.texi: Point to bistromathic for a better option for internationalization. * po/POTFILES.in: Add bistromathic.
* examples: beware of readline on macOSAkim Demaille2020-04-182-1/+31
| | | | | | | | | | macOS' version of readline does not repeat stdin on stdout in non-interactive mode, contrary to the current version of GNU readline. * examples/test: Add support for strip_prompt. * examples/c/bistromathic/bistromathic.test (strip_prompt): Set it when needed. Early exit when needed.
* examples: bistro: don't be lazy with switchAkim Demaille2020-04-141-30/+36
| | | | | * examples/c/bistromathic/parse.y (yylex): Use the switch to discriminate all the cases.
* doc: java: SymbolKind, etc.Akim Demaille2020-04-131-2/+2
| | | | | | | | | | | | | Why didn't I think about this before??? symbolName should be a method of SymbolKind. * data/skeletons/lalr1.java (YYParser::yysymbolName): Move as... * data/skeletons/java.m4 (SymbolKind::getName): this. Make the table a static final table, not a local variable. Adjust dependencies. * doc/bison.texi (Java Parser Interface): Document i18n. (Java Parser Context Interface): Document SymbolKind. * examples/java/calc/Calc.y, tests/local.at: Adjust.
* style: java: get closer to the Java styleAkim Demaille2020-04-132-143/+125
| | | | * examples/java/calc/Calc.y, examples/java/simple/Calc.y: here.
* doc: c++: document parser::contextAkim Demaille2020-04-131-1/+8
| | | | | | | | | | * doc/bison.texi (C++ Parser Context): New. * data/skeletons/lalr1.cc (parser::yysymbol_name): Rename as... (parser::symbol_name): this. (A Complete C++ Example): Promote LAC, now that we have it. Promote parse.error detailed over verbose. * examples/c++/calc++/calc++.test, tests/local.at: Adjust.
* d: put YYEMPTY in the TokenKindAkim Demaille2020-04-131-13/+11
| | | | | | | * data/skeletons/d.m4, data/skeletons/lalr1.d (b4_token_enums): Rename YYTokenType as TokenKind. Define YYEMPTY. * examples/d/calc.y, tests/calc.at, tests/scanner.at: Adjust.
* doc: promote yytoken_kind_t, not yytokentypeAkim Demaille2020-04-122-2/+2
| | | | | | | | | | | | | | | | * data/skeletons/c.m4 (yytoken_kind_t): New. * data/skeletons/c++.m4, data/skeletons/lalr1.cc (yysymbol_kind_type): New. * examples/c/lexcalc/parse.y, examples/c/reccalc/parse.y, * tests/regression.at: Use them. * doc/bison.texi: Replace "enum yytokentype" by "yytoken_kind_t". (api.token.raw): Explain that it forces "yytoken_kind_t" to coincide with "yysymbol_kind_t". (Calling Convention): Mention YYEOF. (Table of Symbols): Add entries for "yytoken_kind_t" and "yysymbol_kind_t". (Glossary): Add entries for "Kind", "Token kind" and "Symbol kind".
* c: rename yyexpected_tokens as yypcontext_expected_tokensAkim Demaille2020-04-121-1/+1
| | | | | | | | | | | | | | | | | The user should think of yypcontext fields as accessible only via yypcontext_* functions. So let's rename yyexpected_tokens to reflect that. Let's _not_ rename yyreport_syntax_error, as the user may define this function, and is not allowed to access directly the fields of yypcontext_t: she *must* use the "accessors". This is comparable to the case of C++/Java where the user defines parser::report_syntax_error, not parser::context::report_syntax_error. * data/skeletons/glr.c, data/skeletons/yacc.c (yyexpected_tokens): Rename as... (yypcontext_expected_tokens): this. Adjust dependencies.
* skeletons: make the eof token translatable if i18n is enabledAkim Demaille2020-04-121-2/+1
| | | | | | | | * src/output.c (has_translations): New. (prepare_symbol_names): Translate endtoken if the user already translated tokens. * examples/c/bistromathic/parse.y, src/parse-gram.y: Simplify.
* skeletons: use "end of file" instead of "$end"Akim Demaille2020-04-123-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | The name "$end" is nice in the report, in particular it avoids that pointed-rules (aka items) be too long. It also helps keeping them "standard". But it is bad in error messages, we should report "end of file" (or maybe "end of input", this is debatable). So, unless the user already defined the alias for the error token herself, make it "end of file". It should even be translated if the user already translated some tokens, so that there is now no strong reason to redefine the $end token. * src/output.c (prepare_symbol_names): Issue "end of file" instead of "$end". * data/skeletons/lalr1.java (yytnamerr_): Remove the renaming hack. * build-aux/update-test: Accept files with names containing a "+", such as c++.at. * tests/actions.at, tests/c++.at, tests/conflicts.at, * tests/glr-regression.at, tests/regression.at, tests/skeletons.at: Adjust.
* java: prefer null to YYSYMBOL_YYEMPTYAkim Demaille2020-04-061-1/+1
| | | | | | | | That's one nice benefit from using enums. * data/skeletons/lalr1.java (YYSYMBOL_YYEMPTY): No longer define it. Use 'null' instead. * examples/java/calc/Calc.y, tests/local.at: Adjust.
* java: rename Lexer.yyreportSyntaxError as reportSyntaxErrorAkim Demaille2020-04-061-1/+1
| | | | | * data/skeletons/lalr1.java: here. * examples/java/calc/Calc.y, tests/local.at: Adjust.
* java: use getExpectedTokens, not yyexpectedTokensAkim Demaille2020-04-061-1/+1
| | | | | * data/skeletons/lalr1.java, examples/java/calc/Calc.y, tests/local.at: here.
* bison: use consistently "token kind", not "token type"Akim Demaille2020-04-051-1/+1
| | | | * src/output.c, src/reader.c, src/scan-gram.l, src/tables.c: here.
* doc: refer to the token kind rather than the token typeAkim Demaille2020-04-051-1/+1
| | | | | | | * doc/bison.texi: Replace occurrences of "token type" with "token kind". Stop referring to the "macro definitions" of the token kinds, just name them "definitions".
* d, java: rename SymbolType as SymbolKindAkim Demaille2020-04-051-3/+3
| | | | | | | | | | See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html. * data/skeletons/d.m4, data/skeletons/lalr1.d, * data/skeletons/java.m4, data/skeletons/lalr1.java (SymbolType): Rename as... (SymbolKind): this. Adjust dependencies.
* c, c++: rename yysymbol_type_t as yysymbol_kind_tAkim Demaille2020-04-051-2/+2
| | | | | | | | | | | | | See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html * data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/yacc.c (yysymbol_type_t): Rename as... (yysymbol_kind_t): this. Adjust dependencies. * data/skeletons/c++.m4, data/skeletons/glr.cc, data/skeletons/lalr1.cc (symbol_type_type): Rename as... (symbol_kind_type): this. Adjust dependencies.
* Merge branch 'maint'Akim Demaille2020-04-051-1/+4
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * maint: maint: post-release administrivia version 3.5.4 examples: reccalc: really compile cleanly in C99 news: announce that Bison 3.6 drops YYERROR_VERBOSE news: update for 3.5.4 style: fix spellos typo: succesful -> successful package: improve the readme java: check and fix support for api.token.raw java: style: prefer 'int[] foo' to 'int foo[]' build: fix syntax-check issues tests: recheck: work properly when the test suite was interrupted doc: c++: promote api.token.raw build: fix compatibility with old compilers examples: reccalc: compile cleanly in C99
| * examples: reccalc: really compile cleanly in C99Akim Demaille2020-04-051-4/+4
| | | | | | | | | | | | | | | | | | | | | | The previous fix does not suffice, and actually managed to make things worse by defining yyscan_t twice in parse.y... Reported by kencu. https://trac.macports.org/ticket/59927#comment:29 * examples/c/reccalc/parse.y (yyscan_t): Define it with the same guards as used by Flex.
| * examples: reccalc: compile cleanly in C99Akim Demaille2020-04-021-0/+3
| | | | | | | | | | | | See https://trac.macports.org/ticket/59927. * examples/c/reccalc/parse.y: C99 does not allow multiple typedefs.
| * examples: use consistently the GFDL header for readmesAkim Demaille2020-03-066-53/+29
| | | | | | | | | | | | | | * examples/c++/README.md, examples/c++/calc++/README.md, * examples/c/calc/README.md, examples/c/lexcalc/README.md, * examples/c/reccalc/README.md: Prefer the GFDL banner to the GPL one.