summaryrefslogtreecommitdiff
path: root/doc/bison.texi
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-02-10 18:38:42 +0100
committerAkim Demaille <akim.demaille@gmail.com>2020-02-10 20:15:46 +0100
commit77bdcc6f0c857d133cea1d9257efe7d8be39de1d (patch)
tree50daf55f3c4d74dc44f95077c88a10f129d5153e /doc/bison.texi
parent57647bb6565dcb1e3d293b7211ad1b06beaa7f82 (diff)
downloadbison-77bdcc6f0c857d133cea1d9257efe7d8be39de1d.tar.gz
parse.error: document and diagnose the incompatibility with %token-table
* doc/bison.texi (Tokens from Literals): Move to code using %token-table to... (Decl Summary: %token-table): here. * data/skeletons/bison.m4: Implement mutual exclusion. * tests/input.at: Check it. * doc/local.mk: Be robust to the removal of doc/.
Diffstat (limited to 'doc/bison.texi')
-rw-r--r--doc/bison.texi48
1 files changed, 25 insertions, 23 deletions
diff --git a/doc/bison.texi b/doc/bison.texi
index 37853834..678101a3 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -5780,6 +5780,8 @@ This is similar to how most shells resolve commands.
@end deffn
@deffn {Directive} %token-table
+This feature is obsolescent, avoid it in new projects.
+
Generate an array of token names in the parser implementation file. The
name of the array is @code{yytname}; @code{yytname[@var{i}]} is the name of
the token whose internal Bison token code number is @var{i}. The first
@@ -5809,6 +5811,29 @@ The number of grammar rules,
@item YYNSTATES
The number of parser states (@pxref{Parser States}).
@end table
+
+Here's code for looking up a multicharacter token in @code{yytname},
+assuming that the characters of the token are stored in @code{token_buffer},
+and assuming that the token does not contain any characters like @samp{"}
+that require escaping.
+
+@example
+for (int i = 0; i < YYNTOKENS; i++)
+ if (yytname[i]
+ && yytname[i][0] == '"'
+ && ! strncmp (yytname[i] + 1, token_buffer,
+ strlen (token_buffer))
+ && yytname[i][strlen (token_buffer) + 1] == '"'
+ && yytname[i][strlen (token_buffer) + 2] == 0)
+ break;
+@end example
+
+This method is discouraged: the primary purpose of string aliases is forging
+good error messages, not describing the spelling of keywords. In addition,
+looking for the token type at runtime incurs a (small but noticeable) cost.
+
+Finally, @code{%token-table} is incompatible with the @code{custom} and
+@code{detailed} values of the @code{parse.error} @code{%define} variable.
@end deffn
@deffn {Directive} %verbose
@@ -7089,29 +7114,6 @@ forging good error messages, not describing the spelling of keywords. In
addition, looking for the token type at runtime incurs a (small but
noticeable) cost.
-The index of the token in the table is the token type's code. The name of a
-multicharacter token is recorded in @code{yytname} with a double-quote, the
-token's characters, and another double-quote. The token's characters are
-escaped as necessary to be suitable as input to Bison.
-
-Here's code for looking up a multicharacter token in @code{yytname},
-assuming that the characters of the token are stored in @code{token_buffer},
-and assuming that the token does not contain any characters like @samp{"}
-that require escaping.
-
-@example
-for (int i = 0; i < YYNTOKENS; i++)
- @{
- if (yytname[i]
- && yytname[i][0] == '"'
- && ! strncmp (yytname[i] + 1, token_buffer,
- strlen (token_buffer))
- && yytname[i][strlen (token_buffer) + 1] == '"'
- && yytname[i][strlen (token_buffer) + 2] == 0)
- break;
- @}
-@end example
-
The @code{yytname} table is generated only if you use the
@code{%token-table} declaration. @xref{Decl Summary}.
@end itemize