-
Notifications
You must be signed in to change notification settings - Fork 2
/
scanner.h
44 lines (33 loc) · 915 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
#ifndef __CLOX_SCANNER__
#define __CLOX_SCANNER__
#include <string>
#include <vector>
#include "token.h"
class Scanner {
const std::string &source;
size_t start, current, line; // current is the char we're about to consume
bool badbit;
std::string errorMessage;
std::vector<Token> tokens;
std::string get_lexeme(TokenType type);
char advance();
char peek();
char peekNext();
bool match(char expected);
void error(std::string message);
inline bool eof() { return current == source.size(); }
void string();
void number();
void readChar();
void identifierOrKeyword();
void addToken(TokenType type);
void scanToken();
public:
Scanner(const std::string &source) : source(source) {
start = current = line = badbit = 0;
}
inline bool good() { return !badbit; }
inline std::string getError() { return errorMessage; }
std::vector<Token> scanTokens();
};
#endif