klee
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_LEXER_H
11#define KLEE_LEXER_H
12
13#include <string>
14
15namespace llvm {
16 class MemoryBuffer;
17}
18
19namespace klee {
20namespace expr {
21 struct Token {
22 enum Kind {
47
50 };
51
53 const char *start;
54 unsigned length;
55 unsigned line;
56 unsigned column;
58
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 Token() : kind(Unknown), start(nullptr) {}
75 };
76
78 class Lexer {
79 const char *BufferPos;
80 const char *BufferEnd;
81 unsigned LineNumber;
82 unsigned ColumnNumber;
83
85 int GetNextChar();
86
90 int PeekNextChar();
91
95
100
101 void SkipToEndOfLine();
102
104 Token &LexNumber(Token &Result);
105
107 Token &LexIdentifier(Token &Result);
108
109 public:
110 explicit Lexer(const llvm::MemoryBuffer *_buf);
111 ~Lexer();
112
116 Token &Lex(Token &Result);
117 };
118}
119}
120
121#endif /* KLEE_LEXER_H */
Lexer - Interface for lexing tokens from a .kquery language file.
Definition: Lexer.h:78
void SkipToEndOfLine()
Definition: Lexer.cpp:188
Token & SetTokenKind(Token &Result, Token::Kind k)
Definition: Lexer.cpp:103
int PeekNextChar()
Definition: Lexer.cpp:74
const char * BufferPos
Definition: Lexer.h:79
unsigned ColumnNumber
The current line.
Definition: Lexer.h:82
unsigned LineNumber
The buffer end position.
Definition: Lexer.h:81
const char * BufferEnd
The current lexer position.
Definition: Lexer.h:80
int GetNextChar()
The current column.
Definition: Lexer.cpp:80
Token & LexNumber(Token &Result)
LexNumber - Lex a number which does not have a base specifier.
Definition: Lexer.cpp:196
Lexer(const llvm::MemoryBuffer *_buf)
Definition: Lexer.cpp:66
Token & Lex(Token &Result)
Definition: Lexer.cpp:210
Token & SetIdentifierTokenKind(Token &Result)
Definition: Lexer.cpp:140
Token & LexIdentifier(Token &Result)
LexIdentifier - Lex an identifier.
Definition: Lexer.cpp:202
Definition: main.cpp:291
const char * start
The token kind.
Definition: Lexer.h:53
unsigned column
The line number of the start of this token.
Definition: Lexer.h:56
unsigned line
The length of the token.
Definition: Lexer.h:55
const char * getKindName() const
getKindName - The name of this token's kind.
Definition: Lexer.cpp:24
unsigned length
The beginning of the token string.
Definition: Lexer.h:54
bool isKeyword() const
isKeyword - True if this token is a keyword.
Definition: Lexer.h:67
std::string getString() const
Definition: Lexer.h:64
@ Arrow
'->'
Definition: Lexer.h:24
@ KWFalse
'false'
Definition: Lexer.h:32
@ KWQuery
'query'
Definition: Lexer.h:33
@ Unknown
<other>
Definition: Lexer.h:46
@ RSquare
']'
Definition: Lexer.h:44
@ Comment
#[^ ]+
Definition: Lexer.h:27
@ KWArray
'array'
Definition: Lexer.h:31
@ Number
[+-]?[0-9][a-zA-Z0-9_]+
Definition: Lexer.h:41
@ EndOfFile
<end of file>
Definition: Lexer.h:28
@ Identifier
[a-zA-Z_][a-zA-Z0-9._]*
Definition: Lexer.h:30
@ Semicolon
';'
Definition: Lexer.h:45
@ Equals
' = '
Definition: Lexer.h:29
@ KWSymbolic
'symbolic'
Definition: Lexer.h:35
@ KWWidth
w[0-9]+
Definition: Lexer.h:37
@ KWReserved
fp[0-9]+([.].*)?, i[0-9]+
Definition: Lexer.h:34
@ KWTrue
'true'
Definition: Lexer.h:36
@ LSquare
'['
Definition: Lexer.h:40