Commit Graph

6887 Commits

Author SHA1 Message Date
Akim Demaille
b269a45fa4 examples: use consistently the GFDL header for readmes
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/calc/README.md, examples/c/lexcalc/README.md,
* examples/c/pushcalc/README.md, examples/c/reccalc/README.md:
Prefer the GFDL banner to the GPL one.
2020-03-01 07:56:02 +01:00
Akim Demaille
1478fccd23 gnulib: use readline 2020-03-01 06:23:49 +01:00
Akim Demaille
535281f0ff examples: bistromathic: don't use Flex
This example will soon use GNU readline, so its scanner should be easy
to use (concurrently) on strings, not streams.  This is not a place
where Flex shines, and anyway, these are examples of Bison, not Flex.
There's already lexcalc and reccalc that demonstrate the use of Flex.

* examples/c/bistromathic/scan.l: Remove.
* examples/c/bistromathic/parse.y (yylex): New.
Adjust dependencies.
2020-02-29 17:52:08 +01:00
Akim Demaille
c4a7e7a1ab examples: bistromathic: strengthen tests
* examples/c/bistromathic/bistromathic.test: here.
* examples/test: Be clearer on failing tests.
2020-02-29 12:22:31 +01:00
Akim Demaille
388e12ac0f examples: lexcalc: demonstrate location tracking
The bistromathic example should not use Flex, it makes it too complex.
But it was the only example to show location tracking with Flex.

* examples/c/lexcalc/lexcalc.test, examples/c/lexcalc/parse.y,
* examples/c/lexcalc/scan.l: Demonstrate location tracking as is done
in bistromathic.
2020-02-29 12:15:19 +01:00
Akim Demaille
b870d5fee4 c++: don't copy the lookahead
The current implementation of parser::context keeps a copy of the
lookahead.  This is troublesome since we support move-only types.
Besides, while GCC is happy with the current implementation, Clang
complains that the ctor it needs to build the copy of the lookahead is
not yet available.

    461. calc.at:1120: testing Calculator C++ %defines %locations parse.error=verbose %name-prefix "calc" %verbose  ...
    calc.at:1120: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -Wno-deprecated -o calc.cc calc.y
    calc.at:1120: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.cc calc-lex.cc calc-main.cc $LIBS
    stderr:
    In file included from calc-lex.cc:7:
    calc.hh:351:12: error: instantiation of function 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' required here, but no definition is available [-Werror,-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    calc.hh:273:7: note: forward declaration of template entity is here
          basic_symbol (const basic_symbol& that);
          ^
    calc.hh:351:12: note: add an explicit instantiation declaration to suppress this warning if 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' is explicitly instantiated in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 error generated.
    In file included from calc-main.cc:7:
    calc.hh:351:12: error: instantiation of function 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' required here, but no definition is available [-Werror,-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    calc.hh:273:7: note: forward declaration of template entity is here
          basic_symbol (const basic_symbol& that);
          ^
    calc.hh:351:12: note: add an explicit instantiation declaration to suppress this warning if 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' is explicitly instantiated in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 error generated.
    stdout:
    calc.at:1120: exit code was 1, expected 0
    461. calc.at:1120: 461. Calculator C++ %defines %locations parse.error=verbose %name-prefix "calc" %verbose  (calc.at:1120): FAILED (calc.at:1120)

* data/skeletons/lalr1.cc (context::yyla_): Make it a const-ref.
Move the implementation out of the declaration.
2020-02-27 21:49:56 +01:00
Akim Demaille
30d01b21e7 c++: minor fixes
Address compiler warnings such as

    warning: declaration of 'yyla' shadows a member of 'yy::parser::context' [-Wshadow]

* data/skeletons/lalr1.cc (context): Don't use the same names for
variables and members.
Use foo_ for private members, as in parser.
Also, use the + trick in array accesses to please ICC and provide it
with an int.
2020-02-27 21:31:09 +01:00
Adrian Vogelsgesang
c2cca46795 c++: add support for parse.error=custom
* data/skeletons/lalr1.cc: added support here
* tests/calc.at: added test cases
* tests/local.at: added yyreport_syntax_error implementation
   for C++ test cases
