From 84a1cb5ad0f8b741d5a891df9bbf51bd1cc44ac3 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 4 May 2009 21:23:55 +0200 Subject: [PATCH] bison: catch bad symbol names. * src/scan-gram.l({int}{id}): Report as an invalid identifier. * tests/input.at: Adjust. --- ChangeLog | 8 +++++++- src/scan-gram.l | 6 ++++++ tests/input.at | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd1799a9..bf412806 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,14 @@ +2009-05-04 Akim Demaille + + bison: catch bad symbol names. + * src/scan-gram.l({int}{id}): Report as an invalid identifier. + * tests/input.at: Adjust. + 2009-05-04 Akim Demaille identifiers: dashes are letters. Dashes can now start identifiers (symbols and directives). - + * src/scan-gram.l ({letter}): Add dash. ({id}): Remove it. * tests/input.at (Symbols): Adjust. diff --git a/src/scan-gram.l b/src/scan-gram.l index 5d4b4b30..7c5b6000 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -240,6 +240,12 @@ splice (\\[ \f\t\v]*\n)* return INT; } + /* Identifiers may not start with a digit. Yet, don't silently + accept "1FOO" as "1 FOO". */ + {int}{id} { + complain_at (*loc, _("invalid identifier: %s"), quote (yytext)); + } + /* Characters. We don't check there is only one. */ "'" STRING_GROW; token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER; diff --git a/tests/input.at b/tests/input.at index 5baa4f97..43f72962 100644 --- a/tests/input.at +++ b/tests/input.at @@ -657,13 +657,13 @@ AT_COMPILE([input.o], [-c input.c]) # Digits cannot. AT_DATA_GRAMMAR([input.y], [[%token .GOOD -%token -GOOD -%token 1NV4L1D + -GOOD + 1NV4L1D %% start: .GOOD -GOOD ]]) AT_BISON_CHECK([-o input.c input.y], [1], [], -[[input.y:11.8: syntax error, unexpected integer, expecting char or identifier or +[[input.y:11.10-16: invalid identifier: `1NV4L1D' ]]) AT_CLEANUP -- 2.47.2