-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.h
57 lines (46 loc) · 859 Bytes
/
scanner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef CS241_SCANNER_H
#define CS241_SCANNER_H
#include <string>
#include <vector>
#include <set>
#include <cstdint>
#include <ostream>
class Token;
std::vector<Token> scan(const std::string &input);
class Token
{
public:
enum Kind
{
ID = 0,
LABEL,
WORD,
COMMA,
LPAREN,
RPAREN,
INT,
HEXINT,
REG,
WHITESPACE,
COMMENT
};
private:
Kind kind;
std::string lexeme;
public:
Token(Kind kind, std::string lexeme);
Kind getKind() const;
const std::string &getLexeme() const;
// Only on INT, HEXINT, and REG
int64_t toLong() const;
};
std::ostream &operator<<(std::ostream &out, const Token &tok);
class ScanningFailure
{
std::string message;
public:
ScanningFailure(std::string message);
// Returns the message associated with the exception.
const std::string &what() const;
};
#endif