tokens: properly define the YYEOF token kind

Currently EOF is handled in an adhoc way, with a #define YYEOF 0 in
the implementation file.  As a result, the user has to define her own
EOF token if she wants to use it, which is a pity.

Give the $end token a visible kind name, YYEOF.  Except that in C,
where enums are not scoped, we would have collisions between all the
definitions of YYEOFs in the header files, so in C, make it
<api.PREFIX>EOF.

* data/skeletons/c.m4 (YYEOF): Override its name to avoid collisions.
Unless the user already gave it a different name.
* data/skeletons/glr.c (YYEOF): Remove.
Use ]b4_symbol(0, [id])[ instead.
Add support for "pre_epilogue", for glr.cc.
* data/skeletons/glr.cc: Remove dead code (never emitted #undefs).
* data/skeletons/yacc.c
* src/parse-gram.c
* src/reader.c
* src/symtab.c
* tests/actions.at
* tests/input.at
This commit is contained in:
Akim Demaille
2020-04-10 18:31:07 +02:00
parent 95421df67b
commit e50de09886
11 changed files with 70 additions and 28 deletions

View File

@@ -431,8 +431,11 @@ static const b4_int_type_for([$2]) yy$1[[]] =
## ------------- ##
# Because C enums are not scoped, because tokens are exposed in the
# header, and because these tokens are common to all the parser, we
# header, and because these tokens are common to all the parsers, we
# need to make sure their names don't collide: use the api.prefix.
# YYEOF is special, since the user may give it a different name.
m4_if(b4_symbol(0, id), [YYEOF],
[m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])])
m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][ERRCODE]])
m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]])