diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-09-24 01:59:31 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-09-24 01:59:31 +0000 |
commit | 3068a93dc13954b3092125b52843ac7f602b8f84 (patch) | |
tree | 7121c9d6f92461a7ecb2486d62319da6680584c9 /llvm/lib/MC/MCParser/AsmLexer.cpp | |
parent | 74c1f1192c1f90ba42df5b601e805b9be1e33a5d (diff) | |
download | llvm-3068a93dc13954b3092125b52843ac7f602b8f84.zip llvm-3068a93dc13954b3092125b52843ac7f602b8f84.tar.gz llvm-3068a93dc13954b3092125b52843ac7f602b8f84.tar.bz2 |
MC/Lexer: Add 'Real' token type for floating point literals.
llvm-svn: 114718
Diffstat (limited to 'llvm/lib/MC/MCParser/AsmLexer.cpp')
-rw-r--r-- | llvm/lib/MC/MCParser/AsmLexer.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp index 086df08..59da381 100644 --- a/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -65,9 +65,21 @@ int AsmLexer::getNextChar() { } /// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* +static bool IsIdentifierChar(char c) { + return isalnum(c) || c == '_' || c == '$' || c == '.' || c == '@'; +} AsmToken AsmLexer::LexIdentifier() { - while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' || - *CurPtr == '.' || *CurPtr == '@') + // Check for floating point literals. + if (CurPtr[-1] == '.' && isdigit(*CurPtr)) { + while (isdigit(*CurPtr)) + ++CurPtr; + if (!IsIdentifierChar(*CurPtr)) { + return AsmToken(AsmToken::Real, + StringRef(TokStart, CurPtr - TokStart)); + } + } + + while (IsIdentifierChar(*CurPtr)) ++CurPtr; // Handle . as a special case. @@ -124,7 +136,6 @@ static void SkipIgnoredIntegerSuffix(const char *&CurPtr) { CurPtr += 3; } - /// LexDigit: First character is [0-9]. /// Local Label: [0-9][:] /// Forward/Backward Label: [0-9][fb] @@ -132,13 +143,21 @@ static void SkipIgnoredIntegerSuffix(const char *&CurPtr) { /// Octal integer: 0[0-7]+ /// Hex integer: 0x[0-9a-fA-F]+ /// Decimal integer: [1-9][0-9]* -/// TODO: FP literal. AsmToken AsmLexer::LexDigit() { // Decimal integer: [1-9][0-9]* if (CurPtr[-1] != '0') { while (isdigit(*CurPtr)) ++CurPtr; - + + // Check for floating point literals. + if (*CurPtr == '.') { + ++CurPtr; + while (isdigit(*CurPtr)) + ++CurPtr; + + return AsmToken(AsmToken::Real, StringRef(TokStart, CurPtr - TokStart)); + } + StringRef Result(TokStart, CurPtr - TokStart); long long Value; |