Commit Graph

254 Commits

Author SHA1 Message Date
Akim Demaille
3dcfb4fd88 java: prefer null to YYSYMBOL_YYEMPTY
That's one nice benefit from using enums.

* data/skeletons/lalr1.java (YYSYMBOL_YYEMPTY): No longer define it.
Use 'null' instead.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-06 19:14:11 +02:00
Akim Demaille
c0ccb8e5b4 java: rename Lexer.yyreportSyntaxError as reportSyntaxError
* data/skeletons/lalr1.java: here.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-06 19:14:06 +02:00
Akim Demaille
79f967ac0d java: use getExpectedTokens, not yyexpectedTokens
* data/skeletons/lalr1.java, examples/java/calc/Calc.y, tests/local.at:
here.
2020-04-06 18:43:34 +02:00
Akim Demaille
cc68bbf799 bison: use consistently "token kind", not "token type"
* src/output.c, src/reader.c, src/scan-gram.l, src/tables.c: here.
2020-04-05 19:14:39 +02:00
Akim Demaille
04d62346f3 doc: refer to the token kind rather than the token type
* doc/bison.texi: Replace occurrences of "token type" with "token
kind".
Stop referring to the "macro definitions" of the token kinds, just
name them "definitions".
2020-04-05 19:14:39 +02:00
Akim Demaille
ff2fc62138 d, java: rename SymbolType as SymbolKind
See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html.

* data/skeletons/d.m4, data/skeletons/lalr1.d,
* data/skeletons/java.m4, data/skeletons/lalr1.java
(SymbolType): Rename as...
(SymbolKind): this.
Adjust dependencies.
2020-04-05 14:56:19 +02:00
Akim Demaille
2c05fc750a c, c++: rename yysymbol_type_t as yysymbol_kind_t
See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/yacc.c
(yysymbol_type_t): Rename as...
(yysymbol_kind_t): this.
Adjust dependencies.
* data/skeletons/c++.m4, data/skeletons/glr.cc, data/skeletons/lalr1.cc
(symbol_type_type): Rename as...
(symbol_kind_type): this.
Adjust dependencies.
2020-04-05 14:56:18 +02:00
Akim Demaille
7aee4586ca Merge branch 'maint'
* maint:
  maint: post-release administrivia
  version 3.5.4
  examples: reccalc: really compile cleanly in C99
  news: announce that Bison 3.6 drops YYERROR_VERBOSE
  news: update for 3.5.4
  style: fix spellos
  typo: succesful -> successful
  package: improve the readme
  java: check and fix support for api.token.raw
  java: style: prefer 'int[] foo' to 'int foo[]'
  build: fix syntax-check issues
  tests: recheck: work properly when the test suite was interrupted
  doc: c++: promote api.token.raw
  build: fix compatibility with old compilers
  examples: reccalc: compile cleanly in C99
2020-04-05 09:38:15 +02:00
Akim Demaille
225a67321b news: update the yyreport_syntax_error example
* examples/c/bistromathic/parse.y, tests/local.at
(yyreport_syntax_error): Fix use of YYSYMBOL_YYEMPTY.
* NEWS: Update.
2020-04-05 08:56:23 +02:00
Akim Demaille
678853da7e examples: reccalc: really compile cleanly in C99
The previous fix does not suffice, and actually managed to make things
worse by defining yyscan_t twice in parse.y...

Reported by kencu.
https://trac.macports.org/ticket/59927#comment:29

* examples/c/reccalc/parse.y (yyscan_t): Define it with the same
guards as used by Flex.
2020-04-05 08:34:40 +02:00
Akim Demaille
76e11b5a3e c: rename yyparse_context_t as yypcontext_t
The first name is too long.  We already have `yypstate`, so
`yypcontext` is ok.  We are also migrating to using `*_t` for our
types.

* NEWS, data/skeletons/glr.c, data/skeletons/yacc.c, doc/bison.texi,
* examples/c/bistromathic/parse.y, src/parse-gram.y, tests/local.at:
(yyparse_context_t, yyparse_context_location, yyparse_context_token):
Rename as...
(yypcontext_t, yypcontext_location, yypcontext_token): these.
2020-04-04 19:20:29 +02:00
Akim Demaille
ad31c3cdf4 java: use SymbolType
The Java enums are very different from the C model.  As a consequence,
one cannot "build" an enum directly from an integer, we must retrieve
it.  That's the purpose of the SymbolType.get class method.

* data/skeletons/java.m4 (b4_symbol_enum, b4_case_code_symbol)
(b4_declare_symbol_enum): New.
* data/skeletons/lalr1.java: Use SymbolType,
SymbolType.YYSYMBOL_YYEMPTY, etc.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-04 16:42:33 +02:00
Akim Demaille
7fa23136ca examples: java: use explicit token identifiers
* examples/java/calc/Calc.y: Declare all the tokens, so that we are
compatibile with api.token.raw.
* examples/java/calc/Calc.test: Adjust.
2020-04-04 16:42:33 +02:00
Akim Demaille
e3e21cc0d8 examples: reccalc: compile cleanly in C99
See https://trac.macports.org/ticket/59927.

