summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2019-02-04 12:26:35 +0100
committerAkim Demaille <akim.demaille@gmail.com>2019-05-25 10:28:12 +0200
commitaa21c457f2d8e9d45786353cec7f31dd1c873b54 (patch)
tree81b8377dd9f5cbcadd8ce55e6b3c0e7e8dfbdade /doc
parent9f26e6d6b35fd844e451b087fcac6e70703a5c16 (diff)
downloadbison-aa21c457f2d8e9d45786353cec7f31dd1c873b54.tar.gz
doc: clarify the purpose of symbol_type constructors
Reported by Frank Heckenbach. http://lists.gnu.org/archive/html/bug-bison/2019-02/msg00006.html * doc/bison.texi (Complete Symbols): Here.
Diffstat (limited to 'doc')
-rw-r--r--doc/bison.texi20
1 files changed, 13 insertions, 7 deletions
diff --git a/doc/bison.texi b/doc/bison.texi
index 579f2083..0301a96c 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -11732,15 +11732,21 @@ symbol_type (int token, const int&, const location_type&);
symbol_type (int token, const location_type&);
@end example
-@noindent
-which should be used in a Flex-scanner as follows.
+Correct matching between token types and value types is checked via
+@code{assert}; for instance, @samp{symbol_type (ID, 42)} would abort. Named
+constructors are preferable (see below), as they offer better type safety
+(for instance @samp{make_ID (42)} would not even compile), but symbol_type
+constructors may help when token types are discovered at run-time, e.g.,
@example
-%%
-[a-z]+ return yy::parser::symbol_type (TOK_IDENTIFIER, yytext, loc);
-[0-9]+ return yy::parser::symbol_type (TOK_INTEGER, text_to_int (yytext), loc);
-":" return yy::parser::symbol_type (':', loc);
-<<EOF>> return yy::parser::symbol_type (0, loc);
+@group
+[a-z]+ @{
+ if (auto i = lookup_keyword (yytext))
+ return yy::parser::symbol_type (i, loc);
+ else
+ return yy::parser::make_ID (yytext, loc);
+ @}
+@end group
@end example
@sp 1