2020-02-27 18:13:44 +01:00
Adrian Vogelsgesang
879530cb95 c++: add parser::context for syntax error handling
* data/skeletons/lalr1.cc: here
2020-02-27 18:13:44 +01:00
Adrian Vogelsgesang
72acecb30c c++: add support for parse.error=detailed
* data/skeletons/lalr1.cc: added support here
* tests/calc.at: added a test case
2020-02-27 18:13:43 +01:00
Adrian Vogelsgesang
d4fcd5c3d0 skeletons: prefer b4_parse_error_{case,bmatch} over manual solution
Prefer b4_parse_error_case over the adhoc solution
`m4_case + b4_percent_define_get`. Same for b4_parse_error_bmatch.

* data/skeletons/glr.c: here
* data/skeletons/yacc.c: here
2020-02-27 18:13:43 +01:00
Adrian Vogelsgesang
368fcf0af5 typo: succesful -> successful
* data/skeletons/lalr1.cc: here
* etc/bench.pl.in: here
* src/location.c: here
* tests/calc.at: and here
2020-02-27 18:10:39 +01:00
Akim Demaille
6fe063da8f bench.pl: clean up the dust
* etc/bench.pl.in: Adjust to the current use of %define's values.
Don't use %error-verbose.
Prefer Bison to CPP (e.g., api.value.type).
Avoid returning characters directly, so that %define api.token.raw works.
2020-02-24 08:42:16 +01:00
Akim Demaille
296660304c style: comment changes
* src/symtab.h, src/lr0.c: here.
2020-02-23 08:25:53 +01:00
Akim Demaille
323731ff74 style: avoid using 'this' as an identifier
LLDB insists on parsing 'this' as a C++ keyword, even when debugging a
C program.

* src/symtab.c: Please the dictator.
2020-02-23 08:25:53 +01:00
Akim Demaille
6f7f949708 style: remove useless declarations
* src/reader.h: Don't duplicate what parse-gram.h already exposes.
* src/lr0.h: Remove useless include.
2020-02-23 08:25:53 +01:00
Akim Demaille
15e57d9108 examples: fix c/calc
* examples/c/calc/calc.y: Remove experiment traces.
2020-02-19 14:58:39 +01:00
Akim Demaille
30ba94081c todo: update 2020-02-19 14:57:17 +01:00
Akim Demaille
0e7bc7a6d8 doc: update recommandation for libtextstyle
* README: here.
2020-02-15 11:17:33 +01:00
Akimn Demaille
eff4d16175 build: fix typo
* build-aux/cross-options.pl: here.
2020-02-15 10:50:19 +01:00
Akim Demaille
b0e11f4523 doc: simplify the cross references
* doc/bison.texi: here.
2020-02-15 09:59:50 +01:00
Akim Demaille
d9b2270bed doc: document token internationalization
* doc/bison.texi (Parser Internationalization): Move most of its
content into...
(Enabling I18n): this new node.
(Token I18n): New.
(Token Decl): Refer to token internationalization.
(Error Reporting Function): Promote parse.error detailed.
2020-02-15 09:55:59 +01:00
Akim Demaille
7a28659495 regen 2020-02-15 08:28:57 +01:00
Victor Morales Cayuela
e09a72eeb0 diagnostics: modernize the display of submessages
Since Bison 2.7, output was indented four spaces for explanatory
statements.  For example:

    input.y:2.7-13: error: %type redeclaration for exp
    input.y:1.7-11:     previous declaration

Since the introduction of caret-diagnostics, it became less clear.
Remove the indentation and display submessages as in GCC:

    input.y:2.7-13: error: %type redeclaration for exp
        2 | %type <float> exp
          |       ^~~~~~~
    input.y:1.7-11: note: previous declaration
        1 | %type <int> exp
          |       ^~~~~