* examples/c/reccalc/parse.y: C99 does not allow multiple typedefs.
2020-04-02 07:14:19 +02:00
Akim Demaille
ecc3a13c34 bistromathic: use symbol numbers instead of YYTRANSLATE
* examples/c/bistromathic/parse.y: here.
2020-04-01 08:31:48 +02:00
Akim Demaille
00c80bc96c yacc.c: use yysymbol_type_t instead of int for yytoken
Now that we have a proper type for internal symbol numbers, let's use
it.  More code needs conversion, e.g., printers and destructors, but
they are shared with glr.c, which is not ready yet for this change.

It will also help us deal with warnings such as (GCC9 on GNU/Linux):

    input.c: In function 'int yyparse()':
    input.c:475:37: error: enumeral and non-enumeral type in conditional expression [-Werror=extra]
      475 |   (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYSYMBOL_YYUNDEF)
          |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    input.c:1024:17: note: in expansion of macro 'YYTRANSLATE'
     1024 |       yytoken = YYTRANSLATE (yychar);
          |                 ^~~~~~~~~~~

* data/skeletons/yacc.c (yytranslate, yysymbol_name)
(yyparse_context_t, yyexpected_tokens, yypstate_expected_tokens)
(yysyntax_error_arguments):
Use yysymbol_type_t instead of int.
2020-04-01 08:31:48 +02:00
Akim Demaille
2c74872991 java: move away from _ for internationalization
The "_" is becoming a keyword in Java, which causes tons of warnings
currently in our test suite.  GNU Gettext is now using "i18n" instead
of "_"
(https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=e89fea36545f27487d9652a13e6a0adbea1117d0).

* data/skeletons/java.m4: Use "i18n", not "_".
* examples/java/calc/Calc.y, tests/calc.at: Adjust.
2020-03-30 08:03:10 +02:00
Akim Demaille
1045c8d0ef examples: don't use yysyntax_error_arguments
Suggested by Adrian Vogelsgesang.
https://lists.gnu.org/archive/html/bison-patches/2020-02/msg00069.html

* data/skeletons/lalr1.java (Context.EMPTY, Context.getToken): New.
(Context.yyntokens): Rename as...
(Context.NTOKENS): this.
Because (i) all the Java coding styles recommend upper case for
constants, and (ii) the Java Skeleton exposes Lexer.EOF, not
Lexer.YYEOF.
* data/skeletons/yacc.c (yyparse_context_token): New.
* examples/c/bistromathic/parse.y (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
* examples/java/calc/Calc.y (yyreportSyntaxError): Likewise.
2020-03-28 15:13:27 +01:00
Akim Demaille
84b1972c96 yacc.c: use negative numbers for errors in auxiliary functions
yyparse returns 0, 1, 2 since ages (accept, reject, memory exhausted).
Some of our auxiliary functions such as yy_lac and
yyreport_syntax_error also need to return error codes and also use 0,
1, 2.  Because it uses yy_lac, yyexpected_tokens also needs to return
"problem", "memory exhausted", but in case of success, it needs to
return the number of tokens, so it cannot use 1 and 2 as error code.
Currently it uses -1 and -2, which is later converted into 1 and 2 as
yacc.c expects it.

Let's simplify this and use consistently -1 and -2 for auxiliary
functions that are not exposed (or not yet exposed) to the user.  In
particular this will save the user from having to convert
yyexpected_tokens's -2 into yyreport_syntax_error's 2: both return -1
or -2.

* data/skeletons/yacc.c (yy_lac, yyreport_syntax_error)
(yy_lac_stack_realloc): Return -1, -2 for errors instead of 1, 2.
Adjust callers.
* examples/c/bistromathic/parse.y (yyreport_syntax_error): Do take
error codes into account.
Issue a syntax error message even if we ran out of memory.
* src/parse-gram.y, tests/local.at (yyreport_syntax_error): Adjust.
2020-03-23 07:02:36 +01:00
Akim Demaille
44ac18d136 yacc.c: yypstate_expected_tokens
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).
2020-03-17 19:20:13 +01:00
Akim Demaille
0c3dd3a669 examples: bistromathic: simplify
* examples/c/bistromathic/parse.y (expected_tokens): Remove useless "break".
2020-03-09 07:24:33 +01:00
Akim Demaille
b437b16603 examples: use consistently the GFDL header for readmes
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/calc/README.md, examples/c/lexcalc/README.md,
* examples/c/reccalc/README.md:
Prefer the GFDL banner to the GPL one.
2020-03-06 08:31:34 +01:00
Akim Demaille
2f83ef57f3 yacc.c: push: undefine the pstate macros for the epilogue
* 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.
2020-03-05 07:26:49 +01:00
Akim Demaille
744171ddbf yacc.c: push: initialize the pstate variables in pstate_new
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.
2020-03-05 07:13:23 +01:00
Akim Demaille
67793793e8 bistromathic: properly compute the lcp, as expected by readline
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.
2020-03-04 08:24:36 +01:00
Akim Demaille
f334775dbf bistromathic: don't require spaces after operators for completion
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.
2020-03-04 08:24:35 +01:00
Akim Demaille
feb1011c8b bistromathic: check completion
* examples/c/bistromathic/bistromathic.test: here.
* examples/c/bistromathic/parse.y (expected_tokens): Fix a memory
leak.
2020-03-02 06:58:25 +01:00
Akim Demaille
5789f9d91e examples: bistromathic: demonstrate the use of yyexpected_tokens
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.
2020-03-01 12:31:39 +01:00
Akim Demaille
b269a45fa4 examples: use consistently the GFDL header for readmes
* examples/c++/README.md, examples/c++/calc++/README.md,
* examples/c/calc/README.md, examples/c/lexcalc/README.md,
* examples/c/pushcalc/README.md, examples/c/reccalc/README.md:
Prefer the GFDL banner to the GPL one.
2020-03-01 07:56:02 +01:00
Akim Demaille
535281f0ff examples: bistromathic: don't use Flex
This example will soon use GNU readline, so its scanner should be easy
to use (concurrently) on strings, not streams.  This is not a place
where Flex shines, and anyway, these are examples of Bison, not Flex.
There's already lexcalc and reccalc that demonstrate the use of Flex.

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

