This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Correct exponent lexing
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Tue, 21 Dec 2010 10:51:48 -0800
- Subject: Go patch committed: Correct exponent lexing
This patch to the Go frontend corrects the lexing of exponents in
floating point numbers. An exponent requires at least one decimal
digit after an optional sign. Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r 5e30b192004f go/lex.cc
--- a/go/lex.cc Tue Dec 21 10:30:04 2010 -0800
+++ b/go/lex.cc Tue Dec 21 10:48:10 2010 -0800
@@ -931,6 +931,25 @@
|| (c >= 'a' && c <= 'f'));
}
+// Return whether an exponent could start at P.
+
+bool
+Lex::could_be_exponent(const char* p, const char* pend)
+{
+ if (*p != 'e' && *p != 'E')
+ return false;
+ ++p;
+ if (p >= pend)
+ return false;
+ if (*p == '+' || *p == '-')
+ {
+ ++p;
+ if (p >= pend)
+ return false;
+ }
+ return *p >= '0' && *p <= '9';
+}
+
// Pick up a number.
Token
@@ -980,7 +999,7 @@
}
}
- if (*p != '.' && *p != 'e' && *p != 'E' && *p != 'i')
+ if (*p != '.' && *p != 'i' && !Lex::could_be_exponent(p, pend))
{
std::string s(pnum, p - pnum);
mpz_t val;
@@ -1004,7 +1023,7 @@
++p;
}
- if (*p != '.' && *p != 'E' && *p != 'e' && *p != 'i')
+ if (*p != '.' && *p != 'i' && !Lex::could_be_exponent(p, pend))
{
std::string s(pnum, p - pnum);
mpz_t val;
@@ -1039,7 +1058,7 @@
++p;
}
- if (dot && (*p == 'E' || *p == 'e'))
+ if (dot && Lex::could_be_exponent(p, pend))
{
++p;
if (*p == '+' || *p == '-')
diff -r 5e30b192004f go/lex.h
--- a/go/lex.h Tue Dec 21 10:30:04 2010 -0800
+++ b/go/lex.h Tue Dec 21 10:48:10 2010 -0800
@@ -379,6 +379,9 @@
Token
gather_identifier();
+ static bool
+ could_be_exponent(const char*, const char*);
+
Token
gather_number();