-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
63 lines (58 loc) · 1.48 KB
/
main.c
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
#include <stdlib.h>
#include <getopt.h>
#include "global.h"
#include "init.h"
#include "parser/parser.h"
#include "util/NFA.h"
#include "util/regex.h"
int main(int argc, char **argv)
{
file = stdin;
out = stdout;
debug = 0;
static struct option long_options[] =
{
{"debug", no_argument, NULL, 'd'},
{"out", required_argument, NULL, 'o'},
// {"o", required_argument, NULL, 'o'},
{0, 0, 0, 0}
};
int c;
int option_index = 0;
while((c = getopt_long(argc, argv, "do:", long_options, &option_index)) != -1) {
switch(c)
{
case 'd':
debug = 1;
break;
case 'o':
fprintf(stderr, "Outputting '%s'\n", optarg);
out = fopen(optarg, "w");
break;
}
}
while(optind < argc){
fprintf(stderr, "Compiling '%s'\n", argv[optind]);
file = fopen(argv[optind++], "r");
break;
}
if(file == NULL){
fprintf(stderr, "Cannot read from input file!\n");
exit(1);
}
if(out == NULL){
fprintf(stderr, "Cannot write to output file!\n");
exit(1);
}
struct NFA* n = compileRE("\\a\\w*");
//printNFA(n);
struct NFA* d = toDFA(n);
//printNFA(d);
printf("%d\n", validate(d, "abc"));
printf("%d\n", validate(d, "abd2"));
printf("%d\n", validate(d, "2bde"));
printf("%d\n", validate(d, "abdef"));
init();
parse();
exit(0);
}