-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.cpp
More file actions
51 lines (40 loc) · 1021 Bytes
/
Copy pathdemo.cpp
File metadata and controls
51 lines (40 loc) · 1021 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
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <fstream>
#include "flexer.hpp"
int main(int argc, const char *argv[])
{
if (argc != 2)
{
std::cout << "usage: " << argv[0] << " <file>\n";
return 1;
}
// read the file into `content`
const char *filename = argv[1];
std::ifstream file(filename);
if (!file.is_open())
{
std::cout << "error reading file: " << filename << "\n";
return 1;
}
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
flexer::config_t config;
config.configure_as_c23();
flexer::flexer flexer(config, content.c_str(), filename);
flexer::token_t t;
while (true)
{
flexer.get_token(t);
std::cout << t.to_string() << " at " << t.get_location().to_string() << "\n";
if (t.get_kind() == flexer::token_kind_t::invalid)
{
std::cout << "*** invalid token detected ***\n";
return 1;
}
if (t.get_kind() == flexer::token_kind_t::eof)
{
break;
}
}
return 0;
}