-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_main.cpp
More file actions
50 lines (42 loc) · 1.54 KB
/
Copy pathsample_main.cpp
File metadata and controls
50 lines (42 loc) · 1.54 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
#include "Regex.hpp"
void example_lexing_entire_string(Fast_Attribute_DFA& dfa, std::string_view input_text)
{
size_t index = 0;
size_t token_count = 0;
while(index < input_text.size())
{
LexToken t = dfa.parse_token(input_text, index);
index += t.text.size();
index += (t.text.size() == 0);
if(t.priority != 16 && t.text.size() > 0)
{
std::cout<<token_count<<" "<<t<<'\n';
token_count++;
}
}
std::cout<<token_count<<"\n";
}
int main(int argc, char ** argv)
{
if(argc < 3)
{
std::cerr<<"Error must supply path to attribute regex to be parsed in first param, and file to be lexed in second\n";
exit(1);
}
Attribute_NFA nfa(read_file(argv[1]));
std::cout<<"\n\nNFA generated from file: "<<argv[1]<<":\n\n";
nfa.print();
std::string input = read_file(argv[1]);
Fast_Attribute_DFA dfa = compile_regex(input);
//created empty dfa to show how to load dfa from file
Fast_Attribute_DFA dfa2 = compile_regex(std::string(""));
dfa.write_to_file("test_binary_fadfa.bin");
dfa2.load_file("test_binary_fadfa.bin");
std::cout<<"\n\n\nDFA generated from file: "<<argv[1]<<":\n\n";
std::cout<<dfa2<<'\n';
std::string file_to_be_lexed = argv[2];
const std::string test_input = read_file(file_to_be_lexed);
std::cout<<"\nTokens parsed by performing lexical analysis on file: "<<file_to_be_lexed<<" with dfa generated:\n";
example_lexing_entire_string(dfa2, test_input);
return 0;
}