* src/complain.h (SUB_INDENT): Remove.
(warnings): Add "note" to the enum.
* src/complain.h, src/complain.c (complain_indent): Replace by...
(subcomplain): this.
Adjust all dependencies.
* tests/actions.at, tests/diagnostics.at, tests/glr-regression.at,
* tests/input.at, tests/named-refs.at, tests/regression.at:
Adjust expectations.
2020-02-15 08:28:40 +01:00
Akim Demaille
a09d0ae4d1 doc: simplify uses of references
This reverts "doc: work around problems with PDF generation", commit
d810aa3d8f.  Upstream issue is fixed.
https://lists.gnu.org/r/bug-texinfo/2020-02/msg00006.html

* gnulib: Update.
* doc/bison.texi: Simplify.
2020-02-13 19:22:51 +01:00
Akim Demaille
1e25cb44d1 java: provide a Context ctor
This is really a private auxiliary inner class, so it should not
matter.  But it's better style.

* data/skeletons/lalr1.java: here.
2020-02-13 19:22:10 +01:00
Akim Demaille
3ed42d2487 Merge tag 'v3.5.2'
bison 3.5.2

* tag 'v3.5.2':
  version 3.5.2
  news: 3.5.2
  gnulib: update
  doc: update Doxygen template
  java: avoid trailing white spaces
  m4: fix b4_token_format
  doc: clearly state that %yacc only makes sense with yacc.c
  doc: spell check
  examples: be more robust to spaces in paths
  larlr1.cc: Reject unsupported values for parse.lac
2020-02-13 19:19:11 +01:00
Akim Demaille
7f921d18dd version 3.5.2
* NEWS: Record release date.
v3.5.2
2020-02-13 18:25:21 +01:00
Akim Demaille
cc3760ef51 news: 3.5.2
* NEWS: Update.
2020-02-13 18:25:11 +01:00
Akim Demaille
2f23ca6f65 gnulib: update 2020-02-13 08:18:12 +01:00
Akim Demaille
468b68c5cd doc: update Doxygen template
* Doxyfile.in: Run doxygen -u on it.
2020-02-13 08:18:12 +01:00
Akim Demaille
9ed802a026 java: avoid trailing white spaces
* data/skeletons/java.m4 (b4_maybe_throws): Issue a space before when needed.
* data/skeletons/lalr1.java: Avoid trailing spaces.
2020-02-13 08:18:12 +01:00
Akim Demaille
fb554c2804 m4: fix b4_token_format
We used to emit:

    /** Token number,to be returned by the scanner.  */
    static final int NUM = 258;
    /** Token number,to be returned by the scanner.  */
    static final int NEG = 259;

with no space after the comma.  Fix that.

* data/skeletons/bison.m4 (b4_token_format): Quote where appropriate.
2020-02-13 08:18:11 +01:00
Akim Demaille
47850d4f58 doc: clearly state that %yacc only makes sense with yacc.c
* doc/bison.texi: here.
2020-02-13 08:18:11 +01:00
Akim Demaille
57b035a242 doc: spell check
* doc/bison.texi: here.
2020-02-13 08:18:11 +01:00
Akim Demaille
e7a202d762 examples: bistromathic: demonstrate named references
* examples/c/bistromathic/parse.y: here.
2020-02-12 00:18:47 +01:00
Akim Demaille
11e2b755f0 c++: simplify
* data/skeletons/stack.hh (ssize): Remove, same as size.
2020-02-12 00:09:15 +01:00
Akim Demaille
f3d33c3613 tests: check calls to yyerror from the user actions
This revealed a number of things I had not realized:

- the Java location tracking was aliasing the same pair of positions
  for all the symbols (see previous commit).

- in impure parsers, it's quite easy to use incorrect locations for
  diagnostics, since yyerror uses yylloc, which is the location of the
  lookahead, not that of the current lhs.  So we need something like

    {
      YYLTYPE old_yylloc = yylloc;
      yylloc = @$;
      yyerror (]AT_PARAM_IF([result, count, nerrs, ])[buf);
      yylloc = old_yylloc;
    }

  Maybe we should do that little yylloc dance in the skeleton instead
  of leaving it to the user?  It might be costly...  But that's only
  for users of the impure parsers, which are asking for trouble
  anyway.

