-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
43 lines (37 loc) · 837 Bytes
/
main.cpp
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
#include "lex.h"
#include "parser.h"
#include "symbol_table.h"
FILE *sourcefile;
char *line,*lineptr, ch;
tpToken SymbolTable[Tsize];
int main(int argc, char *argv[])
{
// Initialize the symbol table
init();
sourcefile = NULL;
line = (char *)malloc(270*sizeof(char));
if (argc != 2)
{
printf("Error: Incorrect use of program.\n");
printf("Usage: ./parser <sourcefile>.\n");
exit(1);
}
// Open source file
sourcefile = fopen(argv[1],"r");
if (sourcefile == NULL)
{
printf("Couldn't find the file.\n");
perror("Error");
return 1;
}
// Set the beginning of the file
fgets(line, 250, sourcefile);
ch = line[0];
lineptr = line;
// Call the parser, returns the complete symbol table
parser();
report();
fclose(sourcefile);
// --------------------
return 0;
}