diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-09-27 20:12:52 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-09-27 20:12:52 +0000 |
commit | d116d8a4e9120bc8e431154f40964f9332074071 (patch) | |
tree | 502a9127f2dc0e2607de627fd685d318a8c970ab /llvm/lib/MC/MCParser/AsmLexer.cpp | |
parent | cb67d7b7c22be6dfc93a2eed3f27b43e7dda0e3f (diff) | |
download | llvm-d116d8a4e9120bc8e431154f40964f9332074071.zip llvm-d116d8a4e9120bc8e431154f40964f9332074071.tar.gz llvm-d116d8a4e9120bc8e431154f40964f9332074071.tar.bz2 |
MC/AsmParser: Handle exponents in floating point literals.
llvm-svn: 114861
Diffstat (limited to 'llvm/lib/MC/MCParser/AsmLexer.cpp')
-rw-r--r-- | llvm/lib/MC/MCParser/AsmLexer.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp index 1a71d24..7ca1ccc 100644 --- a/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -64,6 +64,31 @@ int AsmLexer::getNextChar() { } } +/// LexFloatLiteral: [0-9]*[.][0-9]*([eE][+-]?[0-9]*)? +/// +/// The leading integral digit sequence and dot should have already been +/// consumed, some or all of the fractional digit sequence *can* have been +/// consumed. +AsmToken AsmLexer::LexFloatLiteral() { + // Skip the fractional digit sequence. + while (isdigit(*CurPtr)) + ++CurPtr; + + // Check for exponent; we intentionally accept a slighlty wider set of + // literals here and rely on the upstream client to reject invalid ones (e.g., + // "1e+"). + if (*CurPtr == 'e' || *CurPtr == 'E') { + ++CurPtr; + if (*CurPtr == '-' || *CurPtr == '+') + ++CurPtr; + while (isdigit(*CurPtr)) + ++CurPtr; + } + + return AsmToken(AsmToken::Real, + StringRef(TokStart, CurPtr - TokStart)); +} + /// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* static bool IsIdentifierChar(char c) { return isalnum(c) || c == '_' || c == '$' || c == '.' || c == '@'; @@ -71,12 +96,11 @@ static bool IsIdentifierChar(char c) { AsmToken AsmLexer::LexIdentifier() { // Check for floating point literals. if (CurPtr[-1] == '.' && isdigit(*CurPtr)) { + // Disambiguate a .1243foo identifier from a floating literal. while (isdigit(*CurPtr)) ++CurPtr; - if (!IsIdentifierChar(*CurPtr)) { - return AsmToken(AsmToken::Real, - StringRef(TokStart, CurPtr - TokStart)); - } + if (*CurPtr == 'e' || *CurPtr == 'E' || !IsIdentifierChar(*CurPtr)) + return LexFloatLiteral(); } while (IsIdentifierChar(*CurPtr)) @@ -150,12 +174,9 @@ AsmToken AsmLexer::LexDigit() { ++CurPtr; // Check for floating point literals. - if (*CurPtr == '.') { + if (*CurPtr == '.' || *CurPtr == 'e') { ++CurPtr; - while (isdigit(*CurPtr)) - ++CurPtr; - - return AsmToken(AsmToken::Real, StringRef(TokStart, CurPtr - TokStart)); + return LexFloatLiteral(); } StringRef Result(TokStart, CurPtr - TokStart); |