-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanner.h
More file actions
40 lines (35 loc) · 875 Bytes
/
Scanner.h
File metadata and controls
40 lines (35 loc) · 875 Bytes
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
//
// Created by ryousuke kaga on 2023/11/06.
//
#ifndef INTERPRETER_IN_CPP_SCANNER_H
#define INTERPRETER_IN_CPP_SCANNER_H
#include <vector>
#include <utility>
#include "Token.h"
#include "Interpreter.h"
#include "Literal.h"
class Scanner {
public:
Scanner(std::string source);
void scanToken();
std::vector<Token> scanTokens();
private:
bool isAtEnd();
char advance();
bool match(char expected);
char peek();
char peekNext();
void addToken(TokenType type, const std::shared_ptr<Literal>& literal);
void string();
void number();
bool isAlpha(char c);
bool isAlphaNumeric(char c);
void identifier();
std::string source;
std::vector<Token> tokens;
int start = 0;
int current = 0;
int line = 1;
std::unordered_map<std::string, TokenType> nameTokenMap;
};
#endif //INTERPRETER_IN_CPP_SCANNER_H