- in glr.cc invoking yyerror is somewhat cumbersome: the C++ interface
  is not available as we are in yyparse (which in C), and yyerror is
  used by glr.cc itself to bind it to the user's parser::error.  If we
  call yyerror, we need:

    yyerror (]AT_LOCATION_IF([[&@$, ]])[yyparser, ]AT_PARAM_IF([result, count, nerrs, ])[msg);

  However calling yy::parser::error is easier, once we know that the
  current parser object is available as 'yyparser'.  Which also saves
  us from having to pass the parse-params ourselves:

    yyparser.error (]AT_LOCATION_IF([[@$, ]])[msg);

* tests/calc.at: Invoke yyerror by hand, instead of using fprintf etc.
Adjust expectations.
2020-02-12 00:00:05 +01:00
Akim Demaille
163a35d6dd java: beware not to alias the locations of the various symbols
* examples/java/calc/Calc.y, tests/calc.at, tests/local.at
(getStartPos, getEndPos): Always return a new object.
* doc/bison.texi: Clarify this.
2020-02-11 21:31:44 +01:00
Akim Demaille
cdb42f7730 java: check that parse.error custom|detailed work with push parsers
* tests/calc.at: here.
2020-02-11 08:39:08 +01:00
Akim Demaille
126252333d java: don't expose the Context's members
* data/skeletons/lalr1.java (Context): Make data members private.
(Context.getLocation): New.
* examples/java/calc/Calc.y, tests/java.at, tests/local.at: Adjust.
2020-02-11 08:39:03 +01:00
Akim Demaille
8637f2c7d6 build: pacify syntax-check
* src/complain.c: Fix indentation.
* cfg.mk: Using strcmp is ok in the tests.
Test cases and examples don't need Bison's PO support.
2020-02-10 20:46:56 +01:00
Akim Demaille
6946149701 regen 2020-02-10 20:42:23 +01:00
Akim Demaille
1368b9dbc9 gnulib: update 2020-02-10 20:42:23 +01:00
Akim Demaille
0e96eaf612 build: prefer %D% and %C% to hard coded values
* doc/local.mk: here.
2020-02-10 20:15:46 +01:00
Akim Demaille
77bdcc6f0c parse.error: document and diagnose the incompatibility with %token-table
* doc/bison.texi (Tokens from Literals): Move to code using
%token-table to...
(Decl Summary: %token-table): here.
* data/skeletons/bison.m4: Implement mutual exclusion.
* tests/input.at: Check it.
* doc/local.mk: Be robust to the removal of doc/.
2020-02-10 20:15:46 +01:00
Akim Demaille
57647bb656 doc: spell check
* doc/bison.texi: here.
2020-02-10 20:15:45 +01:00
Akim Demaille
63cd2918ff doc: formatting changes
* doc/bison.texi: here.
2020-02-10 20:15:45 +01:00
Akim Demaille
d810aa3d8f doc: work around problems with PDF generation
With texinfo.tex 2019-09-24.13, node names with + are not properly
handled.
https://lists.gnu.org/r/bug-texinfo/2020-02/msg00004.html

* doc/bison.texi: Always use the three-argument form for references to
node with a + in the name.
2020-02-10 20:15:41 +01:00
Akim Demaille
ed1eedbbcb java: revert "style: avoid useless initializers"
This reverts commit ebab1ffca8.
This commit removed "useless" initializers, going from

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
    private static final byte yypact_[] = yypact_init ();
    private static final byte[] yypact_init ()
    {
      return new byte[]
      {
        25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
        -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
        -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
         3,     3
      };
    }

to

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
    private static final byte[] yypact_ =
    {
        25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
        -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
        -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
         3,     3
    };

But it turns out that this was on purpose, to work around the 64KB
limitation in JVM methods.  It was introduced on the 2008-11-10 by
Di-an Jan in 09ccae9b18: "Work around
Java's ``code too large'' problem for parser tables".  See
https://lists.gnu.org/r/help-bison/2008-11/msg00004.html.  A real
test, where we would hit the JVM limitation, would be nice.

To avoid further regressions, add comments.
2020-02-10 07:34:07 +01:00