forked from SolomonBoloshe116/meda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
52 lines (44 loc) · 957 Bytes
/
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
#include "meda_parser.h"
#include "./table/variable.h"
#include "./table/literal.h"
#include <stdio.h>
#include <errno.h>
extern int yylex(void);
extern int yyparse(void);
extern FILE *yyin;
extern void destroy_literal_table(void);
void handle_with_input(char *file_name);
void handle_without_input(void);
int main(int argc, char *argv[])
{
init_literal_table();
atexit(destroy_literal_table);
switch(argc)
{
case 1:
handle_without_input();
break;
case 2:
handle_with_input(argv[1]);
break;
default:
fprintf(stderr, "Please don\'t mess with too many arguments\n");
}
return 0;
}
void handle_with_input(char *file_name)
{
yyin = fopen(file_name, "r");
if(!yyin)
{
perror("Error:");
exit(EXIT_FAILURE);
}
yyparse();
fclose(yyin);
destroy_literal_table();
}
void handle_without_input()
{
yyparse();
}