* examples/c/lexcalc/lexcalc.test, examples/c/lexcalc/parse.y,
* examples/c/lexcalc/scan.l: Demonstrate location tracking as is done
in bistromathic.
2020-02-29 12:15:19 +01:00
Akim Demaille
15e57d9108 examples: fix c/calc
* examples/c/calc/calc.y: Remove experiment traces.
2020-02-19 14:58:39 +01:00
Akim Demaille
e7a202d762 examples: bistromathic: demonstrate named references
* examples/c/bistromathic/parse.y: here.
2020-02-12 00:18:47 +01:00
Akim Demaille
163a35d6dd java: beware not to alias the locations of the various symbols
* examples/java/calc/Calc.y, tests/calc.at, tests/local.at
(getStartPos, getEndPos): Always return a new object.
* doc/bison.texi: Clarify this.
2020-02-11 21:31:44 +01:00
Akim Demaille
126252333d java: don't expose the Context's members
* data/skeletons/lalr1.java (Context): Make data members private.
(Context.getLocation): New.
* examples/java/calc/Calc.y, tests/java.at, tests/local.at: Adjust.
2020-02-11 08:39:03 +01:00
Akim Demaille
80a4389377 java: provide Context with a more OO interface
* data/skeletons/lalr1.java (yyexpectedTokens)
(yysyntaxErrorArguments): Make them methods of Context.
(Context.yysymbolName): New.
* tests/local.at: Adjust.
2020-02-08 16:17:53 +01:00
Akim Demaille
ef097719ea java: add support for parse.error custom
* 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.
2020-02-08 16:03:50 +01:00
Akim Demaille
52db24b2bc java: add support for parse.error=detailed
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.
2020-02-08 11:24:53 +01:00
Akim Demaille
f705e9abdb java: style: prefer putting the square brackets on the type
* examples/java/calc/Calc.y, examples/java/simple/Calc.y,
* tests/calc.at, tests/local.at: here.
2020-02-05 13:17:00 +01:00
Akim Demaille
d6f576102e java: examples: fix the tracking of locations
* 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.
2020-02-05 13:17:00 +01:00
Akim Demaille
0f587e9931 java: examples: prefer switch to chains of else-if
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: here.
* examples/java/simple/Calc.y: Use the tokenizer's handling of blanks.
2020-02-05 13:17:00 +01:00
Akim Demaille
48be689a73 java: examples: split in two
* examples/java: Split in...
* examples/java/simple, examples/java/calc: these.
2020-02-05 13:17:00 +01:00
Akim Demaille
37aeda6fb3 traces: show the stack after reading a token
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.
2020-02-05 06:48:42 +01:00
Akim Demaille
c16fcaf2fb java: example: properly track the locations
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.
2020-02-02 11:33:13 +01:00
Akim Demaille
7e99f67592 java: example: improve
* examples/java/Calc.y: Propagate the exit status.
Support -p.
2020-02-02 11:33:03 +01:00
Akim Demaille
d5f929d407 java: example: rely on autoboxing
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.
2020-02-02 11:32:55 +01:00
Akim Demaille
493359b758 examples: bistromathic: fix location tracking
* examples/c/bistromathic/scan.l (LOCATION_STEP): New.
Use to properly ignore blanks.
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-02-02 11:28:45 +01:00
Akim Demaille
3197d0fac9 examples: be more robust to spaces in paths
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.
2020-01-27 07:22:22 +01:00
Akim Demaille
f374310119 examples: add a complete example with all the bells and whistles
* 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.
2020-01-27 06:41:11 +01:00