12#include "llvm/Support/MemoryBuffer.h"
13#include "llvm/Support/raw_ostream.h"
24const char *Token::getKindName()
const {
28 case Arrow:
return "Arrow";
30 case Colon:
return "Colon";
31 case Comma:
return "Comma";
34 case Equals:
return "Equals";
41 case KWTrue:
return "KWTrue";
43 case LBrace:
return "LBrace";
44 case LParen:
return "LParen";
46 case Number:
return "Number";
47 case RBrace:
return "RBrace";
48 case RParen:
return "RParen";
55 llvm::errs() <<
"(Token \"" <<
getKindName() <<
"\" "
63 return isalnum(Char) || Char ==
'_' || Char ==
'.' || Char ==
'-';
67 : BufferPos(MB->getBufferStart()), BufferEnd(MB->getBufferEnd()),
68 LineNumber(1), ColumnNumber(0) {
87 if (Result ==
'\n' || Result ==
'\r') {
113 if (N>1 && Str[0] ==
'i') {
115 if (!isdigit(Str[i]))
122 if (N>3 && Str[0]==
'f' && Str[1]==
'p' && isdigit(Str[2])) {
124 if (!isdigit(Str[i]))
126 if (i==N || Str[i]==
'.')
133 if (N<2 || Str[0] !=
'w')
135 for (
unsigned i=1; i<N; ++i)
136 if (!isdigit(Str[i]))
144 if (memcmp(
"def", Result.
start, 3) == 0)
146 if (memcmp(
"var", Result.
start, 3) == 0)
151 if (memcmp(
"true", Result.
start, 4) == 0)
156 if (memcmp(
"array", Result.
start, 5) == 0)
158 if (memcmp(
"false", Result.
start, 5) == 0)
160 if (memcmp(
"query", Result.
start, 5) == 0)
165 if (memcmp(
"define", Result.
start, 6) == 0)
170 if (memcmp(
"declare", Result.
start, 7) == 0)
175 if (memcmp(
"symbolic", Result.
start, 8) == 0)
191 if (Char == -1 || Char ==
'\n')
253 else if (isdigit(Next))
263 else if (isalpha(Char) || Char ==
'_')
static bool isReservedKW(const char *Str, unsigned N)
static bool isWidthKW(const char *Str, unsigned N)
static bool isInternalIdentifierChar(int Char)
Token & SetTokenKind(Token &Result, Token::Kind k)
unsigned ColumnNumber
The current line.
unsigned LineNumber
The buffer end position.
const char * BufferEnd
The current lexer position.
int GetNextChar()
The current column.
Token & LexNumber(Token &Result)
LexNumber - Lex a number which does not have a base specifier.
Lexer(const llvm::MemoryBuffer *_buf)
Token & Lex(Token &Result)
Token & SetIdentifierTokenKind(Token &Result)
Token & LexIdentifier(Token &Result)
LexIdentifier - Lex an identifier.
const char * start
The token kind.
unsigned column
The line number of the start of this token.
unsigned line
The length of the token.
const char * getKindName() const
getKindName - The name of this token's kind.
unsigned length
The beginning of the token string.
@ Number
[+-]?[0-9][a-zA-Z0-9_]+
@ Identifier
[a-zA-Z_][a-zA-Z0-9._]*
@ KWReserved
fp[0-9]+([.].*)?, i[0-9]+