Last bit of clean up before building the parser.

This commit is contained in:
2022-02-02 20:43:25 +00:00
parent d39e37b078
commit 7c6e5e1541
4 changed files with 43 additions and 39 deletions
+31 -9
View File
@@ -10,26 +10,48 @@ typedef struct {
char** parameters;
} Instruction;
void print_file(char*);
List* get_strings(const char*);
int main(int argc, char* args[]) {
const char *input_files[argc - 1];
if (argc == 1) {
printf("Input files required.\n");
return -1;
}
FILE *file;
int line_count = 1;
char* line = NULL;
size_t len = 0;
ssize_t bytes_read;
int line_number = 1;
file = fopen(args[1], "r");
if (!file) {
printf("Failed to open '%s' for reading.\n", args[1]);
return 1;
}
List* tokens = GenerateTokensFromFile(args[1]);
//getline() uses realloc() for the line parameter, so there shouldn't
//be any issue with memory leaks as long as the last time this function
//is called, line gets free()ed.
while((bytes_read = getline(&line, &len, file)) != -1) {
List* tokens = GetTokensFromLine(line);
for (int i = 0; i < tokens->size; i++) {
Token* t = (Token*) tokens->content[i];
for (int i = 0; i < tokens->size; i++) {
Token* t = (Token*) tokens->content[i];
printf("Token Type: '%d' Value: '%s'\n", t->type, t->value);
printf("Token Type: '%d' Value: '%s' (%d)\n", t->type, t->value, line_number);
free(t->value);
free(t->value);
}
DestroyList(tokens);
line_number++;
}
DestroyList(tokens);
fclose(file);
if (line) free(line);
}