Sprint1 basic prog setup fe t#06
This commit is contained in:
Annie Slenker
2025-02-11 19:02:00 -05:00
committed by GitHub
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#include "runner.h"
int main(int argc, char *argv[]) {
char *check_input;
int token;
//check_input can be compared to INVALID_ARG and DIFF_ARG to determine if -tok and holds the generated file name if it is
check_input = is_tok(argc, argv);
FILE * output = fopen(check_input, "w");
if (check_input == INVALID_ARG) {
return -1;
}
while (0 != (token = yylex())) {
if (check_input != DIFF_ARG) {
fprintf(output, "%d %d %3d \"%s\"\n", line_number, column_number, token, yytext);
}
}
return 0;
}
char *is_tok(int argc, char *argv[]) {
if (argc == 3 && strcmp("-tok", argv[1])) {
char *input_prog = argv[2];
int file_len = strlen(input);
//check that input program is a .alpha file
if (strcmp(".alpha", input_prog[file_len - ALPHA_OFFSET]) != 0) {
return INVALID_ARG;
}
char *FILE_tok[file_len - ALPHA_OFFSET + TOK_LEN];
strncpy(input, FILE_tok, file_len - ALPHA_OFFSET); //copy name of prog before .alpha
strcpy(".tok", FILE_tok[file_len - ALPHA_OFFSET]); //add .tok to end of file name
return FILE_tok;
}
return DIFF_ARG;
}

13
runner.h Normal file
View File

@ -0,0 +1,13 @@
#define ALPHA_OFFSET 5
#define TOK_LEN 3
#define INVALID_ARG "invalid"
#define DIFF_ARG "diff"
#include <string.h>
#include <std.io>
#include "lex.yy.c"
extern int line_number, column_number;
extern char *yytext;
int main(int argc, char* argv);
char *is_tok(int argc, char* argv);#define ALPHA_OFFSET 5