cex: update NEWS for 3.7
[bison.git] / TODO
blob59c08564111e574f78e655952cd64476a23fffd9
1 * Bison 3.7
2 ** Cex
3 *** Improve gnulib
4 Don't do this (counterexample.c):
6 // This is the fastest way to get the tail node from the gl_list API.
7 gl_list_node_t
8 list_get_end (gl_list_t list)
10   gl_list_node_t sentinel = gl_list_add_last (list, NULL);
11   gl_list_node_t res = gl_list_previous_node (list, sentinel);
12   gl_list_remove_node (list, sentinel);
13   return res;
16 *** Ambiguous rewriting
17 If the user is stupid enough to have equal rules, then the derivations are
18 harder to read:
20     Reduce/reduce conflict on tokens $end, "+", "⊕":
21         2 exp: exp "+" exp .
22         3 exp: exp "+" exp .
23       Example                  exp "+" exp •
24       First derivation         exp ::=[ exp "+" exp • ]
25       Example                  exp "+" exp •
26       Second derivation        exp ::=[ exp "+" exp • ]
28 Do we care about this?  In color, we use twice the same color here, but we
29 could try to use the same color for the same rule.
31 *** XML reports
32 Show the counterexamples.  This is going to be really hard and/or painful.
33 Unless we play it dumb (little structure).
35 ** Bistromathic
36 - How about not evaluating incomplete lines when the text is not finished
37   (as shells do).
39 ** Questions
40 *** Java
41 - Should i18n be part of the Lexer?  Currently it's a static method of
42   Lexer.
44 - is there a migration path that would allow to use TokenKinds in
45   yylex?
47 - define the tokens as an enum too.
49 - promote YYEOF rather than EOF.
51 *** D
52 - is there a way to attach yysymbol_name to the enum itself?  As we did
53   in Java.
55 - It would be better to have TokenKind as return value.  Can we use
56   reflection to support both output types?
58 ** YYerror
59 https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y;h=a712255af4f2f739c93336d4ff6556d932a426a5;hb=HEAD
61 should be updated to not use YYERRCODE.  Returning an undef token is good
62 enough.
64 ** Java
65 *** calc.at
66 Stop hard-coding "Calc".  Adjust local.at (look for FIXME).
68 ** A dev warning for b4_
69 Maybe we should check for m4_ and b4_ leaking out of the m4 processing, as
70 Autoconf does.  It would have caught overquotation issues.
72 ** doc
73 I feel it's ugly to use the GNU style to declare functions in the doc.  It
74 generates tons of white space in the page, and may contribute to bad page
75 breaks.
77 ** consistency
78 token vs terminal.
80 ** api.token.raw
81 The YYUNDEFTOK could be assigned a semantic value so that yyerror could be
82 used to report invalid lexemes.
84 ** push parsers
85 Consider deprecating impure push parsers.  They add a lot of complexity, for
86 a bad feature.  On the other hand, that would make it much harder to sit
87 push parsers on top of pull parser.  Which is currently not relevant, since
88 push parsers are measurably slower.
90 ** %define parse.error formatted
91 How about pushing bistromathics' yyreport_syntax_error as another standard
92 way to generate the error message, and leave to the user the task of
93 providing the message formats?  Currently in bistro, it reads:
95     const char *
96     error_format_string (int argc)
97     {
98       switch (argc)
99         {
100         default: /* Avoid compiler warnings. */
101         case 0: return _("%@: syntax error");
102         case 1: return _("%@: syntax error: unexpected %u");
103           // TRANSLATORS: '%@' is a location in a file, '%u' is an
104           // "unexpected token", and '%0e', '%1e'... are expected tokens
105           // at this point.
106           //
107           // For instance on the expression "1 + * 2", you'd get
108           //
109           // 1.5: syntax error: expected - or ( or number or function or variable before *
110         case 2: return _("%@: syntax error: expected %0e before %u");
111         case 3: return _("%@: syntax error: expected %0e or %1e before %u");
112         case 4: return _("%@: syntax error: expected %0e or %1e or %2e before %u");
113         case 5: return _("%@: syntax error: expected %0e or %1e or %2e or %3e before %u");
114         case 6: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e before %u");
115         case 7: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e before %u");
116         case 8: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e or %6e before %u");
117         }
118     }
120 The message would have to be generated in a string, and pushed to yyerror.
121 Which will be a pain in the neck in yacc.c.
123 If we want to do that, we should think very carefully about the syntax of
124 the format string.
126 ** yyclearin does not invoke the lookahead token's %destructor
127 https://lists.gnu.org/r/bug-bison/2018-02/msg00000.html
128 Rici:
130 > Modifying yyclearin so that it calls yydestruct seems like the simplest
131 > solution to this issue, but it is conceivable that such a change would
132 > break programs which already perform some kind of workaround in order to
133 > destruct the lookahead symbol. So it might be necessary to use some kind of
134 > compatibility %define, or to create a new replacement macro with a
135 > different name such as yydiscardin.
137 > At a minimum, the fact that yyclearin does not invoke the %destructor
138 > should be highlighted in the documentation, since it is not at all obvious.
140 ** Issues in i18n
142 Les catégories d'avertissements incluent :
143   conflicts-sr      conflits S/R (activé par défaut)
144   conflicts-rr      conflits R/R (activé par défaut)
145   dangling-alias    l'alias chaîne n'est pas attaché à un symbole
146   deprecated        construction obsolète
147   empty-rule        règle vide sans %empty
148   midrule-values    valeurs de règle intermédiaire non définies ou inutilisées
149   precedence        priorité et associativité inutiles
150   yacc              incompatibilités avec POSIX Yacc
151   other             tous les autres avertissements (activé par défaut)
152   all               tous les avertissements sauf « dangling-alias » et « yacc »
153   no-CATEGORY       désactiver les avertissements dans CATEGORIE
154   none              désactiver tous les avertissements
155   error[=CATEGORY]  traiter les avertissements comme des erreurs
157 Line -1 and -3 should mention CATEGORIE, not CATEGORY.
159 * Bison 3.8
160 ** Rewrite glr.cc
161 Get rid of scaffolding in glr.c.
163 ** Unit rules / Injection rules (Akim Demaille)
164 Maybe we could expand unit rules (or "injections", see
165 https://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html), i.e.,
166 transform
168         exp: arith | bool;
169         arith: exp '+' exp;
170         bool: exp '&' exp;
172 into
174         exp: exp '+' exp | exp '&' exp;
176 when there are no actions.  This can significantly speed up some grammars.
177 I can't find the papers.  In particular the book 'LR parsing: Theory and
178 Practice' is impossible to find, but according to 'Parsing Techniques: a
179 Practical Guide', it includes information about this issue.  Does anybody
180 have it?
182 ** clean up (Akim Demaille)
183 Do not work on these items now, as I (Akim) have branches with a lot of
184 changes in this area (hitting several files), and no desire to have to fix
185 conflicts.  Addressing these items will happen after my branches have been
186 merged.
188 *** lalr.c
189 Introduce a goto struct, and use it in place of from_state/to_state.
190 Rename states1 as path, length as pathlen.
191 Introduce inline functions for things such as nullable[*rp - ntokens]
192 where we need to map from symbol number to nterm number.
194 There are probably a significant part of the relations management that
195 should be migrated on top of a bitsetv.
197 *** closure
198 It should probably take a "state*" instead of two arguments.
200 *** traces
201 The "automaton" and "set" categories are not so useful.  We should probably
202 introduce lr(0) and lalr, just the way we have ielr categories.  The
203 "closure" function is too verbose, it should probably have its own category.
205 "set" can still be used for summariring the important sets.  That would make
206 tests easy to maintain.
208 *** complain.*
209 Rename these guys as "diagnostics.*" (or "diagnose.*"), since that's the
210 name they have in gcc, clang, etc.  Likewise for the complain_* series of
211 functions.
213 *** ritem
214 states/nstates, rules/nrules, ..., ritem/nritems
215 Fix the latter.
217 * Better error messages
218 The users are not provided with enough tools to forge their error messages.
219 See for instance "Is there an option to change the message produced by
220 YYERROR_VERBOSE?" by Simon Sobisch, on bison-help.
222 See also
223 https://www.cs.tufts.edu/~nr/cs257/archive/clinton-jefferey/lr-error-messages.pdf
224 https://research.swtch.com/yyerror
225 http://gallium.inria.fr/~fpottier/publis/fpottier-reachability-cc2016.pdf
227 * Modernization
228 Fix data/skeletons/yacc.c so that it defines YYPTRDIFF_T properly for modern
229 and older C++ compilers.  Currently the code defaults to defining it to
230 'long' for non-GCC compilers, but it should use the proper C++ magic to
231 define it to the same type as the C ptrdiff_t type.
233 * Completion
234 Several features are not available in all the backends.
236 - lac: D, Java (easy)
237 - push parsers: glr.c, glr.cc, lalr1.cc (not very difficult)
238 - token constructors: Java, C, D (a bit difficult)
239 - glr: D, Java (super difficult)
241 * Bugs
242 ** Autotest has quotation issues
243 tests/input.at:1730:AT_SETUP([%define errors])
247 $ ./tests/testsuite -l | grep errors | sed q
248   38: input.at:1730      errors
250 * Short term
251 ** Get rid of YYPRINT and b4_toknum
252 Besides yytoknum is wrong when api.token.raw is defined.
254 ** Better design for diagnostics
255 The current implementation of diagnostics is ad hoc, it grew organically.
256 It works as a series of calls to several functions, with dependency of the
257 latter calls on the former.  For instance:
259       complain (&sym->location,
260                 sym->content->status == needed ? complaint : Wother,
261                 _("symbol %s is used, but is not defined as a token"
262                   " and has no rules; did you mean %s?"),
263                 quote_n (0, sym->tag),
264                 quote_n (1, best->tag));
265       if (feature_flag & feature_caret)
266         location_caret_suggestion (sym->location, best->tag, stderr);
268 We should rewrite this in a more FP way:
270 1. build a rich structure that denotes the (complete) diagnostic.
271    "Complete" in the sense that it also contains the suggestions, the list
272    of possible matches, etc.
274 2. send this to the pretty-printing routine.  The diagnostic structure
275    should be sufficient so that we can generate all the 'format' of
276    diagnostics, including the fixits.
278 If properly done, this diagnostic module can be detached from Bison and be
279 put in gnulib.  It could be used, for instance, for errors caught by
280 xgettext.
282 There's certainly already something alike in GCC.  At least that's the
283 impression I get from reading the "-fdiagnostics-format=FORMAT" part of this
284 page:
286 https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html
288 ** Graphviz display code thoughts
289 The code for the --graph option is over two files: print_graph, and
290 graphviz. This is because Bison used to also produce VCG graphs, but since
291 this is no longer true, maybe we could consider these files for fusion.
293 An other consideration worth noting is that print_graph.c (correct me if I
294 am wrong) should contain generic functions, whereas graphviz.c and other
295 potential files should contain just the specific code for that output
296 format. It will probably prove difficult to tell if the implementation is
297 actually generic whilst only having support for a single format, but it
298 would be nice to keep stuff a bit tidier: right now, the construction of the
299 bitset used to show reductions is in the graphviz-specific code, and on the
300 opposite side we have some use of \l, which is graphviz-specific, in what
301 should be generic code.
303 Little effort seems to have been given to factoring these files and their
304 rint{,-xml} counterpart. We would very much like to re-use the pretty format
305 of states from .output for the graphs, etc.
307 Since graphviz dies on medium-to-big grammars, maybe consider an other tool?
309 ** push-parser
310 Check it too when checking the different kinds of parsers.  And be
311 sure to check that the initial-action is performed once per parsing.
313 ** m4 names
314 b4_shared_declarations is no longer what it is.  Make it
315 b4_parser_declaration for instance.
317 ** yychar in lalr1.cc
318 There is a large difference bw maint and master on the handling of
319 yychar (which was removed in lalr1.cc).  See what needs to be
320 back-ported.
323     /* User semantic actions sometimes alter yychar, and that requires
324        that yytoken be updated with the new translation.  We take the
325        approach of translating immediately before every use of yytoken.
326        One alternative is translating here after every semantic action,
327        but that translation would be missed if the semantic action
328        invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
329        yychar.  In the case of YYABORT or YYACCEPT, an incorrect
330        destructor might then be invoked immediately.  In the case of
331        YYERROR, subsequent parser actions might lead to an incorrect
332        destructor call or verbose syntax error message before the
333        lookahead is translated.  */
335     /* Make sure we have latest lookahead translation.  See comments at
336        user semantic actions for why this is necessary.  */
337     yytoken = yytranslate_ (yychar);
340 ** Get rid of fake #lines [Bison: ...]
341 Possibly as simple as checking whether the column number is nonnegative.
343 I have seen messages like the following from GCC.
345 <built-in>:0: fatal error: opening dependency file .deps/libltdl/argz.Tpo: No such file or directory
348 ** Discuss about %printer/%destroy in the case of C++.
349 It would be very nice to provide the symbol classes with an operator<<
350 and a destructor.  Unfortunately the syntax we have chosen for
351 %destroy and %printer make them hard to reuse.  For instance, the user
352 is invited to write something like
354    %printer { debug_stream() << $$; } <my_type>;
356 which is hard to reuse elsewhere since it wants to use
357 "debug_stream()" to find the stream to use.  The same applies to
358 %destroy: we told the user she could use the members of the Parser
359 class in the printers/destructors, which is not good for an operator<<
360 since it is no longer bound to a particular parser, it's just a
361 (standalone symbol).
363 * Various
364 ** Rewrite glr.cc in C++ (Valentin Tolmer)
365 As a matter of fact, it would be very interesting to see how much we can
366 share between lalr1.cc and glr.cc.  Most of the skeletons should be common.
367 It would be a very nice source of inspiration for the other languages.
369 Valentin Tolmer is working on this.
371 ** yychar == YYEMPTY
372 The code in yyerrlab reads:
374       if (yychar <= YYEOF)
375         {
376           /* Return failure if at end of input.  */
377           if (yychar == YYEOF)
378             YYABORT;
379         }
381 There are only two yychar that can be <= YYEOF: YYEMPTY and YYEOF.
382 But I can't produce the situation where yychar is YYEMPTY here, is it
383 really possible?  The test suite does not exercise this case.
385 This shows that it would be interesting to manage to install skeleton
386 coverage analysis to the test suite.
388 * From lalr1.cc to yacc.c
389 ** Single stack
390 Merging the three stacks in lalr1.cc simplified the code, prompted for
391 other improvements and also made it faster (probably because memory
392 management is performed once instead of three times).  I suggest that
393 we do the same in yacc.c.
395 (Some time later): it's also very nice to have three stacks: it's more dense
396 as we don't lose bits to padding.  For instance the typical stack for states
397 will use 8 bits, while it is likely to consume 32 bits in a struct.
399 We need trustworthy benchmarks for Bison, for all our backends.  Akim has a
400 few things scattered around; we need to put them in the repo, and make them
401 more useful.
403 * Report
405 ** Figures
406 Some statistics about the grammar and the parser would be useful,
407 especially when asking the user to send some information about the
408 grammars she is working on.  We should probably also include some
409 information about the variables (I'm not sure for instance we even
410 specify what LR variant was used).
412 ** GLR
413 How would Paul like to display the conflicted actions?  In particular,
414 what when two reductions are possible on a given lookahead token, but one is
415 part of $default.  Should we make the two reductions explicit, or just
416 keep $default?  See the following point.
418 ** Disabled Reductions
419 See 'tests/conflicts.at (Defaulted Conflicted Reduction)', and decide
420 what we want to do.
422 ** Documentation
423 Extend with error productions.  The hard part will probably be finding
424 the right rule so that a single state does not exhibit too many yet
425 undocumented ''features''.  Maybe an empty action ought to be
426 presented too.  Shall we try to make a single grammar with all these
427 features, or should we have several very small grammars?
429 * Extensions
430 ** More languages?
431 Well, only if there is really some demand for it.
433 *** PHP
434 https://github.com/scfc/bison-php/blob/master/data/lalr1.php
436 *** Python
437 https://lists.gnu.org/r/bison-patches/2013-09/msg00000.html and following
439 ** Multiple start symbols
440 Would be very useful when parsing closely related languages.  The idea is to
441 declare several start symbols, for instance
443     %start stmt expr
444     %%
445     stmt: ...
446     expr: ...
448 and to generate parse(), parse_stmt() and parse_expr().  Technically, the
449 above grammar would be transformed into
451    %start yy_start
452    %token YY_START_STMT YY_START_EXPR
453    %%
454    yy_start: YY_START_STMT stmt | YY_START_EXPR expr
456 so that there are no new conflicts in the grammar (as would undoubtedly
457 happen with yy_start: stmt | expr).  Then adjust the skeletons so that this
458 initial token (YY_START_STMT, YY_START_EXPR) be shifted first in the
459 corresponding parse function.
461 ** %include
462 This is a popular demand.  We already made many changes in the parser that
463 should make this reasonably easy to implement.
465 Bruce Mardle <marblypup@yahoo.co.uk>
466 https://lists.gnu.org/archive/html/bison-patches/2015-09/msg00000.html
468 However, there are many other things to do before having such a feature,
469 because I don't want a % equivalent to #include (which we all learned to
470 hate).  I want something that builds "modules" of grammars, and assembles
471 them together, paying attention to keep separate bits separated, in pseudo
472 name spaces.
474 ** Push parsers
475 There is demand for push parsers in Java and C++.  And GLR I guess.
477 ** Generate code instead of tables
478 This is certainly quite a lot of work.  See
479 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.50.4539.
481 ** $-1
482 We should find a means to provide an access to values deep in the
483 stack.  For instance, instead of
485         baz: qux { $$ = $<foo>-1 + $<bar>0 + $1; }
487 we should be able to have:
489   foo($foo) bar($bar) baz($bar): qux($qux) { $baz = $foo + $bar + $qux; }
491 Or something like this.
493 ** %if and the like
494 It should be possible to have %if/%else/%endif.  The implementation is
495 not clear: should it be lexical or syntactic.  Vadim Maslow thinks it
496 must be in the scanner: we must not parse what is in a switched off
497 part of %if.  Akim Demaille thinks it should be in the parser, so as
498 to avoid falling into another CPP mistake.
500 (Later): I'm sure there's actually good case for this.  People who need that
501 feature can use m4/cpp on top of Bison.  I don't think it is worth the
502 trouble in Bison itself.
504 ** XML Output
505 There are couple of available extensions of Bison targeting some XML
506 output.  Some day we should consider including them.  One issue is
507 that they seem to be quite orthogonal to the parsing technique, and
508 seem to depend mostly on the possibility to have some code triggered
509 for each reduction.  As a matter of fact, such hooks could also be
510 used to generate the yydebug traces.  Some generic scheme probably
511 exists in there.
513 XML output for GNU Bison and gcc
514    http://www.cs.may.ie/~jpower/Research/bisonXML/
516 XML output for GNU Bison
517    http://yaxx.sourceforge.net/
519 * Coding system independence
520 Paul notes:
522         Currently Bison assumes 8-bit bytes (i.e. that UCHAR_MAX is
523         255).  It also assumes that the 8-bit character encoding is
524         the same for the invocation of 'bison' as it is for the
525         invocation of 'cc', but this is not necessarily true when
526         people run bison on an ASCII host and then use cc on an EBCDIC
527         host.  I don't think these topics are worth our time
528         addressing (unless we find a gung-ho volunteer for EBCDIC or
529         PDP-10 ports :-) but they should probably be documented
530         somewhere.
532         More importantly, Bison does not currently allow NUL bytes in
533         tokens, either via escapes (e.g., "x\0y") or via a NUL byte in
534         the source code.  This should get fixed.
536 * Broken options?
537 ** %token-table
538 ** Skeleton strategy
539 Must we keep %token-table?
541 * Precedence
543 ** Partial order
544 It is unfortunate that there is a total order for precedence.  It
545 makes it impossible to have modular precedence information.  We should
546 move to partial orders (sounds like series/parallel orders to me).
548 This is a prerequisite for modules.
550 * Pre and post actions.
551 From: Florian Krohm <florian@edamail.fishkill.ibm.com>
552 Subject: YYACT_EPILOGUE
553 To: bug-bison@gnu.org
554 X-Sent: 1 week, 4 days, 14 hours, 38 minutes, 11 seconds ago
556 The other day I had the need for explicitly building the parse tree. I
557 used %locations for that and defined YYLLOC_DEFAULT to call a function
558 that returns the tree node for the production. Easy. But I also needed
559 to assign the S-attribute to the tree node. That cannot be done in
560 YYLLOC_DEFAULT, because it is invoked before the action is executed.
561 The way I solved this was to define a macro YYACT_EPILOGUE that would
562 be invoked after the action. For reasons of symmetry I also added
563 YYACT_PROLOGUE. Although I had no use for that I can envision how it
564 might come in handy for debugging purposes.
565 All is needed is to add
567 #if YYLSP_NEEDED
568     YYACT_EPILOGUE (yyval, (yyvsp - yylen), yylen, yyloc, (yylsp - yylen));
569 #else
570     YYACT_EPILOGUE (yyval, (yyvsp - yylen), yylen);
571 #endif
573 at the proper place to bison.simple. Ditto for YYACT_PROLOGUE.
575 I was wondering what you think about adding YYACT_PROLOGUE/EPILOGUE
576 to bison. If you're interested, I'll work on a patch.
578 * Better graphics
579 Equip the parser with a means to create the (visual) parse tree.
582 Local Variables:
583 mode: outline
584 coding: utf-8
585 fill-column: 76
586 End:
588 -----
590 Copyright (C) 2001-2004, 2006, 2008-2015, 2018-2020 Free Software
591 Foundation, Inc.
593 This file is part of Bison, the GNU Compiler Compiler.
595 Permission is granted to copy, distribute and/or modify this document
596 under the terms of the GNU Free Documentation License, Version 1.3 or
597 any later version published by the Free Software Foundation; with no
598 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
599 Texts.  A copy of the license is included in the "GNU Free
600 Documentation License" file as part of this distribution.