diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2010-12-21 18:51:45 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2010-12-21 18:51:45 +0000 |
commit | 093e6632429ed7fdadf22e031875aef628f261fc (patch) | |
tree | fd03e871f8e2a43bf63c47a52f4f4df9b92291dd /gcc | |
parent | 3868d6bfa679afaf881699faa86ea73dc5bd441f (diff) | |
download | gcc-093e6632429ed7fdadf22e031875aef628f261fc.zip gcc-093e6632429ed7fdadf22e031875aef628f261fc.tar.gz gcc-093e6632429ed7fdadf22e031875aef628f261fc.tar.bz2 |
Correct lexing of exponents.
From-SVN: r168129
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/lex.cc | 25 | ||||
-rw-r--r-- | gcc/go/gofrontend/lex.h | 3 |
2 files changed, 25 insertions, 3 deletions
diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc index ad1a1fe..67d4b1b 100644 --- a/gcc/go/gofrontend/lex.cc +++ b/gcc/go/gofrontend/lex.cc @@ -931,6 +931,25 @@ Lex::is_hex_digit(char c) || (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 @@ 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); mpz_t val; @@ -1004,7 +1023,7 @@ Lex::gather_number() ++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 @@ Lex::gather_number() ++p; } - if (dot && (*p == 'E' || *p == 'e')) + if (dot && Lex::could_be_exponent(p, pend)) { ++p; if (*p == '+' || *p == '-') diff --git a/gcc/go/gofrontend/lex.h b/gcc/go/gofrontend/lex.h index c8def2b..4202ed3 100644 --- a/gcc/go/gofrontend/lex.h +++ b/gcc/go/gofrontend/lex.h @@ -379,6 +379,9 @@ class Lex Token gather_identifier(); + static bool + could_be_exponent(const char*, const char*); + Token gather_number(); |