62 lines
1.4 KiB
C
62 lines
1.4 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "../includes/list.h"
|
|
#include "../includes/lexer.h"
|
|
#include "../includes/parser.h"
|
|
|
|
typedef struct {
|
|
char *opcode;
|
|
unsigned char count;
|
|
char** parameters;
|
|
} Instruction;
|
|
|
|
List* get_strings(const char*);
|
|
|
|
int main(int argc, char* args[]) {
|
|
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;
|
|
}
|
|
|
|
//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);
|
|
|
|
if (line_number == 1 || line_number == 2) {
|
|
ParseTokens(tokens);
|
|
}
|
|
|
|
for (int i = 0; i < tokens->size; i++) {
|
|
Token* t = (Token*) tokens->content[i];
|
|
|
|
printf("Token Type: '%d' Value: '%s' (%d)\n", t->type, t->value, line_number);
|
|
|
|
free(t->value);
|
|
}
|
|
|
|
DestroyList(tokens);
|
|
|
|
line_number++;
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
if (line) free(line);
|
|
} |