-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.hpp
More file actions
55 lines (51 loc) · 1.2 KB
/
scanner.hpp
File metadata and controls
55 lines (51 loc) · 1.2 KB
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
#pragma once
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include "token.hpp"
#include "debug.hpp"
class Scanner{
private:
int start = 0;
int current =0;
int line =1;
std::string source;
std::vector<Token> tokens;//1
std::unordered_map<std::string,TokenType> keywords = {
// Palavras-chave reservadas
{"and", TokenType::AND},
{"class", TokenType::CLASS},
{"else", TokenType::ELSE},
{"false", TokenType::MY_FALSE},
{"for", TokenType::FOR},
{"fun", TokenType::FUN},
{"if", TokenType::IF},
{"nil", TokenType::NIL},
{"or", TokenType::OR},
{"print", TokenType::PRINT},
{"return", TokenType::RETURN},
{"super", TokenType::SUPER},
{"this", TokenType::THIS},
{"true", TokenType::MY_TRUE},
{"var", TokenType::VAR},
{"while", TokenType::WHILE}
};
bool isAlpha(char c);
bool isDigit(char c);
bool isAlphaNumeric(char c);
bool match(char expected);
void scanToken();
char advance();
void addToken(TokenType type);
void addToken(TokenType type, std::any literal);
char peek();
char peekNext();
void string();
void number();
void identifier();
public:
Scanner(const std::string&);
bool isAtEnd();
std::vector<Token> scanTokens();
};