Combined binaries (parser + alpha)

This commit is contained in:
Scarlett
2025-03-05 14:01:34 -05:00
parent 45940c0500
commit c2f28b6836
5 changed files with 47 additions and 37 deletions

View File

@ -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;
}