forked from The-Quantum-Project/QVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLexer.cpp
67 lines (58 loc) · 1.48 KB
/
Lexer.cpp
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
58
59
60
61
62
63
64
65
66
67
//
// Created by joshu on 10/10/2015.
//
#include "Lexer.h"
#include <regex>
Lexer::Lexer() {
res_map.push_back(">=");
res_map.push_back("<=");
res_map.push_back(">");
res_map.push_back("<");
res_map.push_back("=>");
res_map.push_back("+");
res_map.push_back("-");
res_map.push_back("*");
res_map.push_back("/");
res_map.push_back("=");
res_map.push_back("(");
res_map.push_back(")");
res_map.push_back(";");
res_map.push_back(",");
res_map.push_back("if");
res_map.push_back("def");
res_map.push_back("else");
res_map.push_back("fi");
res_map.push_back("while");
res_map.push_back("");
res_map.push_back("");
res_map.push_back("");
res_map.push_back("");
}
int i = 0;
Lexer::TokenType Lexer::nextToken() {
std::string inp;
std::getline(std::cin, inp);
try {
//TODO URGENT Fix regex.......
std::regex r(R"(>=|<=|-->|(if)|[def]|else|fi|while)", std::regex_constants::basic);//("(\\s+|#.*)|>=|<=|-->|if|def|else|fi|while|([a-zA-Z][a-zA-Z0-9]*)|(\\d+)|.");
std::smatch result;
std::regex_match(inp, result, r);
std::cerr << *result.begin() << std::endl;
} catch (std::exception &e) {
std::cerr << e.what() << std::endl;
}
TokenType t;
t = NEOF;
switch (i) {
case 0:
t = LT;
break;
case 1:
t = GT;
break;
default:
break;
}
// i++;
return t;
}