-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
68 lines (62 loc) · 1.4 KB
/
parser.cpp
File metadata and controls
68 lines (62 loc) · 1.4 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "equation.hpp"
#include "parse.hpp"
#include <iostream>
#include <fstream>
void usage(char* name){
std::cerr<<"Usage: "<<name<<" [options] filename"<<std::endl;
exit(-1);
}
int main(int argc, char** argv){
char opt=0;
bool print_bindings=false;
// Parse the arguments
while ((opt = getopt(argc, argv, "B?")) != -1)
switch (opt){
case 'B':
print_bindings=true;
break;
case '?':
default:
usage(argv[0]);
}
if (optind != argc-1)
usage(argv[0]);
(void) print_bindings;
try{
std::ifstream file(argv[optind]);
std::string formula;
std::getline(file,formula);
Equation eq = parse_formula(formula);
std::cout<<eq<<std::endl;
if(print_bindings){
auto [u,b,m] = bindings(eq);
std::cout<<std::endl;
// u|std::transform(.value)|join(",")
std::cout<<"Unbound: ";
if(u.size()){
std::cout<<u.front();
for(size_t i=1;i<u.size();i++)
std::cout<<","<<u[i];
}
std::cout<<std::endl;
std::cout<<"Bound: ";
if(b.size()){
std::cout<<b.front();
for(size_t i=1;i<b.size();i++)
std::cout<<","<<b[i];
}
std::cout<<std::endl;
std::cout<<"Mixed Use: ";
if(m.size()){
std::cout<<m.front();
for(size_t i=1;i<m.size();i++)
std::cout<<","<<m[i];
}
std::cout<<std::endl;
}
}catch(const char* e){
std::cerr<<"[ERROR] Caught unhandled Exception: \""<<e<<"\""<<std::endl;
std::cout<<"Parse Error"<<std::endl;
}
return 0;
}