klee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Lexer.h
Go to the documentation of this file.
1 //===-- Lexer.h -------------------------------------------------*- C++ -*-===//
2 //
3 // The KLEE Symbolic Virtual Machine
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef KLEE_EXPR_LEXER_H
11 #define KLEE_EXPR_LEXER_H
12 
13 #include <string>
14 
15 namespace llvm {
16  class MemoryBuffer;
17 }
18 
19 namespace klee {
20 namespace expr {
21  struct Token {
22  enum Kind {
23  At,
47 
50  };
51 
53  const char *start;
54  unsigned length;
55  unsigned line;
56  unsigned column;
57 
60  const char *getKindName() const;
61 
64  std::string getString() const { return std::string(start, length); }
65 
67  bool isKeyword() const {
68  return kind >= KWKindFirst && kind <= KWKindLast;
69  }
70 
71  // dump - Dump the token to stderr.
72  void dump();
73  };
74 
76  class Lexer {
77  const char *BufferPos;
78  const char *BufferEnd;
79  unsigned LineNumber;
80  unsigned ColumnNumber;
81 
83  int GetNextChar();
84 
88  int PeekNextChar();
89 
92  Token &SetTokenKind(Token &Result, Token::Kind k);
93 
98 
99  void SkipToEndOfLine();
100 
102  Token &LexNumber(Token &Result);
103 
105  Token &LexIdentifier(Token &Result);
106 
107  public:
108  explicit Lexer(const llvm::MemoryBuffer *_buf);
109  ~Lexer();
110 
114  Token &Lex(Token &Result);
115  };
116 }
117 }
118 
119 #endif
unsigned LineNumber
The buffer end position.
Definition: Lexer.h:79
unsigned line
The length of the token.
Definition: Lexer.h:55
int PeekNextChar()
Definition: Lexer.cpp:74
Lexer(const llvm::MemoryBuffer *_buf)
Definition: Lexer.cpp:66
Token & SetTokenKind(Token &Result, Token::Kind k)
Definition: Lexer.cpp:103
Token & LexNumber(Token &Result)
LexNumber - Lex a number which does not have a base specifier.
Definition: Lexer.cpp:196
int GetNextChar()
The current column.
Definition: Lexer.cpp:80
unsigned length
The beginning of the token string.
Definition: Lexer.h:54
[+-]?[0-9][a-zA-Z0-9_]+
Definition: Lexer.h:41
fp[0-9]+([.].*)?, i[0-9]+
Definition: Lexer.h:34
std::string getString() const
Definition: Lexer.h:64
Token & SetIdentifierTokenKind(Token &Result)
Definition: Lexer.cpp:140
const char * getKindName() const
getKindName - The name of this token's kind.
Definition: Lexer.cpp:24
const char * start
The token kind.
Definition: Lexer.h:53
Lexer - Interface for lexing tokens from a .pc language file.
Definition: Lexer.h:76
unsigned column
The line number of the start of this token.
Definition: Lexer.h:56
bool isKeyword() const
isKeyword - True if this token is a keyword.
Definition: Lexer.h:67
const char * BufferPos
Definition: Lexer.h:77
unsigned ColumnNumber
The current line.
Definition: Lexer.h:80
Token & LexIdentifier(Token &Result)
LexIdentifier - Lex an identifier.
Definition: Lexer.cpp:202
const char * BufferEnd
The current lexer position.
Definition: Lexer.h:78
[a-zA-Z_][a-zA-Z0-9._]*
Definition: Lexer.h:30
Token & Lex(Token &Result)
Definition: Lexer.cpp:210
void SkipToEndOfLine()
Definition: Lexer.cpp:188