tweaked the lexer to always have DEBUG of 0 and updated .tok file logic in runner

This commit is contained in:
Partho Bhattacharya
2025-02-13 18:51:31 -05:00
parent 3125d14942
commit f64a4633f7
16 changed files with 2783 additions and 17 deletions

View File

@ -28,6 +28,12 @@ int main(int argc, char *argv[]) {
}
}
if (yyin != NULL) {
fclose(yyin);
}
if (output != NULL && arg == TOK_ARG) {
fclose(output);
}
return 0;
}
@ -40,21 +46,20 @@ char *is_tok(int argc, char *argv[]) {
return INVALID_ARG;
}
int ignore_path = 0;
int count_since_slash = 0;
for (int i = 0; i < file_len; i++) {
count_since_slash++;
if (input_prog[i] == '/') {
ignore_path += count_since_slash;
count_since_slash = 0;
}
const char *basename = input_prog;
const char *slash = strrchr(input_prog, '/');
if (slash != NULL) {
basename = slash + 1;
}
// Calculate lengths
int basename_len = strlen(basename);
char* FILE_tok = calloc(basename_len - ALPHA_OFFSET + TOK_LEN + 1, sizeof(char));
// Copy filename and add .tok extension
strncpy(FILE_tok, basename, basename_len - ALPHA_OFFSET);
strcat(FILE_tok, ".tok");
file_len -= ignore_path;
input_prog += ignore_path;
char* FILE_tok = calloc(sizeof(char), file_len - ALPHA_OFFSET + TOK_LEN);
strncpy(FILE_tok, input_prog, file_len - ALPHA_OFFSET); //copy name of prog before .alpha
strcpy(FILE_tok + sizeof(char) * (file_len - ALPHA_OFFSET), ".tok"); //add .tok to end of file name
return FILE_tok;
}
return CHECK_OTHER;