-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_dump_tokens.cpp
More file actions
38 lines (31 loc) · 1.04 KB
/
Copy pathsimple_dump_tokens.cpp
File metadata and controls
38 lines (31 loc) · 1.04 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
#include "lexer.h"
#include <iostream>
#include <fstream>
#include <sstream>
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <filename>" << std::endl;
return 1;
}
std::ifstream file(argv[1]);
if (!file.is_open()) {
std::cerr << "Error: Could not open file " << argv[1] << std::endl;
return 1;
}
std::stringstream buffer;
buffer << file.rdbuf();
std::string source = buffer.str();
file.close();
Lexer lexer(source);
std::vector<Token> tokens = lexer.tokenize();
std::cout << "Total tokens: " << tokens.size() << std::endl;
std::cout << "----------------------------" << std::endl;
// Display all tokens
for (size_t i = 0; i < tokens.size(); ++i) {
std::cout << i << ": Type=" << static_cast<int>(tokens[i].type)
<< ", Value='" << tokens[i].value << "'"
<< ", Line=" << tokens[i].line
<< ", Column=" << tokens[i].column << std::endl;
}
return 0;
}