-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
59 lines (54 loc) · 1.32 KB
/
main.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
#include <fstream>
#include <iostream>
#include <string>
#include <cctype>
#include "preprocessor.h"
#include "lexer.h"
extern std::unordered_set<std::string> keywords;
int main() {
//Interactions with user
std::string input;
std::cout << "Enter file name(or input): ";
std::getline(std::cin, input);
/*std::ifstream inputFileStream(input);
//Verifying file
if (!inputFileStream) {
std::cerr << "Error opnening file\n";
return 1;
}*/
std::string lexeme;
for (char c : input) {
//Detects when the lexeme ends
if (std::isalnum(c) || c == '_') {
lexeme += c;
}
else {
if (!lexeme.empty()) {
TokenType tokenType = getTokenType(lexeme);
std::cout << "Lexeme: " << lexeme << " \n- Token Type: ";
//Switch statement that determines the output based on the tokenType
switch (tokenType) {
case IDENTIFIER:
std::cout << "IDENTIFIER" << std::endl;
break;
case KEYWORD:
std::cout << "KEYWORD" << std::endl;
break;
case LITERAL:
std::cout << "LITERAL" << std::endl;
break;
case OPERATOR:
std::cout << "OPERATOR" << std::endl;
break;
case PUNCTUATION:
std::cout << "PUCNTUATION" << std::endl;
}
}
if (!std::isspace(c)) {
std::cout << "Lexeme: " << c << " \n- Token Type: Punctuation" << std::endl;
}
lexeme.clear();
}
}
return 0;
}