Commit 093e6632 by Ian Lance Taylor

Correct lexing of exponents.

From-SVN: r168129
parent 3868d6bf
...@@ -931,6 +931,25 @@ Lex::is_hex_digit(char c) ...@@ -931,6 +931,25 @@ Lex::is_hex_digit(char c)
|| (c >= 'a' && c <= 'f')); || (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. // Pick up a number.
Token Token
...@@ -980,7 +999,7 @@ Lex::gather_number() ...@@ -980,7 +999,7 @@ Lex::gather_number()
} }
} }
if (*p != '.' && *p != 'e' && *p != 'E' && *p != 'i') if (*p != '.' && *p != 'i' && !Lex::could_be_exponent(p, pend))
{ {
std::string s(pnum, p - pnum); std::string s(pnum, p - pnum);
mpz_t val; mpz_t val;
...@@ -1004,7 +1023,7 @@ Lex::gather_number() ...@@ -1004,7 +1023,7 @@ Lex::gather_number()
++p; ++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); std::string s(pnum, p - pnum);
mpz_t val; mpz_t val;
...@@ -1039,7 +1058,7 @@ Lex::gather_number() ...@@ -1039,7 +1058,7 @@ Lex::gather_number()
++p; ++p;
} }
if (dot && (*p == 'E' || *p == 'e')) if (dot && Lex::could_be_exponent(p, pend))
{ {
++p; ++p;
if (*p == '+' || *p == '-') if (*p == '+' || *p == '-')
......
...@@ -379,6 +379,9 @@ class Lex ...@@ -379,6 +379,9 @@ class Lex
Token Token
gather_identifier(); gather_identifier();
static bool
could_be_exponent(const char*, const char*);
Token Token
gather_number(); gather_number();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment