summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* scanner: don't crash on strings containing a NUL byteAkim Demaille2020-07-282-2/+11
| | | | | | | | | | | | We crash if the input contains a string containing a NUL byte. Reported by Suhwan Song. https://lists.gnu.org/r/bug-bison/2020-07/msg00051.html * src/flex-scanner.h (STRING_FREE): Avoid accidental use of last_string. * src/scan-gram.l: Don't call STRING_FREE without calling STRING_FINISH first. * tests/input.at (Invalid inputs): Check that case.
* style: avoid warnings with GCC 4.6Akim Demaille2020-07-231-3/+3
| | | | | | | | | | With have a clash with the "max" function. src/counterexample.c: In function 'visited_hasher': src/counterexample.c:720:48: error: declaration of 'max' shadows a global declaration [-Werror=shadow] src/counterexample.c:116:12: error: shadowed declaration is here [-Werror=shadow] * src/counterexample.c (visited_hasher): Alpha conversion.
* cex: update NEWS for 3.7Akim Demaille2020-07-221-3/+2
| | | | * NEWS: Update to the current style of cex display.
* cex: make "rerun with '-Wcex'" a note instead of a warningAkim Demaille2020-07-211-8/+12
| | | | | | | | | | | | | | | | Currently the suggestion to rerun is a -Wother warning: warning: 2 shift/reduce conflicts [-Wconflicts-sr] warning: rerun with option '-Wcounterexamples' to generate conflict counterexamples [-Wother] Instead, let's attach it as a subnote of the diagnostic (in the current case, -Wconflicts-sr): warning: 2 shift/reduce conflicts [-Wconflicts-sr] note: rerun with option '-Wcounterexamples' to generate conflict counterexamples * src/conflicts.c (conflicts_print): Do that. Adjust the test suite.
* cex: label all the derivations by their initial actionAkim Demaille2020-07-201-8/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] Example: A b . First derivation a `-> A b . Second derivation a `-> A b `-> b . to input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] Example: A b . First reduce derivation a `-> A b . Second reduce derivation a `-> A b `-> b . * src/counterexample.c (print_counterexample): here. Compute the width of the labels to properly align the values. * tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at, * tests/report.at: Adjust.
* cex: improve readability of the subsectionsAkim Demaille2020-07-203-7/+6
| | | | | | | | | | | | | Now that the derivation is no longer printed on one line, aligning the example and the derivation is no longer useful. It can actually be harmful, as it makes the overall structure less clear. * src/derivation.h, src/derivation.c (derivation_print_leaves): Remove the `prefix` argument. * src/counterexample.c (print_counterexample): Put the example next to its label. * tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at, * tests/report.at: Adjust.
* cex: don't issue an empty line between counterexamplesAkim Demaille2020-07-201-2/+3
| | | | | | | | Now that we use complain, the "sections" are clearer. * src/counterexample.c (print_counterexample): Use the empty line only in reports. * tests/counterexample.at, tests/diagnostics.at, tests/report.at: Adjust.
* cex: use usual routines for diagnostics about S/R conflictsAkim Demaille2020-07-201-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | See previous commit. We go from input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr] Shift/reduce conflict on token "⊕": Example exp "+" exp • "⊕" exp Shift derivation exp ↳ exp "+" exp ↳ exp • "⊕" exp to input.y: warning: 3 reduce/reduce conflicts [-Wconflicts-rr] input.y: warning: shift/reduce conflict on token "⊕" [-Wcounterexamples] Example exp "+" exp • "⊕" exp Shift derivation exp ↳ exp "+" exp ↳ exp • "⊕" exp with an hyperlink on -Wcounterexamples. * src/counterexample.c (counterexample_report_shift_reduce): Use complain. * tests/counterexample.at, tests/diagnostics.at, tests/report.at: Adjust.
* cex: use usual routines for diagnostics about R/R conflictsAkim Demaille2020-07-201-9/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is more consistent, and brings benefits: users know that these diagnostics are attached to -Wcounterexamples, and they can also click on the hyperlink if permitted by their terminal. We go from warning: 1 reduce/reduce conflict [-Wconflicts-rr] Reduce/reduce conflict on token $end: Example A b . First derivation a -> [ A b . ] Second derivation a -> [ A b -> [ b . ] ] to warning: 1 reduce/reduce conflict [-Wconflicts-rr] input.y: warning: reduce/reduce conflict on token $end [-Wcounterexamples] Example A b . First derivation a -> [ A b . ] Second derivation a -> [ A b -> [ b . ] ] with an hyperlink on -Wcounterexamples. * src/counterexample.c (counterexample_report_reduce_reduce): Use complain. * tests/counterexample.at, tests/diagnostics.at, tests/report.at: Adjust.
* diagnostics: use hyperlinks to point to the only documentationAkim Demaille2020-07-191-3/+35
| | | | | | | * src/complain.c (begin_hyperlink, end_hyperlink): New. (warnings_print_categories): Use them. * tests/local.at (AT_SET_ENV): Disable hyperlinks in the tests, they contain random id's, and brackets (which is not so nice for M4).
* glyphs: fix typesAkim Demaille2020-07-192-30/+24
| | | | | | | | | | | | The code was written on top of buffers of `char[26]`, and then was changed to use `char *`, yet was still using `sizeof buf`, which became `sizeof (char *)` instead of `sizeof (char[26])`. Reported by Dagobert Michelsen. https://lists.gnu.org/r/bug-bison/2020-07/msg00023.html * src/glyphs.h, src/glyphs.c: Get rid of uses of `char *`, use only glyph_buffer_t.
* style: avoid strncpyAkim Demaille2020-07-191-3/+3
| | | | | | | | | | | | syntax-check seems to dislike strncpy. The GNU Coreutils replaced their uses of strncpy with stpncpy. strlcpy is not an option. http://sources.redhat.com/ml/libc-alpha/2002-01/msg00159.html http://sources.redhat.com/ml/libc-alpha/2002-01/msg00011.html http://lists.gnu.org/archive/html/bug-gnulib/2004-09/msg00181.html * src/glyphs.c: Use stpncpy.
* cex: display derivations as treesAkim Demaille2020-07-184-16/+278
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sometimes, understanding the derivations is difficult, because they are serialized to fit in one line. For instance, the example taken from the NEWS file: %token ID %% s: a ID a: expr expr: expr ID ',' | "expr" gave First example expr • ID ',' ID $end Shift derivation $accept → [ s → [ a → [ expr → [ expr • ID ',' ] ] ID ] $end ] Second example expr • ID $end Reduce derivation $accept → [ s → [ a → [ expr • ] ID ] $end ] Printing as trees, it gives: First example expr • ID ',' ID $end Shift derivation $accept ↳ s $end ↳ a ID ↳ expr ↳ expr • ID ',' Second example expr • ID $end Reduce derivation $accept ↳ s $end ↳ a ID ↳ expr • * src/glyphs.h, src/glyphs.c (down_arrow, empty, derivation_separator): New. * src/derivation.c (derivation_print, derivation_print_impl): Rename as... (derivation_print_flat, derivation_print_flat_impl): These. (fputs_if, derivation_depth, derivation_width, derivation_print_tree) (derivation_print_tree_impl, derivation_print): New. * src/counterexample.c (print_counterexample): Adjust. * tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at, * tests/report.at: Adjust.
* cex: use the glyphsAkim Demaille2020-07-163-43/+5
| | | | | | * src/derivation.c: here. * src/gram.h, src/gram.c (print_arrow, print_dot, print_fallback): Remove.
* cex: factor the handling of graphical symbolsAkim Demaille2020-07-165-2/+124
| | | | * src/glyphs.h, src/glyphs.c: New.
* cex: style changesAkim Demaille2020-07-151-1/+1
| | | | * src/counterexample.c: here.
* style: comments changesAkim Demaille2020-07-142-8/+8
| | | | * src/print.c: here.
* cex: display shifts before reductionsAkim Demaille2020-07-141-9/+25
| | | | | | | | | | | | | | | | When reporting counterexamples for s/r conflicts, put the shift first. This is more natural, and displays the default resolution first, which is also what happens for r/r conflicts where the smallest rule number is displayed first, and "wins". * src/counterexample.c (counterexample): Add a shift_reduce member. (new_counterexample): Adjust. Swap the derivations when this is a s/r conflict. (print_counterexample): For s/r conflicts, prefer "Shift derivation" and "Reduce derivation" rather than "First/Second derivation". * tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust. * NEWS, doc/bison.texi: Ditto.
* style: s/lookahead_tokens/lookaheads/gAkim Demaille2020-07-1415-103/+100
| | | | | | | | | | Currently we use both names. Let's stick to the short one. * src/AnnotationList.c, src/conflicts.c, src/counterexample.c, * src/getargs.c, src/getargs.h, src/graphviz.c, src/ielr.c, * src/lalr.c, src/print-graph.c, src/print-xml.c, src/print.c, * src/state-item.c, src/state.c, src/state.h, src/tables.c: s/lookahead_token/lookahead/gi.
* cex: factor memory allocationAkim Demaille2020-07-141-5/+6
| | | | | * src/counterexample.c (counterexample_report_state): Allocate once per conflicted state, instead of once per r/r conflict.
* cex: use state_item_number consistentlyAkim Demaille2020-07-142-15/+15
| | | | | | * src/counterexample.c, src/state-item.c: here. (counterexample_report_state): While at it, prefer c2 to j/k, to match c1.
* cex: more consistent memory allocation/copyAkim Demaille2020-07-142-9/+9
| | | | | | | * src/counterexample.c, src/parse-simulation.c: It is more usual in Bison to use sizeof on expressions than on types, especially for allocation. Let the compiler do it's job instead of calling memcpy ourselves.
* cex: minor renamingAkim Demaille2020-07-141-2/+2
| | | | | * src/counterexample.c (has_common_prefix): Rename as... (have_common_prefix): this.
* cex: use better type namesAkim Demaille2020-07-147-65/+78
| | | | | | | | | | | There are too many gl_list_t in there, it's hard to understand what is going on. Introduce and use more precise types. I sure can be wrong in some places, it's hard to tell without proper tool support. * src/counterexample.c, src/lssi.c, src/lssi.h, src/parse-simulation.c, * src/parse-simulation.h, src/state-item.c, src/state-item.h (si_bfs_node_list, search_state_list, ssb_list, lssi_list) (state_item_list): New.
* cex: minor style changesAkim Demaille2020-07-143-25/+34
| | | | | | * src/counterexample.h, src/derivation.h, src/derivation.c: More comments. Use `out` for FILE*, as elsewhere.
* cex: prefer → to ::=Akim Demaille2020-07-112-7/+27
| | | | | | | | | | | | | | | | | | It does not make a lot of sense to use ::= in our counterexamples, that's not something that belongs to the Bison "vocabulary". Using the colon makes sense, but it's too discreet. Let's use the arrow, which we already use in some reports (HTML and Dot). * src/gram.h (print_dot_fallback): Generalize into... (print_fallback): this. (print_arrow): New. * src/derivation.c: Use it. * NEWS, tests/conflicts.at, tests/counterexample.at, * tests/diagnostics.at, tests/report.at: Adjust. * doc/bison.texi: Ditto. Unfortunately the literal `→` is output as `↦`. So we need to use @arrow.
* style: cex: prefer the array notationAkim Demaille2020-07-114-43/+41
| | | | | | | | | Prefer `&foos[i]` to `foos + i` when `foos` is an array. IMHO, it makes the semantics clearer. * src/counterexample.c, src/lssi.c, src/parse-simulation.c, * src/state-item.c: With arrays, prefer the array notation rather than the pointer one.
* style: cex: remove variables that don't make it simpler to readAkim Demaille2020-07-112-24/+17
| | | | | * src/counterexample.c: With arrays, prefer the array notation rather than the pointer one.
* reports: let xml reports catch up with --report and --graphAkim Demaille2020-07-111-4/+9
| | | | | | | | | | | | | | | The text and Dot reports are expected to be identical when generated directly (--report, --graph) or indirectly (via XML). The xml testsuite had not be run for ages, let it catch up a bit. * src/print-xml.c: Pass the type of the symbols. * data/xslt/xml2text.xsl Catch up with the new layout. Display the symbol types. Use '•', not '.' * tests/local.at: Smash '•' to '.' when matching against the direct text report. * tests/report.at: Adjust XML expectations.
* style: factor complex expressionsAkim Demaille2020-07-112-11/+14
| | | | | * src/print-xml.c, src/print.c: Introduce a variable pointing to the current symbol.
* style: update commentsAkim Demaille2020-07-053-8/+7
| | | | | | * src/reader.c: action_obstack was removed in 2002... * src/parse-gram.y: Better names. * src/scan-code.h: More comments.
* style: update comments in the skeletonsAkim Demaille2020-07-051-2/+3
| | | | | | | * data/skeletons/c++.m4, data/skeletons/glr.c, data/skeletons/lalr1.d, * data/skeletons/lalr1.java, data/skeletons/yacc.c: Be more accurate about yychar and yytoken. Don't name local variables as if they were members.
* regenAkim Demaille2020-07-052-19/+20
|
* examples: include the generated headerAkim Demaille2020-07-051-3/+4
| | | | | | | | | * examples/c/bistromathic/parse.y, examples/c/lexcalc/parse.y, * examples/c/reccalc/parse.y: here. Add some comments. * src/parse-gram.y (api_version): Pull out of handle_require. Bump to 3.7.
* dot: also use a dot in the outputAkim Demaille2020-07-031-1/+1
| | | | | | | | * src/print-graph.c (print_core): Use a dot instead of a point. * doc/figs/example-reduce.gv, doc/figs/example-reduce.txt, * doc/figs/example-shift.gv, doc/figs/example-shift.txt, * doc/figs/example.gv: Update. * tests/output.at, tests/report.at: Adjust.
* regenAkim Demaille2020-06-292-43/+23
|
* java: rename package as api.packageAkim Demaille2020-06-281-0/+1
| | | | | | | * data/skeletons/lalr1.java: here. * doc/bison.texi: Update. * src/muscle-tab.c: Ensure backward compat. * tests/java.at: Check it.
* style: shift/reduce, not shift-reduceAkim Demaille2020-06-281-2/+2
| | | | * src/reader.c: here.
* style: rename endtoken as eoftokenAkim Demaille2020-06-275-21/+21
| | | | | | * src/symtab.h, src/symtab.c (endtoken): Rename as... (eoftoken): this. Adjust dependencies.
* style: use 'nonterminal' consistentlyAkim Demaille2020-06-2718-69/+79
| | | | | | | | | * doc/bison.texi: Formatting changes. * src/gram.h, src/gram.c (nvars): Rename as... (nnterms): this. Adjust dependencies. (section): New. Use it. Replace "non terminal" and "non-terminal" by "nonterminal".
* c++: by default, use const std::string for file namesAkim Demaille2020-06-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | Reported by Martin Blais and Yuriy Solodkyy. https://lists.gnu.org/r/help-bison/2020-05/msg00011.html https://lists.gnu.org/r/bug-bison/2020-06/msg00038.html While at it, modernize filename_type as api.filename.type and document it properly. * data/skeletons/c++.m4 (filename_type): Rename as... (api.filename.type): this. Default to const std::string. * data/skeletons/location.cc (position, location): Expose the filename_type type. Use api.filename.type. * doc/bison.texi (%define Summary): Document api.filename.type. (C++ Location Values): Document position::filename_type. * src/muscle-tab.c (muscle_percent_variable_update): Ensure backward compatibility. * tests/c++.at: Check that using const file names is ok. tests/input.at: Check backward compat.
* ielr: fix crash on memory managementAkim Demaille2020-06-272-1/+5
| | | | | | | | | | | Reported by Dwight Guth. https://lists.gnu.org/r/bug-bison/2020-06/msg00037.html * src/AnnotationList.c (AnnotationList__computePredecessorAnnotations): Beware that SBITSET__FOR_EACH nests _two_ for-loops, so "break" does not actually break out of it. That was the only occurrence in the code. * src/Sbitset.h (SBITSET__FOR_EACH): Warn passersby.
* style: factor the access to a rule from its itemsAkim Demaille2020-06-255-42/+19
| | | | | | * src/counterexample.c (item_rule): Move to... * src/counterexample.h: here. * src/AnnotationList.c, src/counterexample.c, src/ielr.c: Use it.
* style: clean up nullableAkim Demaille2020-06-251-51/+44
| | | | | * src/nullable.c: Reduce scopes. Prefer `r` to `rules_ruleno`, which is truly an ugly name.
* style: clean up ielrAkim Demaille2020-06-252-186/+179
| | | | | | | | | * src/AnnotationList.c, src/ielr.c: Fix include order. Prefer `res` to `result`. Reduce scopes. Be free of the oldish 76 cols limitation when it clutters too much the code. Denest when possible (we're starving for horizontal width).
* don't use strlen to compute visual widthAkim Demaille2020-06-231-1/+2
| | | | * src/output.c (prepare_symbol_names): Use mbswidth.
* doc: use dot/'•' rather than point/'.'Akim Demaille2020-06-232-3/+3
| | | | | | | | | | | | | AFAICT, "dotted rule" is a more frequent synonym of "item" than "pointed rule". So let's migrate to using "dot" only. * doc/bison.texi: Use dot/'•' rather than point/'.'. * src/print-xml.c (print_core): Use dot rather than point. This is not backward compatible, but AFAICT, we don't have actual user of the XML output (but ourselves). So... * data/xslt/xml2dot.xsl, data/xslt/xml2text.xsl, * data/xslt/xml2xhtml.xsl, tests/report.at: ... adjust.
* cex: display all the S/R conflicts, not just one per (state, rule)Akim Demaille2020-06-231-25/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, on %% exp : "if" exp "then" exp | "if" exp "then" exp "else" exp | exp "+" exp | "num" we used to not display the third counterexample below: Shift/reduce conflict on token "+": Example exp "+" exp . "+" exp First derivation exp ::=[ exp ::=[ exp "+" exp . ] "+" exp ] Second derivation exp ::=[ exp "+" exp ::=[ exp . "+" exp ] ] Shift/reduce conflict on token "else": Example "if" exp "then" "if" exp "then" exp . "else" exp First derivation exp ::=[ "if" exp "then" exp ::=[ "if" exp "then" exp . ] "else" exp ] Second derivation exp ::=[ "if" exp "then" exp ::=[ "if" exp "then" exp . "else" exp ] ] Shift/reduce conflict on token "+": Example "if" exp "then" exp . "+" exp First derivation exp ::=[ exp ::=[ "if" exp "then" exp . ] "+" exp ] Second derivation exp ::=[ "if" exp "then" exp ::=[ exp . "+" exp ] ] Shift/reduce conflict on token "+": Example "if" exp "then" exp "else" exp . "+" exp First derivation exp ::=[ exp ::=[ "if" exp "then" exp "else" exp . ] "+" exp ] Second derivation exp ::=[ "if" exp "then" exp "else" exp ::=[ exp . "+" exp ] ] * src/counterexample.c (counterexample_report_state): Don't stop of the first conflicts. * tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at, * tests/report.at: Adjust.
* cex: don't display twice unifying examples if there is no colorAkim Demaille2020-06-223-6/+30
| | | | | | | | | | | | It makes no sense, and is actually confusing, to display twice the same example with no visible difference. * src/complain.h, src/complain.c (is_styled): New. * src/counterexample.c (print_counterexample): Display the unified example a second time only if it makes a difference. * tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust. * tests/diagnostics.at: Make sure we do display the unifying examples twice when colors are enabled. And check those colors.
* cex: fix reporting of null nonterminalsVincent Imbimbo2020-06-222-11/+25
| | | | | | | | | | | I implemented this to print A ::= [ ], but A ::= [ %empty ] might be clearer. * src/parse-simulation.c (nullable_closure): Don't generate null nonterminal derivations as leaves. * src/derivation.c (derivation_print_impl): Don't print seperator spaces for null nonterminal. * tests/counterexample.at: Update test results.