-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
67 lines (49 loc) · 1.21 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
64
65
66
67
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
// generated files
#include "parser.h"
#include "lexer.h"
// my types
#include "symstack.h"
// #define BUFSIZE 800
int yyparse(yyscan_t scanner);
int compile(const char *source) {
yyscan_t scanner;
YY_BUFFER_STATE state;
if (yylex_init(&scanner)) {
return 1; /* could not initialize */
}
state = yy_scan_string(source, scanner);
if (yyparse(scanner)) {
return 2; /* error parsing */
}
yy_delete_buffer(state, scanner);
yylex_destroy(scanner);
return 0;
}
void catfile(char* destination, int size, char *filename) {
FILE *f = fopen(filename, "r");
if (!f) {
perror("file not found");
exit(1);
}
int read = fread(destination, 1, size, f);
printf("file size: %i\n", read);
fclose(f);
}
int main(int argc, char** argv) {
++argv;
--argc;
// for (int i = 0; i < argc; i++) {
// printf("%s\n", argv[i]);
// }
// printf("running...\n\n");
// call_stack = new_stack();
char file[800];
// catfile(file, 800, "./test/test.txt");
catfile(file, 800, argv[0]);
int code = compile(file);
// print_stack();
return code;
}