gnulib: update
[bison.git] / TODO
blob150d40721d8342043279e0dcecb15939afd25659
1 * Soon
2 ** POSIX updates
3 See the recent changes about function prototypes in POSIX Yacc.  Implement
4 them.
6 ** scan-code
7 The default case is scanning char-per-char.
9     /* By default, grow the string obstack with the input.  */
10     .|\n        STRING_GROW ();
12 make it more eager?
14 ** Missing tests
15 commit c22902e360e0fbbe9fd5657dcf107e03166da309
16 Author: Akim Demaille <akim.demaille@gmail.com>
17 Date:   Sat Jan 23 18:40:15 2021 +0100
19     tables: fix handling for useless tokens
21 See https://github.com/akimd/bison/issues/72#issuecomment-766153154
23 commit 2c294c132528ede23d8ae4959783a67e9ff05ac5
24 Author: Vincent Imbimbo <vmi6@cornell.edu>
25 Date:   Sat Jan 23 13:25:18 2021 -0500
27     cex: fix state-item pruning
29 See https://lists.gnu.org/r/bug-bison/2021-01/msg00002.html
31 ** pos_set_set
32 The current approach is correct, but with poor performances.  Bitsets need
33 to support 'assign' and 'shift'.  And instead of extending POS_SET just for
34 the out-of-range new values, we need something like doubling the size.
36 ** glr
37 There is no test with "Parse on stack %ld rejected by rule %d" in it.
39 ** yyrline etc.
40 Clarify that rule numbers in the skeletons are 1-based.
42 ** Macros in C++
43 There are many macros that should obey api.prefix: YY_CPLUSPLUS, YY_MOVE,
44 etc.
46 ** yyerrok in Java
47 And add tests in calc.at, to prepare work for D.
49 ** YYERROR and yynerrs
50 We are missing some cases.  Write a test case, and check all the skeletons.
52 ** Cex
53 *** Improve gnulib
54 Don't do this (counterexample.c):
56 // This is the fastest way to get the tail node from the gl_list API.
57 gl_list_node_t
58 list_get_end (gl_list_t list)
60   gl_list_node_t sentinel = gl_list_add_last (list, NULL);
61   gl_list_node_t res = gl_list_previous_node (list, sentinel);
62   gl_list_remove_node (list, sentinel);
63   return res;
66 *** Ambiguous rewriting
67 If the user is stupid enough to have equal rules, then the derivations are
68 harder to read:
70     Reduce/reduce conflict on tokens $end, "+", "⊕":
71         2 exp: exp "+" exp .
72         3 exp: exp "+" exp .
73       Example                  exp "+" exp •
74       First derivation         exp ::=[ exp "+" exp • ]
75       Example                  exp "+" exp •
76       Second derivation        exp ::=[ exp "+" exp • ]
78 Do we care about this?  In color, we use twice the same color here, but we
79 could try to use the same color for the same rule.
81 *** XML reports
82 Show the counterexamples.  This is going to be really hard and/or painful.
83 Unless we play it dumb (little structure).
85 ** Bistromathic
86 - How about not evaluating incomplete lines when the text is not finished
87   (as shells do).
89 ** Questions
90 *** Java
91 - Should i18n be part of the Lexer?  Currently it's a static method of
92   Lexer.
94 - is there a migration path that would allow to use TokenKinds in
95   yylex?
97 - define the tokens as an enum too.
99 - promote YYEOF rather than EOF.
101 ** YYerror
102 https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y;h=a712255af4f2f739c93336d4ff6556d932a426a5;hb=HEAD
104 should be updated to not use YYERRCODE.  Returning an undef token is good
105 enough.
107 ** Java
108 *** calc.at
109 Stop hard-coding "Calc".  Adjust local.at (look for FIXME).
111 ** doc
112 I feel it's ugly to use the GNU style to declare functions in the doc.  It
113 generates tons of white space in the page, and may contribute to bad page
114 breaks.
116 ** consistency
117 token vs terminal.
119 ** api.token.raw
120 The YYUNDEFTOK could be assigned a semantic value so that yyerror could be
121 used to report invalid lexemes.
123 ** push parsers
124 Consider deprecating impure push parsers.  They add a lot of complexity, for
125 a bad feature.  On the other hand, that would make it much harder to sit
126 push parsers on top of pull parser.  Which is currently not relevant, since
127 push parsers are measurably slower.
129 ** %define parse.error formatted
130 How about pushing Bistromathic's yyreport_syntax_error as another standard
131 way to generate the error message, and leave to the user the task of
132 providing the message formats?  Currently in bistro, it reads:
134     const char *
135     error_format_string (int argc)
136     {
137       switch (argc)
138         {
139         default: /* Avoid compiler warnings. */
140         case 0: return _("%@: syntax error");
141         case 1: return _("%@: syntax error: unexpected %u");
142           // TRANSLATORS: '%@' is a location in a file, '%u' is an
143           // "unexpected token", and '%0e', '%1e'... are expected tokens
144           // at this point.
145           //
146           // For instance on the expression "1 + * 2", you'd get
147           //
148           // 1.5: syntax error: expected - or ( or number or function or variable before *
149         case 2: return _("%@: syntax error: expected %0e before %u");
150         case 3: return _("%@: syntax error: expected %0e or %1e before %u");
151         case 4: return _("%@: syntax error: expected %0e or %1e or %2e before %u");
152         case 5: return _("%@: syntax error: expected %0e or %1e or %2e or %3e before %u");
153         case 6: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e before %u");
154         case 7: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e before %u");
155         case 8: return _("%@: syntax error: expected %0e or %1e or %2e or %3e or %4e or %5e or %6e before %u");
156         }
157     }
159 The message would have to be generated in a string, and pushed to yyerror.
160 Which will be a pain in the neck in yacc.c.
162 If we want to do that, we should think very carefully about the syntax of
163 the format string.
165 ** yyclearin does not invoke the lookahead token's %destructor
166 https://lists.gnu.org/r/bug-bison/2018-02/msg00000.html
167 Rici:
169 > Modifying yyclearin so that it calls yydestruct seems like the simplest
170 > solution to this issue, but it is conceivable that such a change would
171 > break programs which already perform some kind of workaround in order to
172 > destruct the lookahead symbol. So it might be necessary to use some kind of
173 > compatibility %define, or to create a new replacement macro with a
174 > different name such as yydiscardin.
176 > At a minimum, the fact that yyclearin does not invoke the %destructor
177 > should be highlighted in the documentation, since it is not at all obvious.
179 ** Issues in i18n
181 Les catégories d'avertissements incluent :
182   conflicts-sr      conflits S/R (activé par défaut)
183   conflicts-rr      conflits R/R (activé par défaut)
184   dangling-alias    l'alias chaîne n'est pas attaché à un symbole
185   deprecated        construction obsolète
186   empty-rule        règle vide sans %empty
187   midrule-values    valeurs de règle intermédiaire non définies ou inutilisées
188   precedence        priorité et associativité inutiles
189   yacc              incompatibilités avec POSIX Yacc
190   other             tous les autres avertissements (activé par défaut)
191   all               tous les avertissements sauf « dangling-alias » et « yacc »
192   no-CATEGORY       désactiver les avertissements dans CATEGORIE
193   none              désactiver tous les avertissements
194   error[=CATEGORY]  traiter les avertissements comme des erreurs
196 Line -1 and -3 should mention CATEGORIE, not CATEGORY.
198 * Bison 3.8
199 ** Rewrite glr.cc (currently glr2.cc)
200 *** Remove jumps
201 We can probably replace setjmp/longjmp with exceptions.  That would help
202 tremendously other languages such as D and Java that probably have no
203 similar feature.  If we remove jumps, we probably no longer need _Noreturn,
204 so simplify `b4_attribute_define([noreturn])` into `b4_attribute_define`.
206 After discussing with Valentin, it was decided that it's better to stay with
207 jumps, since in some places exceptions are ruled out from C++.
209 *** Coding style
210 Move to our coding conventions.  In particular names such as yy_glr_stack,
211 not yyGLRStack.
213 *** yydebug
214 It should be a member of the parser object, see lalr1.cc.  Let the parser
215 object decide what the debug stream is, rather than open coding std::cerr.
217 *** Avoid pointers
218 There are many places where pointers should be replaced with references.
219 Some occurrences were fixed, but now some have improper names:
221 -yygetToken (int *yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser][]b4_pure_if([, glr_stack* yystackp])[]b4_user_formals[)
222 +yygetToken (int& yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser][]b4_pure_if([, glr_stack* yystackp])[]b4_user_formals[)
224 yycharp is no longer a Pointer.  And yystackp should probably also be a reference.
226 *** parse.assert
227 Currently all the assertions are enabled.  Once we are confident in glr2.cc,
228 let parse.assert use the same approach as in lalr1.cc.
230 *** debug_stream
231 Stop using std::cerr everywhere.
233 *** glr.c
234 When glr2.cc fully replaces glr.cc, get rid of the glr.cc scaffolding in
235 glr.c.
237 * Chains
238 ** Unit rules / Injection rules (Akim Demaille)
239 Maybe we could expand unit rules (or "injections", see
240 https://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html), i.e.,
241 transform
243         exp: arith | bool;
244         arith: exp '+' exp;
245         bool: exp '&' exp;
247 into
249         exp: exp '+' exp | exp '&' exp;
251 when there are no actions.  This can significantly speed up some grammars.
252 I can't find the papers.  In particular the book 'LR parsing: Theory and
253 Practice' is impossible to find, but according to 'Parsing Techniques: a
254 Practical Guide', it includes information about this issue.  Does anybody
255 have it?
257 ** clean up (Akim Demaille)
258 Do not work on these items now, as I (Akim) have branches with a lot of
259 changes in this area (hitting several files), and no desire to have to fix
260 conflicts.  Addressing these items will happen after my branches have been
261 merged.
263 *** lalr.c
264 Introduce a goto struct, and use it in place of from_state/to_state.
265 Rename states1 as path, length as pathlen.
266 Introduce inline functions for things such as nullable[*rp - ntokens]
267 where we need to map from symbol number to nterm number.
269 There are probably a significant part of the relations management that
270 should be migrated on top of a bitsetv.
272 *** closure
273 It should probably take a "state*" instead of two arguments.
275 *** traces
276 The "automaton" and "set" categories are not so useful.  We should probably
277 introduce lr(0) and lalr, just the way we have ielr categories.  The
278 "closure" function is too verbose, it should probably have its own category.
280 "set" can still be used for summarizing the important sets.  That would make
281 tests easy to maintain.
283 *** complain.*
284 Rename these guys as "diagnostics.*" (or "diagnose.*"), since that's the
285 name they have in GCC, clang, etc.  Likewise for the complain_* series of
286 functions.
288 *** ritem
289 states/nstates, rules/nrules, ..., ritem/nritems
290 Fix the latter.
292 *** m4: slot, type, type_tag
293 The meaning of type_tag varies depending on api.value.type.  We should avoid
294 that and using clear definitions with stable semantics.
296 * D programming language
297 There's a number of features that are missing, here sorted in _suggested_
298 order of implementation.
300 When copying code from other skeletons, keep the comments exactly as they
301 are.  Keep the same variable names.  If you change the wording in one place,
302 do it in the others too.  In other words: make sure to keep the
303 maintenance *simple* by avoiding any gratuitous difference.
305 ** CI
306 Check when gdc and ldc.
308 ** GLR Parser
309 This is very ambitious.  That's the final boss.  There are currently no
310 "clean" implementation to get inspiration from.
312 glr.c is very clean but:
313 - is low-level C
314 - is a different skeleton from yacc.c
316 glr.cc is (currently) an ugly hack: a C++ shell around glr.c.  Valentin
317 Tolmer is currently rewriting glr.cc to be clean C++, but he is not
318 finished.  There will be a lot a common code between lalr1.cc and glr.cc, so
319 eventually I would like them to be fused into a single skeleton, supporting
320 both deterministic and generalized parsing.
322 It would be great for D to also support this.
324 The basic ideas of GLR are explained here:
326 https://www.codeproject.com/Articles/5259825/GLR-Parsing-in-Csharp-How-to-Use-The-Most-Powerful
328 * Better error messages
329 The users are not provided with enough tools to forge their error messages.
330 See for instance "Is there an option to change the message produced by
331 YYERROR_VERBOSE?" by Simon Sobisch, on bison-help.
333 See also
334 https://www.cs.tufts.edu/~nr/cs257/archive/clinton-jefferey/lr-error-messages.pdf
335 https://research.swtch.com/yyerror
336 http://gallium.inria.fr/~fpottier/publis/fpottier-reachability-cc2016.pdf
338 * Modernization
339 Fix data/skeletons/yacc.c so that it defines YYPTRDIFF_T properly for modern
340 and older C++ compilers.  Currently the code defaults to defining it to
341 'long' for non-GCC compilers, but it should use the proper C++ magic to
342 define it to the same type as the C ptrdiff_t type.
344 * Completion
345 Several features are not available in all the back-ends.
347 - push parsers: glr.c, glr.cc, lalr1.cc (not very difficult)
348 - token constructors: Java, C, D (a bit difficult)
349 - glr: D, Java (super difficult)
351 * Bugs
352 ** Autotest has quotation issues
353 tests/input.at:1730:AT_SETUP([%define errors])
357 $ ./tests/testsuite -l | grep errors | sed q
358   38: input.at:1730      errors
360 * Short term
361 ** Better design for diagnostics
362 The current implementation of diagnostics is ad hoc, it grew organically.
363 It works as a series of calls to several functions, with dependency of the
364 latter calls on the former.  For instance:
366       complain (&sym->location,
367                 sym->content->status == needed ? complaint : Wother,
368                 _("symbol %s is used, but is not defined as a token"
369                   " and has no rules; did you mean %s?"),
370                 quote_n (0, sym->tag),
371                 quote_n (1, best->tag));
372       if (feature_flag & feature_caret)
373         location_caret_suggestion (sym->location, best->tag, stderr);
375 We should rewrite this in a more FP way:
377 1. build a rich structure that denotes the (complete) diagnostic.
378    "Complete" in the sense that it also contains the suggestions, the list
379    of possible matches, etc.
381 2. send this to the pretty-printing routine.  The diagnostic structure
382    should be sufficient so that we can generate all the 'format' of
383    diagnostics, including the fixits.
385 If properly done, this diagnostic module can be detached from Bison and be
386 put in gnulib.  It could be used, for instance, for errors caught by
387 xgettext.
389 There's certainly already something alike in GCC.  At least that's the
390 impression I get from reading the "-fdiagnostics-format=FORMAT" part of this
391 page:
393 https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html
395 ** Graphviz display code thoughts
396 The code for the --graph option is over two files: print_graph, and
397 graphviz. This is because Bison used to also produce VCG graphs, but since
398 this is no longer true, maybe we could consider these files for fusion.
400 An other consideration worth noting is that print_graph.c (correct me if I
401 am wrong) should contain generic functions, whereas graphviz.c and other
402 potential files should contain just the specific code for that output
403 format. It will probably prove difficult to tell if the implementation is
404 actually generic whilst only having support for a single format, but it
405 would be nice to keep stuff a bit tidier: right now, the construction of the
406 bitset used to show reductions is in the graphviz-specific code, and on the
407 opposite side we have some use of \l, which is graphviz-specific, in what
408 should be generic code.
410 Little effort seems to have been given to factoring these files and their
411 print{,-xml} counterpart. We would very much like to re-use the pretty format
412 of states from .output for the graphs, etc.
414 Since graphviz dies on medium-to-big grammars, maybe consider an other tool?
416 ** push-parser
417 Check it too when checking the different kinds of parsers.  And be
418 sure to check that the initial-action is performed once per parsing.
420 ** m4 names
421 b4_shared_declarations is no longer what it is.  Make it
422 b4_parser_declaration for instance.
424 ** yychar in lalr1.cc
425 There is a large difference bw maint and master on the handling of
426 yychar (which was removed in lalr1.cc).  See what needs to be
427 back-ported.
430     /* User semantic actions sometimes alter yychar, and that requires
431        that yytoken be updated with the new translation.  We take the
432        approach of translating immediately before every use of yytoken.
433        One alternative is translating here after every semantic action,
434        but that translation would be missed if the semantic action
435        invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
436        yychar.  In the case of YYABORT or YYACCEPT, an incorrect
437        destructor might then be invoked immediately.  In the case of
438        YYERROR, subsequent parser actions might lead to an incorrect
439        destructor call or verbose syntax error message before the
440        lookahead is translated.  */
442     /* Make sure we have latest lookahead translation.  See comments at
443        user semantic actions for why this is necessary.  */
444     yytoken = yytranslate_ (yychar);
447 ** Get rid of fake #lines [Bison: ...]
448 Possibly as simple as checking whether the column number is nonnegative.
450 I have seen messages like the following from GCC.
452 <built-in>:0: fatal error: opening dependency file .deps/libltdl/argz.Tpo: No such file or directory
455 ** Discuss about %printer/%destroy in the case of C++.
456 It would be very nice to provide the symbol classes with an operator<<
457 and a destructor.  Unfortunately the syntax we have chosen for
458 %destroy and %printer make them hard to reuse.  For instance, the user
459 is invited to write something like
461    %printer { debug_stream() << $$; } <my_type>;
463 which is hard to reuse elsewhere since it wants to use
464 "debug_stream()" to find the stream to use.  The same applies to
465 %destroy: we told the user she could use the members of the Parser
466 class in the printers/destructors, which is not good for an operator<<
467 since it is no longer bound to a particular parser, it's just a
468 (standalone symbol).
470 * Various
471 ** Rewrite glr.cc in C++ (Valentin Tolmer)
472 As a matter of fact, it would be very interesting to see how much we can
473 share between lalr1.cc and glr.cc.  Most of the skeletons should be common.
474 It would be a very nice source of inspiration for the other languages.
476 Valentin Tolmer is working on this.
478 * From lalr1.cc to yacc.c
479 ** Single stack
480 Merging the three stacks in lalr1.cc simplified the code, prompted for
481 other improvements and also made it faster (probably because memory
482 management is performed once instead of three times).  I suggest that
483 we do the same in yacc.c.
485 (Some time later): it's also very nice to have three stacks: it's more dense
486 as we don't lose bits to padding.  For instance the typical stack for states
487 will use 8 bits, while it is likely to consume 32 bits in a struct.
489 We need trustworthy benchmarks for Bison, for all our backends.  Akim has a
490 few things scattered around; we need to put them in the repo, and make them
491 more useful.
493 * Report
495 ** Figures
496 Some statistics about the grammar and the parser would be useful,
497 especially when asking the user to send some information about the
498 grammars she is working on.  We should probably also include some
499 information about the variables (I'm not sure for instance we even
500 specify what LR variant was used).
502 ** GLR
503 How would Paul like to display the conflicted actions?  In particular,
504 what when two reductions are possible on a given lookahead token, but one is
505 part of $default.  Should we make the two reductions explicit, or just
506 keep $default?  See the following point.
508 ** Disabled Reductions
509 See 'tests/conflicts.at (Defaulted Conflicted Reduction)', and decide
510 what we want to do.
512 ** Documentation
513 Extend with error productions.  The hard part will probably be finding
514 the right rule so that a single state does not exhibit too many yet
515 undocumented ''features''.  Maybe an empty action ought to be
516 presented too.  Shall we try to make a single grammar with all these
517 features, or should we have several very small grammars?
519 * Extensions
520 ** More languages?
521 Well, only if there is really some demand for it.
523 *** PHP
524 https://github.com/scfc/bison-php/blob/master/data/lalr1.php
526 *** Python
527 https://lists.gnu.org/r/bison-patches/2013-09/msg00000.html and following
529 ** Multiple start symbols
530 Would be very useful when parsing closely related languages.  The idea is to
531 declare several start symbols, for instance
533     %start stmt expr
534     %%
535     stmt: ...
536     expr: ...
538 and to generate parse(), parse_stmt() and parse_expr().  Technically, the
539 above grammar would be transformed into
541    %start yy_start
542    %token YY_START_STMT YY_START_EXPR
543    %%
544    yy_start: YY_START_STMT stmt | YY_START_EXPR expr
546 so that there are no new conflicts in the grammar (as would undoubtedly
547 happen with yy_start: stmt | expr).  Then adjust the skeletons so that this
548 initial token (YY_START_STMT, YY_START_EXPR) be shifted first in the
549 corresponding parse function.
551 *** Number of useless symbols
552 AT_TEST(
553 [[%start exp;
554 exp: exp;]],
555 [[input.y: warning: 2 nonterminals useless in grammar [-Wother]
556 input.y: warning: 2 rules useless in grammar [-Wother]
557 input.y:2.8-10: error: start symbol exp does not derive any sentence]])
559 We should say "1 nonterminal": the other one is $accept, which should not
560 participate in the count.
562 *** Tokens
563 Do we want to disallow terminal start symbols?  The limitation is not
564 technical.  Can it be useful to someone to "parse" a token?
566 ** %include
567 This is a popular demand.  We already made many changes in the parser that
568 should make this reasonably easy to implement.
570 Bruce Mardle <marblypup@yahoo.co.uk>
571 https://lists.gnu.org/r/bison-patches/2015-09/msg00000.html
573 However, there are many other things to do before having such a feature,
574 because I don't want a % equivalent to #include (which we all learned to
575 hate).  I want something that builds "modules" of grammars, and assembles
576 them together, paying attention to keep separate bits separated, in pseudo
577 name spaces.
579 ** Push parsers
580 There is demand for push parsers in C++.
582 ** Generate code instead of tables
583 This is certainly quite a lot of work.  See
584 https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.50.4539.
586 ** $-1
587 We should find a means to provide an access to values deep in the
588 stack.  For instance, instead of
590         baz: qux { $$ = $<foo>-1 + $<bar>0 + $1; }
592 we should be able to have:
594   foo($foo) bar($bar) baz($bar): qux($qux) { $baz = $foo + $bar + $qux; }
596 Or something like this.
598 ** %if and the like
599 It should be possible to have %if/%else/%endif.  The implementation is
600 not clear: should it be lexical or syntactic.  Vadim Maslow thinks it
601 must be in the scanner: we must not parse what is in a switched off
602 part of %if.  Akim Demaille thinks it should be in the parser, so as
603 to avoid falling into another CPP mistake.
605 (Later): I'm sure there's actually good case for this.  People who need that
606 feature can use m4/cpp on top of Bison.  I don't think it is worth the
607 trouble in Bison itself.
609 ** XML Output
610 There are couple of available extensions of Bison targeting some XML
611 output.  Some day we should consider including them.  One issue is
612 that they seem to be quite orthogonal to the parsing technique, and
613 seem to depend mostly on the possibility to have some code triggered
614 for each reduction.  As a matter of fact, such hooks could also be
615 used to generate the yydebug traces.  Some generic scheme probably
616 exists in there.
618 XML output for GNU Bison and gcc
619    http://www.cs.may.ie/~jpower/Research/bisonXML/
621 XML output for GNU Bison
622    http://yaxx.sourceforge.net/
624 * Coding system independence
625 Paul notes:
627         Currently Bison assumes 8-bit bytes (i.e. that UCHAR_MAX is
628         255).  It also assumes that the 8-bit character encoding is
629         the same for the invocation of 'bison' as it is for the
630         invocation of 'cc', but this is not necessarily true when
631         people run bison on an ASCII host and then use cc on an EBCDIC
632         host.  I don't think these topics are worth our time
633         addressing (unless we find a gung-ho volunteer for EBCDIC or
634         PDP-10 ports :-) but they should probably be documented
635         somewhere.
637         More importantly, Bison does not currently allow NUL bytes in
638         tokens, either via escapes (e.g., "x\0y") or via a NUL byte in
639         the source code.  This should get fixed.
641 * Broken options?
642 ** %token-table
643 ** Skeleton strategy
644 Must we keep %token-table?
646 * Precedence
648 ** Partial order
649 It is unfortunate that there is a total order for precedence.  It
650 makes it impossible to have modular precedence information.  We should
651 move to partial orders (sounds like series/parallel orders to me).
653 This is a prerequisite for modules.
655 * Pre and post actions.
656 From: Florian Krohm <florian@edamail.fishkill.ibm.com>
657 Subject: YYACT_EPILOGUE
658 To: bug-bison@gnu.org
659 X-Sent: 1 week, 4 days, 14 hours, 38 minutes, 11 seconds ago
661 The other day I had the need for explicitly building the parse tree. I
662 used %locations for that and defined YYLLOC_DEFAULT to call a function
663 that returns the tree node for the production. Easy. But I also needed
664 to assign the S-attribute to the tree node. That cannot be done in
665 YYLLOC_DEFAULT, because it is invoked before the action is executed.
666 The way I solved this was to define a macro YYACT_EPILOGUE that would
667 be invoked after the action. For reasons of symmetry I also added
668 YYACT_PROLOGUE. Although I had no use for that I can envision how it
669 might come in handy for debugging purposes.
670 All is needed is to add
672 #if YYLSP_NEEDED
673     YYACT_EPILOGUE (yyval, (yyvsp - yylen), yylen, yyloc, (yylsp - yylen));
674 #else
675     YYACT_EPILOGUE (yyval, (yyvsp - yylen), yylen);
676 #endif
678 at the proper place to bison.simple. Ditto for YYACT_PROLOGUE.
680 I was wondering what you think about adding YYACT_PROLOGUE/EPILOGUE
681 to bison. If you're interested, I'll work on a patch.
683 * Better graphics
684 Equip the parser with a means to create the (visual) parse tree.
687 -----
689 # LocalWords:  Cex gnulib gl Bistromathic TokenKinds yylex enum YYEOF EOF
690 # LocalWords:  YYerror gettext af hb YYERRCODE undef calc FIXME dev yyerror
691 # LocalWords:  Autoconf YYUNDEFTOK lexemes parsers Bistromathic's yyreport
692 # LocalWords:  const argc yacc yyclearin lookahead destructor Rici incluent
693 # LocalWords:  yydestruct yydiscardin catégories d'avertissements sr activé
694 # LocalWords:  conflits défaut rr l'alias chaîne n'est attaché un symbole
695 # LocalWords:  obsolète règle vide midrule valeurs de intermédiaire ou avec
696 # LocalWords:  définies inutilisées priorité associativité inutiles POSIX
697 # LocalWords:  incompatibilités tous les autres avertissements sauf dans rp
698 # LocalWords:  désactiver CATEGORIE traiter comme des erreurs glr Akim bool
699 # LocalWords:  Demaille arith lalr goto struct pathlen nullable ntokens lr
700 # LocalWords:  nterm bitsetv ielr ritem nstates nrules nritems yysymbol EQ
701 # LocalWords:  SymbolKind YYEMPTY YYUNDEF YYTNAME NUM yyntokens yytname sed
702 # LocalWords:  nonterminals yykind yycode YYNAMES yynames init getName conv
703 # LocalWords:  TokenKind ival yychar yylval yylexer Tolmer hoc
704 # LocalWords:  Sobisch YYPTRDIFF ptrdiff Autotest toknum yytoknum
705 # LocalWords:  sym Wother stderr FP fixits xgettext fdiagnostics Graphviz
706 # LocalWords:  graphviz VCG bitset xml bw maint yytoken YYABORT deps
707 # LocalWords:  YYACCEPT yytranslate nonnegative destructors yyerrlab repo
708 # LocalWords:  backends stmt expr yy Mardle baz qux Vadim Maslow CPP cpp
709 # LocalWords:  yydebug gcc UCHAR EBCDIC gung PDP NUL Pre Florian Krohm utf
710 # LocalWords:  YYACT YYLLOC YYLSP yyval yyvsp yylen yyloc yylsp endif
711 # LocalWords:  ispell american
713 Local Variables:
714 mode: outline
715 coding: utf-8
716 fill-column: 76
717 ispell-dictionary: "american"
718 End:
720 Copyright (C) 2001-2004, 2006, 2008-2015, 2018-2021 Free Software
721 Foundation, Inc.
723 This file is part of Bison, the GNU Compiler Compiler.
725 Permission is granted to copy, distribute and/or modify this document
726 under the terms of the GNU Free Documentation License, Version 1.3 or
727 any later version published by the Free Software Foundation; with no
728 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
729 Texts.  A copy of the license is included in the "GNU Free
730 Documentation License" file as part of this distribution.