diff --git a/data/README.md b/data/README.md index c91fe1c5..5d32b75f 100644 --- a/data/README.md +++ b/data/README.md @@ -83,18 +83,20 @@ field), where field can `has_id`, `id`, etc.: see The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS: -- `has_id`: 0 or 1. - +- `has_id`: 0 or 1 Whether the symbol has an id. - `id`: string If has_id, the id (prefixed by api.token.prefix if defined), otherwise - defined as empty. Guaranteed to be usable as a C identifier. + defined as empty. Guaranteed to be usable as a C identifier. This is + used to define the token kind (i.e., the enum used by the return value of + yylex). -- `tag`: string. - A representation of the symbol. Can be 'foo', 'foo.id', '"foo"' etc. +- `tag`: string + A human representation of the symbol. Can be 'foo', 'foo.id', '"foo"' etc. - `user_number`: integer + The code associated to the `id`. The external number as used by yylex. Can be ASCII code when a character, some number chosen by bison, or some user number in the case of %token FOO . Corresponds to yychar in yacc.c. @@ -102,7 +104,12 @@ The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS: - `is_token`: 0 or 1 Whether this is a terminal symbol. +- `kind`: string + The symbol kind, i.e., the enumerator of this symbol (token or nonterminal) + which is mapping to its `number`. + - `number`: integer + The code associated to the `kind`. The internal number (computed from the external number by yytranslate). Corresponds to yytoken in yacc.c. This is the same number that serves as key in b4_symbol(NUM, FIELD). diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4 index 1bd30dd1..480872fd 100644 --- a/data/skeletons/bison.m4 +++ b/data/skeletons/bison.m4 @@ -405,13 +405,13 @@ m4_define([_b4_symbol], [__b4_symbol([$1], [$2])])]) -# b4_symbol_sid(NUM) -# ------------------ -# Build the symbol ID based for this symbol. It must always exist, +# b4_symbol_kind(NUM) +# ------------------- +# Build the name of the kind of this symbol. It must always exist, # otherwise some symbols might not be represented in the enum, which # might be compiled into too small a type to contain all the symbol # numbers. -m4_define([b4_symbol_sid], +m4_define([b4_symbol_kind], [m4_case([$1], [-2], [[YYSYMBOL_YYEMPTY]], [0], [[YYSYMBOL_YYEOF]], @@ -433,7 +433,7 @@ m4_define([b4_symbol], [m4_case([$2], [id], [m4_do([b4_percent_define_get([api.token.prefix])], [_b4_symbol([$1], [id])])], - [sid], [b4_symbol_sid([$1])], + [kind], [b4_symbol_kind([$1])], [_b4_symbol($@)])]) diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4 index 720977b0..ac074f4b 100644 --- a/data/skeletons/c++.m4 +++ b/data/skeletons/c++.m4 @@ -192,7 +192,7 @@ m4_define([b4_declare_symbol_enum], { ]m4_join([, ], - ]b4_symbol_sid([-2])[ = -2, + ]b4_symbol_kind([-2])[ = -2, b4_symbol_map([b4_symbol_enum]), [YYNTOKENS = ]b4_tokens_number[ ///< Number of tokens.])[ }; diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4 index 2c134365..aeafea4e 100644 --- a/data/skeletons/c.m4 +++ b/data/skeletons/c.m4 @@ -495,9 +495,9 @@ m4_define([b4_symbol_translate], # -------------------------- # Output the definition of this symbol as an enum. m4_define([b4_symbol_enum], -[m4_ifval(b4_symbol([$1], [sid]), +[m4_ifval(b4_symbol([$1], [kind]), [m4_format([[%s = %s]], - b4_symbol([$1], [sid]), + b4_symbol([$1], [kind]), b4_symbol([$1], [number]))])]) @@ -512,7 +512,7 @@ enum yysymbol_kind_t { ]m4_join([, ], - ]b4_symbol_sid([-2])[ = -2, + ]b4_symbol_kind([-2])[ = -2, b4_symbol_map([b4_symbol_enum]))[ }; typedef enum yysymbol_kind_t yysymbol_kind_t; diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4 index b8862cf7..fefe74a1 100644 --- a/data/skeletons/d.m4 +++ b/data/skeletons/d.m4 @@ -181,9 +181,9 @@ b4_symbol_foreach([b4_token_enum]) # -------------------------- # Output the definition of this symbol as an enum. m4_define([b4_symbol_enum], -[m4_ifval(b4_symbol([$1], [sid]), +[m4_ifval(b4_symbol([$1], [kind]), [m4_format([[%s = %s]], - b4_symbol([$1], [sid]), + b4_symbol([$1], [kind]), b4_symbol([$1], [number]))])]) @@ -198,7 +198,7 @@ m4_define([b4_declare_symbol_enum], { ]m4_join([, ], - ]b4_symbol_sid([-2])[ = -2, + ]b4_symbol_kind([-2])[ = -2, b4_symbol_map([b4_symbol_enum]))[ }; ]])]) diff --git a/data/skeletons/java.m4 b/data/skeletons/java.m4 index 47e745ae..3733f261 100644 --- a/data/skeletons/java.m4 +++ b/data/skeletons/java.m4 @@ -157,9 +157,9 @@ b4_symbol_foreach([b4_token_enum])])]) # -------------------------- # Output the definition of this symbol as an enum. m4_define([b4_symbol_enum], -[m4_ifval(b4_symbol([$1], [sid]), +[m4_ifval(b4_symbol([$1], [kind]), [m4_format([[%s(%s)]], - b4_symbol([$1], [sid]), + b4_symbol([$1], [kind]), b4_symbol([$1], [number]))])]) @@ -171,7 +171,7 @@ m4_define([b4_declare_symbol_enum], { ]m4_join([, ], - ]b4_symbol_sid([-2])[(-2), + ]b4_symbol_kind([-2])[(-2), b4_symbol_map([b4_symbol_enum]))[; private final int code_; @@ -181,7 +181,7 @@ m4_define([b4_declare_symbol_enum], } private static final SymbolKind[] values_ = { - ]m4_map_args_sep([b4_symbol_sid(], [)], [, + ]m4_map_args_sep([b4_symbol_kind(], [)], [, ], b4_symbol_numbers)[ };