summaryrefslogtreecommitdiff
path: root/examples
Commit message (Collapse)AuthorAgeFilesLines
* yacc.c: yypstate_expected_tokensAkim Demaille2020-03-171-8/+7
| | | | | | | | | | | | | | | | | | | In push parsers, when asking for the list of expected tokens at some point, it makes no sense to build a yyparse_context_t: the yypstate alone suffices (the only difference being the lookahead). Instead of forcing the user to build a useless shell around yypstate, let's offer yypstate_expected_tokens. See https://lists.gnu.org/r/bison-patches/2020-03/msg00025.html. * data/skeletons/yacc.c (yypstate): Declare earlier, so that we can use it for... (yypstate_expected_tokens): this new function, when in push parsers. Adjust dependencies. * examples/c/bistromathic/parse.y: Simplify: use yypstate_expected_tokens. Style fixes. Reduce scopes (reported by Joel E. Denny).
* examples: bistromathic: simplifyAkim Demaille2020-03-091-2/+0
| | | | * examples/c/bistromathic/parse.y (expected_tokens): Remove useless "break".
* yacc.c: push: undefine the pstate macros for the epilogueAkim Demaille2020-03-051-5/+0
| | | | | | | | * data/skeletons/yacc.c (b4_macro_define, b4_macro_undef) (b4_pstate_macro_define, b4_parse_state_variable_macros): New. Use them. * examples/c/bistromathic/parse.y: Remove now useless undefs.
* yacc.c: push: initialize the pstate variables in pstate_newAkim Demaille2020-03-052-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently pstate_new does not set up its variables, this task is left to yypush_parse. This was probably to share more code with usual pull parsers, where these (local) variables are indeed initialized by yyparse. But as a consequence yyexpected_tokens crashes at the very beginning of the parse, since, for instance, the stacks are not even set up. See https://lists.gnu.org/r/bison-patches/2020-03/msg00001.html. The fix could have very simple, but the documentation actually makes it very clear that we can reuse a pstate for several parses: After yypush_parse returns a status other than YYPUSH_MORE, the parser instance yyps may be reused for a new parse. so we need to restore the parser to its pristine state so that (i) it is ready to run the next parse, (ii) it properly supports yyexpected_tokens for the next run. * data/skeletons/yacc.c (b4_initialize_parser_state_variables): New, extracted from the top of yyparse/yypush_parse. (yypstate_clear): New. (yypstate_new): Use it when push parsers are enabled. Define after the yyps macros so that we can use the same code as the regular pull parsers. (yyparse): Use it when push parsers are _not_ enabled. * examples/c/bistromathic/bistromathic.test: Check the completion on the beginning of the line.
* bistromathic: properly compute the lcp, as expected by readlineAkim Demaille2020-03-042-2/+23
| | | | | | | | | Currently completion on "at" proposes only "atan", but does not actually complete "at" into "atan". * examples/c/bistromathic/parse.y (completion): Install the lcp in matches[0]. * examples/c/bistromathic/bistromathic.test: Check that case.
* bistromathic: don't require spaces after operators for completionAkim Demaille2020-03-042-7/+11
| | | | | | | | | Currently "(1+<TAB>" does not work as expected, because "+" is not a word breaking character. * examples/c/bistromathic/parse.y (init_readline): Specify our word breaking characters. * examples/c/bistromathic/bistromathic.test: Avoid trailing spaces.
* bistromathic: check completionAkim Demaille2020-03-022-1/+18
| | | | | | * examples/c/bistromathic/bistromathic.test: here. * examples/c/bistromathic/parse.y (expected_tokens): Fix a memory leak.
* examples: bistromathic: demonstrate the use of yyexpected_tokensAkim Demaille2020-03-015-57/+233
| | | | | | | | | | | | | | | | | | | | | | | | | | | Let's use GNU readline and its TAB autocompletion to demonstrate the use of yyexpected_tokens. This shows a number of weaknesses in our current approach: - some macros (yyssp, etc.) from push parsers "leak" in user code, we need to undefine them - the context needed by yyexpected_tokens does not need the token, yypstate actually suffices - yypstate is not properly setup when first allocated, which results in a crash of yyexpected_tokens if fired before a first token was read. We should move initialization from yypush_parse into yypstate_new. * examples/c/bistromathic/parse.y (yylex): Take input as a string, not a file. (EXIT): New token. (input): Adjust to work only on a line. (line): Remove. (symbol_count, process_line, expected_tokens, completion) (init_readline): New. * examples/c/bistromathic/bistromathic.test: Adjust expectations.
* examples: use consistently the GFDL header for readmesAkim Demaille2020-03-017-66/+35
| | | | | | | * 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.
* examples: bistromathic: don't use FlexAkim Demaille2020-02-295-91/+100
| | | | | | | | | | | 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.
* examples: bistromathic: strengthen testsAkim Demaille2020-02-294-7/+21
| | | | | * examples/c/bistromathic/bistromathic.test: here. * examples/test: Be clearer on failing tests.
* examples: lexcalc: demonstrate location trackingAkim Demaille2020-02-297-16/+43
| | | | | | | | | 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.
* examples: fix c/calcAkim Demaille2020-02-191-1/+0
| | | | * examples/c/calc/calc.y: Remove experiment traces.
* examples: bistromathic: demonstrate named referencesAkim Demaille2020-02-123-12/+14
| | | | * examples/c/bistromathic/parse.y: here.
* java: beware not to alias the locations of the various symbolsAkim Demaille2020-02-111-2/+8
| | | | | | * examples/java/calc/Calc.y, tests/calc.at, tests/local.at (getStartPos, getEndPos): Always return a new object. * doc/bison.texi: Clarify this.
* java: don't expose the Context's membersAkim Demaille2020-02-111-1/+1
| | | | | | * data/skeletons/lalr1.java (Context): Make data members private. (Context.getLocation): New. * examples/java/calc/Calc.y, tests/java.at, tests/local.at: Adjust.
* java: provide Context with a more OO interfaceAkim Demaille2020-02-081-3/+3
| | | | | | | * data/skeletons/lalr1.java (yyexpectedTokens) (yysyntaxErrorArguments): Make them methods of Context. (Context.yysymbolName): New. * tests/local.at: Adjust.
* java: add support for parse.error customAkim Demaille2020-02-084-9/+29
| | | | | | | | | | | | | * data/skeletons/lalr1.java: Add support for custom parse errors. (yyntokens_): Make it public. Under... (yyntokens): this name. (Context): Capture the location too. * examples/c/bistromathic/parse.y, * examples/c/bistromathic/bistromathic.test: Improve error message. * examples/java/calc/Calc.test, examples/java/calc/Calc.y: Use custom error messages. * tests/calc.at, tests/local.at: Check custom error messages.
* java: add support for parse.error=detailedAkim Demaille2020-02-081-1/+1
| | | | | | | | | | | | | | In Java there is no need for N_ and yytranslate_. So instead of hard-coding the use of N_ in the table of the symbol names, rely on b4_symbol_translate. * src/output.c (prepare_symbol_names): Use b4_symbol_translate instead of N_. * data/skeletons/c.m4 (b4_symbol_translate): New. * data/skeletons/lalr1.java (yysymbolName): New. Use it. * examples/java/calc/Calc.y: Use parse.error=detailed. * tests/calc.at: Check parse.error=detailed.
* java: style: prefer putting the square brackets on the typeAkim Demaille2020-02-052-2/+2
| | | | | * examples/java/calc/Calc.y, examples/java/simple/Calc.y, * tests/calc.at, tests/local.at: here.
* java: examples: fix the tracking of locationsAkim Demaille2020-02-052-4/+18
| | | | | | | | * examples/java/calc/Calc.y: The StreamTokenizer cannot "peek" for the next character, it reads it, and keeps it for the next call. So the current location is one passed the end of the current token. To avoid this, keep the previous position, and use it to end the current token. * examples/java/calc/Calc.test: Adjust.
* java: examples: prefer switch to chains of else-ifAkim Demaille2020-02-052-19/+19
| | | | | * examples/java/calc/Calc.y, examples/java/simple/Calc.y: here. * examples/java/simple/Calc.y: Use the tokenizer's handling of blanks.
* java: examples: split in twoAkim Demaille2020-02-0510-25/+252
| | | | | * examples/java: Split in... * examples/java/simple, examples/java/calc: these.
* traces: show the stack after reading a tokenAkim Demaille2020-02-051-0/+1
| | | | | | | | | | | | | | Currently, if we have long rules and series of shift, we stack states without showing stack. Let's be more incremental, and do how the Java skeleton does. * data/skeletons/lalr1.cc, data/skeletons/lalr1.d, * data/skeletons/yacc.c: Here. Adjust test cases. * tests/torture.at (AT_DATA_STACK_TORTURE): Disable stack traces: this test produces a very large stack, and showing the stack each time we shift a token goes quadatric.
* java: example: properly track the locationsAkim Demaille2020-02-022-21/+59
| | | | | | | | | This example, so far, was tracking the current token number, not the current column number. This is not nice for an example... * examples/java/Calc.y (PositionReader): New. Use it. * examples/java/Calc.test: Check the output.
* java: example: improveAkim Demaille2020-02-021-1/+7
| | | | | * examples/java/Calc.y: Propagate the exit status. Support -p.
* java: example: rely on autoboxingAkim Demaille2020-02-022-13/+18
| | | | | | | | | | | | AFAICT, autoboxing/unboxing was added in Java 5 (September 30, 2004). I think we can afford to use it. It should help us merge some Java tests with the main ones. However, beware that != does not unbox: it compares the object addresses. * examples/java/Calc.y, tests/java.at: Simplify. * examples/java/Calc.test, tests/java.at: Improve tests.
* examples: bistromathic: fix location trackingAkim Demaille2020-02-022-3/+14
| | | | | | * examples/c/bistromathic/scan.l (LOCATION_STEP): New. Use to properly ignore blanks. * examples/c/bistromathic/bistromathic.test: Check that case.
* examples: be more robust to spaces in pathsAkim Demaille2020-01-271-14/+14
| | | | | | | | | Reported by Nikki Valen. https://lists.gnu.org/r/bug-bison/2020-01/msg00032.html * examples/test ($prog): Remove, replaced by... (prog): This new function, which pays attention to quoting shell variables.
* examples: add a complete example with all the bells and whistlesAkim Demaille2020-01-279-4/+454
| | | | | | | | | | | | | * examples/c/bistromathic/Makefile, * examples/c/bistromathic/README.md, * examples/c/bistromathic/bistromathic.test, * examples/c/bistromathic/local.mk, * examples/c/bistromathic/parse.y, * examples/c/bistromathic/scan.l: New. * Makefile.am (AM_YFLAGS_WITH_LINES): Add -Wdangling-alias. * examples/test: Make failure errors easier to read.
* examples: add an example of a push parserAkim Demaille2020-01-267-0/+268
| | | | | | | | | | Add an example to demonstrate the use of push parser. I'm pleasantly surprised: parse.error=detailed works like a charm with push parsers. * examples/c/local.mk, examples/c/pushcalc/Makefile * examples/c/pushcalc/README.md, examples/c/pushcalc/calc.test, * examples/c/pushcalc/calc.y, examples/c/pushcalc/local.mk: New.
* examples: more testsAkim Demaille2020-01-261-0/+12
| | | | * examples/c/mfcalc/mfcalc.test: here.
* examples: clean upAkim Demaille2020-01-265-58/+42
| | | | | | | | * examples/c/calc/calc.y: Restore to its original state, with parse.error=detailed instead of parse.error=custom (this example should be simple). * examples/c/calc/calc.test: Check syntax errors. * examples/c/lexcalc/parse.y: Add comments.
* yacc.c: isolate yyexpected_tokensAkim Demaille2020-01-171-5/+27
| | | | | | | | | | Provide users with a means to query for the currently allowed tokens. Could be used for autocompletion for instance. * data/skeletons/yacc.c (yyexpected_tokens): New, extracted from yysyntax_error_arguments. * examples/c/calc/calc.y (PRINT_EXPECTED_TOKENS): New. Use it.
* yacc.c: add custom error message generationAkim Demaille2020-01-171-0/+23
| | | | | | | | | When parse.error is custom, let users define a yyreport_syntax_error function, and use it. * data/skeletons/bison.m4 (b4_error_verbose_if): Accept 'custom'. * data/skeletons/yacc.c: Implement it. * examples/c/calc/calc.y: Experiment with it.
* package: bump copyrights to 2020Akim Demaille2020-01-0534-34/+34
| | | | Run 'make update-copyright'.
* tests: don't fail if seq is no availableAkim Demaille2019-12-141-0/+2
| | | | | | | | As is the case on Solaris. Reported by Dennis Clarke. https://lists.gnu.org/archive/html/bug-bison/2019-12/msg00011.html * examples/c/reccalc/reccalc.test: Skip if there is no seq.
* examples: fix missing dependenciesAkim Demaille2019-10-241-3/+27
| | | | | | | | | | | Reported by Thomas Petazzoni. https://lists.gnu.org/archive/html/bug-bison/2019-08/msg00000.html * examples/c/reccalc/local.mk: Complete dependencies, including for earlier versions of Automake (for sake of our CI, on top of Ubuntu Xenial/Bionic, which feature only Automake 1.15). (%D%/scan.c %D%/scan.h): Upgrade to the full version provided in Automake's documentation.
* gitignore: updateAkim Demaille2019-10-231-0/+2
|
* Port lexcalc scan.l to Solaris 10Paul Eggert2019-10-051-0/+1
| | | | * examples/c/lexcalc/scan.l: Include errno.h.
* Prefer signed to unsigned integersPaul Eggert2019-10-022-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch contains more fixes to prefer signed to unsigned integer types, as modern tools like 'gcc -fsanitize=undefined' can check for signed integer overflow but not unsigned overflow. * NEWS: Document the API change. * boostrap.conf (gnulib_modules): Add intprops. * data/skeletons/glr.c: Include stddef.h and stdint.h, since this skeleton can assume C99 or later. (YYSIZEMAX): Now signed, and the minimum of SIZE_MAX and PTRDIFF_MAX. (yybool) [!__cplusplus]: Now signed (which is how bool behaves). (YYTRANSLATE): Avoid use of unsigned, and make the macro safe even for values greater than UINT_MAX. (yytnamerr, struct yyGLRState, struct yyGLRStateSet, struct yyGLRStack) (yyaddDeferredAction, yyinitStateSet, yyinitGLRStack) (yyexpandGLRStack, yymarkStackDeleted, yyremoveDeletes) (yyglrShift, yyglrShiftDefer, yy_reduce_print, yydoAction) (yyglrReduce, yysplitStack, yyreportTree, yycompressStack) (yyprocessOneStack, yyreportSyntaxError, yyrecoverSyntaxError) (yyparse, yy_yypstack, yypstack, yypdumpstack): * tests/input.at (Torturing the Scanner): Prefer ptrdiff_t to size_t. * data/skeletons/c++.m4 (b4_yytranslate_define): * src/AnnotationList.c (AnnotationList__computePredecessorAnnotations): * src/AnnotationList.h (AnnotationIndex): * src/InadequacyList.h (InadequacyListNodeCount): * src/closure.c (closure_new): * src/complain.c (error_message, complains, complain_indent) (complain_args, duplicate_directive, duplicate_rule_directive): * src/gram.c (nritems, ritem_print, grammar_dump): * src/ielr.c (ielr_compute_ritem_sees_lookahead_set) (ielr_item_has_lookahead, ielr_compute_annotation_lists) (ielr_compute_lookaheads): * src/location.c (columns, boundary_print, location_print): * src/muscle-tab.c (muscle_percent_define_insert) (muscle_percent_define_check_values): * src/output.c (prepare_rules, prepare_actions): * src/parse-gram.y (id, handle_require): * src/reader.c (record_merge_function_type, packgram): * src/reduce.c (nuseless_productions, nuseless_nonterminals) (inaccessable_symbols): * src/relation.c (relation_print): * src/scan-code.l (variant, variant_table_size, variant_count) (variant_add, get_at_spec, show_sub_message, show_sub_messages) (parse_ref): * src/scan-gram.l (<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>) (scan_integer, convert_ucn_to_byte, handle_syncline): * src/scan-skel.l (at_complain): * src/symtab.c (complain_symbol_redeclared) (complain_semantic_type_redeclared, complain_class_redeclared) (symbol_class_set, complain_user_token_number_redeclared): * src/tables.c (conflict_tos, conflrow, conflict_table) (conflict_list, save_row, pack_vector): * tests/local.at (AT_YYLEX_DEFINE(c)): Prefer signed to unsigned integer. * data/skeletons/lalr1.cc (yy_lac_check_): * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): * tests/local.at (AT_YYLEX_DEFINE(c)): Omit now-unnecessary casts. * data/skeletons/location.cc (b4_location_define): * doc/bison.texi (Mfcalc Lexer, C++ position, C++ location): Prefer int to unsigned for line and column numbers. Change example to abort explicitly on memory exhaustion, and fix an off-by-one bug that led to undefined behavior. * data/skeletons/stack.hh (stack::operator[]): Also allow ptrdiff_t indexes. (stack::pop, slice::slice, slice::operator[]): Index arg is now ptrdiff_t, not int. (stack::ssize): New method. (slice::range_): Now ptrdiff_t, not int. * data/skeletons/yacc.c (b4_state_num_type): Remove. All uses replaced by b4_int_type. (YY_CONVERT_INT_BEGIN, YY_CONVERT_INT_END): New macros. (yylac, yyparse): Use them around conversions that -Wconversion would give false alarms about. Omit unnecessary casts. (yy_stack_print): Use int rather than unsigned, and omit a cast that doesn’t seem to be needed here any more. * examples/c++/variant.yy (yylex): * examples/c++/variant-11.yy (yylex): Omit no-longer-needed conversions to unsigned. * src/InadequacyList.c (InadequacyList__new_conflict): Don’t assume *node_count is unsigned. * src/output.c (muscle_insert_unsigned_table): Remove; no longer used.
* git: update ignoresAkim Demaille2019-09-221-0/+1
|
* d: remove useless importsAkim Demaille2019-08-291-5/+0
| | | | * examples/d/calc.y, tests/calc.at: here.
* style: comment changesAkim Demaille2019-06-272-6/+6
| | | | | * examples/c/lexcalc/local.mk, examples/c/reccalc/local.mk: Here.
* d: style changesAkim Demaille2019-06-201-3/+1
| | | | | | * data/skeletons/lalr1.d: here. * examples/d/calc.y: Remove incorrect support for decimal numbers. Formatting changes.
* java: style changesAkim Demaille2019-06-191-3/+3
| | | | | | | | | | | | | | * data/skeletons/lalr1.java: Use more conventional function names for Java. Prefer < and <= to => and >. Use the same approach for m4 quotation as in the other skeletons. Fix indentation issues. * tests/calc.at, tests/java.at, tests/javapush.at: Fix quotation style. (main): Use 'args', not 'argv', the former seems more conventional and is used elsewhere in Bison. Prefer character literals to integers to denote characters. * examples/java/Calc.y: Likewise.
* tests: take SHELL into accountAkim Demaille2019-05-261-1/+1
| | | | | | | Reported by Dennis Clarke. http://lists.gnu.org/archive/html/bug-bison/2019-05/msg00053.html * examples/local.mk, tests/local.mk: here.
* examples: don't run those that require f?lex when it's not availableAkim Demaille2019-05-192-14/+19
| | | | | | | | Reported by Bruno Haible. http://lists.gnu.org/archive/html/bug-bison/2019-05/msg00026.html * configure.ac (FLEX_WORKS): New. * examples/c/lexcalc/local.mk, examples/c/reccalc/local.mk: Use it.
* examples: fix srcdir/builddir issuesAkim Demaille2019-05-182-2/+2
| | | | * examples/d/local.mk, examples/java/local.mk: here.
* build: do not use $< in plain rulesAkim Demaille2019-05-133-5/+5
| | | | | | | | | | | | It works only in implicit rules (or with GNU Make, but not with Solaris Make). Reported by Bruno Haible. http://lists.gnu.org/archive/html/bug-bison/2019-05/msg00009.html Diagnosed thanks to Kiyoshi Kanazawa. * examples/c/reccalc/local.mk, examples/d/local.mk, * examples/java/local.mk: Don't use $< in non implicit rules.