mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 10:13:03 +00:00
NEWS: named constructors are preferable to symbol_type ctors
Reported by Frank Heckenbach. http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00043.html
This commit is contained in:
23
NEWS
23
NEWS
@@ -223,17 +223,18 @@ GNU Bison NEWS
|
|||||||
symbol_type (int token, const int&);
|
symbol_type (int token, const int&);
|
||||||
symbol_type (int token);
|
symbol_type (int token);
|
||||||
|
|
||||||
which should be used in a Flex-scanner as follows.
|
|
||||||
|
|
||||||
%%
|
|
||||||
[a-z]+ return yy::parser::symbol_type (ID, yytext);
|
|
||||||
[0-9]+ return yy::parser::symbol_type (INT, text_to_int (yytext);
|
|
||||||
":" return yy::parser::symbol_type (’:’);
|
|
||||||
<<EOF>> return yy::parser::symbol_type (0);
|
|
||||||
|
|
||||||
Correct matching between token types and value types is checked via
|
Correct matching between token types and value types is checked via
|
||||||
'assert'. For instance, 'symbol_type (ID, 42)' would abort (while
|
'assert'; for instance, 'symbol_type (ID, 42)' would abort. Named
|
||||||
'make_ID (42)' would not even compile).
|
constructors are preferable, as they offer better type safety (for
|
||||||
|
instance 'make_ID (42)' would not even compile), but symbol_type
|
||||||
|
constructors may help when token types are discovered at run-time, e.g.,
|
||||||
|
|
||||||
|
[a-z]+ {
|
||||||
|
if (auto i = lookup_keyword (yytext))
|
||||||
|
return yy::parser::symbol_type (i);
|
||||||
|
else
|
||||||
|
return yy::parser::make_ID (yytext);
|
||||||
|
}
|
||||||
|
|
||||||
*** C++: Variadic emplace
|
*** C++: Variadic emplace
|
||||||
|
|
||||||
@@ -3486,7 +3487,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE
|
LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE
|
||||||
LocalWords: XXLTYPE strictfp IDEs ffixit fdiagnostics parseable fixits
|
LocalWords: XXLTYPE strictfp IDEs ffixit fdiagnostics parseable fixits
|
||||||
LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
|
LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
|
||||||
LocalWords: noexcept constexpr ispell american
|
LocalWords: noexcept constexpr ispell american deprecations
|
||||||
|
|
||||||
Local Variables:
|
Local Variables:
|
||||||
ispell-dictionary: "american"
|
ispell-dictionary: "american"
|
||||||
|
|||||||
Reference in New Issue
Block a user