Combined binaries (parser + alpha)
This commit is contained in:
65
src/runner.c
65
src/runner.c
@ -5,8 +5,7 @@
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc == 1) {
|
||||
fprintf(
|
||||
stderr, INVALID);
|
||||
fprintf(stderr, INVALID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -60,35 +59,46 @@ int check_flag(char *arg, char *alpha) {
|
||||
|
||||
int run(FILE *alpha) {
|
||||
int token;
|
||||
// check that file exists
|
||||
curr = CreateScope(NULL, 1, 1);
|
||||
|
||||
// If file is not found
|
||||
if (alpha == NULL) {
|
||||
fprintf(stderr, "INPUT FILE NOT FOUND\n");
|
||||
return -1;
|
||||
}
|
||||
yyin = alpha;
|
||||
while (0 != (token = yylex())) {
|
||||
if (tok_flag != NULL) {
|
||||
fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, token,
|
||||
yytext);
|
||||
}
|
||||
if (token == COMMENT) {
|
||||
for (int i = 0; i < yyleng; i++) {
|
||||
if (yytext[i] == '\n') {
|
||||
line_number++;
|
||||
column_number = 0;
|
||||
}
|
||||
column_number++;
|
||||
|
||||
// TOK FLAG
|
||||
if (tok_flag != NULL) {
|
||||
while (0 != (token = yylex())) {
|
||||
if (tok_flag != NULL) {
|
||||
fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number,
|
||||
token, yytext);
|
||||
}
|
||||
continue;
|
||||
if (token == COMMENT) {
|
||||
for (int i = 0; i < yyleng; i++) {
|
||||
if (yytext[i] == '\n') {
|
||||
line_number++;
|
||||
column_number = 0;
|
||||
}
|
||||
column_number++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (token == 1999) {
|
||||
printf(
|
||||
"On line number %d and column number %d we have an invalid "
|
||||
"character:%s\n",
|
||||
line_number, column_number, yytext);
|
||||
}
|
||||
column_number += yyleng;
|
||||
}
|
||||
if (token == 1999) {
|
||||
printf(
|
||||
"On line number %d and column number %d we have an invalid "
|
||||
"character:%s\n",
|
||||
line_number, column_number, yytext);
|
||||
// return -1;
|
||||
fclose(tok_flag);
|
||||
|
||||
if (yyin != NULL) {
|
||||
fclose(yyin);
|
||||
}
|
||||
column_number += yyleng;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (st_flag != NULL) {
|
||||
@ -96,14 +106,15 @@ int run(FILE *alpha) {
|
||||
// print_symbol_table(top,st_flag);
|
||||
}
|
||||
|
||||
yyparse();
|
||||
FILE *f = fdopen(1, "w");
|
||||
print_symbol_table(getAncestor(curr), f);
|
||||
fclose(f);
|
||||
|
||||
if (yyin != NULL) {
|
||||
fclose(yyin);
|
||||
}
|
||||
|
||||
if (tok_flag != NULL) {
|
||||
fclose(tok_flag);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user