-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathexample04-complement.cc
52 lines (41 loc) · 1.28 KB
/
example04-complement.cc
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
// example04-complement.cc - complementing an automaton
#include "mata/nfa/nfa.hh"
#include "mata/nfa/builder.hh"
#include <iostream>
#include <fstream>
using namespace mata::nfa;
int main(int argc, char *argv[]) {
if (argc != 2) {
std::cerr << "Input file missing\n";
return EXIT_FAILURE;
}
std::string filename = argv[1];
std::fstream fs(filename, std::ios::in);
if (!fs) {
std::cerr << "Could not open file \'" << filename << "'\n";
return EXIT_FAILURE;
}
mata::parser::Parsed parsed;
Nfa aut;
mata::OnTheFlyAlphabet alphabet;
try {
parsed = mata::parser::parse_mf(fs, true);
fs.close();
if (parsed.size() != 1) {
throw std::runtime_error(
"The number of sections in the input file is not 1\n");
}
if (parsed[0].type != "NFA") {
throw std::runtime_error("The type of input automaton is not NFA\n");
}
aut = mata::nfa::builder::construct(parsed[0], &alphabet);
}
catch (const std::exception& ex) {
fs.close();
std::cerr << "libMATA error: " << ex.what() << "\n";
return EXIT_FAILURE;
}
Nfa cmpl = complement(aut, alphabet);
std::cout << std::to_string(cmpl);
return EXIT_SUCCESS;
}