aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/scng.adb
diff options
context:
space:
mode:
authorRobert Dewar <dewar@adacore.com>2006-10-31 19:05:47 +0100
committerArnaud Charlet <charlet@gcc.gnu.org>2006-10-31 19:05:47 +0100
commitdaca8389efba4b72ee492746f613faa05413dff0 (patch)
treebe795418b7e217fa215dd40df2d2e6621ba8f2cb /gcc/ada/scng.adb
parent1fa4cb204c83e89ecc77d7e94ce22ccc4562c96e (diff)
downloadgcc-daca8389efba4b72ee492746f613faa05413dff0.zip
gcc-daca8389efba4b72ee492746f613faa05413dff0.tar.gz
gcc-daca8389efba4b72ee492746f613faa05413dff0.tar.bz2
scng.adb (Scan, [...]): Better msg for identifier starting with a digit.
2006-10-31 Robert Dewar <dewar@adacore.com> * scng.adb (Scan, case of numeric literal): Better msg for identifier starting with a digit. From-SVN: r118297
Diffstat (limited to 'gcc/ada/scng.adb')
-rw-r--r--gcc/ada/scng.adb48
1 files changed, 47 insertions, 1 deletions
diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb
index ad7f3b3..c4fdd86 100644
--- a/gcc/ada/scng.adb
+++ b/gcc/ada/scng.adb
@@ -477,7 +477,6 @@ package body Scng is
UI_Int_Value := Uint_0;
Scale := 0;
Scan_Integer;
- Scale := 0;
Point_Scanned := False;
UI_Num_Value := UI_Int_Value;
@@ -1741,12 +1740,59 @@ package body Scng is
-- Digits starting a numeric literal
when '0' .. '9' =>
+
+ -- First a bit of a scan ahead to see if we have a case of an
+ -- identifier starting with a digit (remembering exponent case).
+
+ declare
+ C : constant Character := Source (Scan_Ptr + 1);
+
+ begin
+ -- OK literal if digit followed by digit or underscore
+
+ if C in '0' .. '9' or else C = '_' then
+ null;
+
+ -- OK literal if digit not followed by identifier char
+
+ elsif not Identifier_Char (C) then
+ null;
+
+ -- OK literal if digit followed by e/E followed by digit/sign.
+ -- We also allow underscore after the E, which is an error, but
+ -- better handled by Nlit than deciding this is an identifier.
+
+ elsif (C = 'e' or else C = 'E')
+ and then (Source (Scan_Ptr + 2) in '0' .. '9'
+ or else Source (Scan_Ptr + 2) = '+'
+ or else Source (Scan_Ptr + 2) = '-'
+ or else Source (Scan_Ptr + 2) = '_')
+ then
+ null;
+
+ -- Here we have what really looks like an identifier that
+ -- starts with a digit, so give error msg.
+
+ else
+ Error_Msg_S ("identifier may not start with digit");
+ Name_Len := 1;
+ Underline_Found := False;
+ Name_Buffer (1) := Source (Scan_Ptr);
+ Accumulate_Checksum (Name_Buffer (1));
+ Scan_Ptr := Scan_Ptr + 1;
+ goto Scan_Identifier;
+ end if;
+ end;
+
+ -- Here we have an OK integer literal
+
Nlit;
if Identifier_Char (Source (Scan_Ptr)) then
Error_Msg_S
("delimiter required between literal and identifier");
end if;
+
Post_Scan;
return;