-
Notifications
You must be signed in to change notification settings - Fork 2
/
myjs.c
61 lines (44 loc) · 1.37 KB
/
myjs.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
#include <stdio.h>
#include <malloc.h>
#include "token.h"
#include "lexical_parser.h"
#include "io.h"
int main(int argc, char *argv[]){
FILE * f;
TokenList * tokenList;
f_i fi;
printf("============\n");
printf(" myjs\n");
printf("============\n\n");
if(argc == 1){
//TODO this default src file is for testing speed. Remove later.
f = fopen("src.js", "r");
//printf("Usage: %s script.js\n", argv[0]);
//return 0;
} else {
f = fopen(argv[1], "r");
}
if(f == NULL){
printf(">>>>>ERROR: File does not exist.\n>>>>>Exiting...\n");
return 1;
}
fi = (f_i) malloc(sizeof(struct FILE_INFO));
fi = get_file_info(f, &fi);
rewind(f);
tokenList = initializeTokenList(tokenList);
printf("LoC: %d\n", fi->lines);
printf("Max line length: %d\n", fi->max_line_length);
char * line_buff = (char*) malloc(sizeof(char) * fi->max_line_length);
int line_num = 0;
while(get_line(line_buff, fi->max_line_length, f) != NULL){
if(LOG) printf(">>>>> Parsing Line: %s\n", line_buff);
if(lexical_analisys(line_buff, tokenList, ++line_num) == 1) {
fclose(f);
return 1;
}
}
printf("\n====== Finished parsing file ======\n");
printTokenList(tokenList);
fclose(f);
return 0;
}