Added very simple parsing logic.

This commit is contained in:
2021-12-28 20:48:09 +00:00
parent 5162804270
commit 9c6b1d9057
2 changed files with 56 additions and 1 deletions
BIN
View File
Binary file not shown.
+56 -1
View File
@@ -1,7 +1,15 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct opcode {
char op[255];
char param1[255];
char param2[255];
} Opcode;
void print_file(char*);
Opcode* get_opcode(char*);
int main(int argc, char* args[]) {
const char *input_files[argc - 1];
@@ -33,7 +41,21 @@ void print_file(char* file_path) {
}
while((bytes_read = getline(&line, &len, file)) != -1) {
printf("%s", line);
//printf("%s", line);
unsigned short int count = 0;
char* c;
char* opcode;
char* param1;
char* param2;
//for(c = line; *c != '\0'; c++) {
Opcode* op = get_opcode(line);
//}
//printf("\n");
if (strcmp(op->op, "NA") == 0) continue;
printf("%s %s, %s\n", op->op, op->param1, op->param2);
}
printf("\n");
@@ -41,4 +63,37 @@ void print_file(char* file_path) {
fclose(file);
if (line) free(line);
}
Opcode* get_opcode(char* line) {
Opcode *op = malloc(sizeof(Opcode));
strcpy(op->op, "NA");
if (strlen(line) == 0 ) return op;
if (line[0] == ';') return op;
int i = 0;
int count = 0;
for (char* c = line; *c != '\0'; c++) {
if (*c == ';') break;
if (*c == ' ') {
i = 0;
count++;
continue;
}
if (*c == ',') {
i = 0;
continue;
}
if (count == 0) op->op[i] = *c;
else if (count == 1) op->param1[i] = *c;
else if (count == 2) op->param2[i] = *c;
i++;
}
return op;
}