Got the scanner running again. Seems to be picking up punctuation, labels, identifiers and strings as expected.
This commit is contained in:
+52
-14
@@ -21,27 +21,65 @@ int main(int argc, char* args[]) {
|
||||
if (!ReadAllString(args[1], &source_code, &bytes_read)) return EX_IOERR;
|
||||
|
||||
List* list = GenerateTokenList(source_code);
|
||||
char mnemonic[12];
|
||||
|
||||
// for(int i = 0; i < list->size; i++) {
|
||||
// Token* t = (Token*) list->content[i];
|
||||
for(int i = 0; i < list->size; i++) {
|
||||
Token* t = (Token*) list->content[i];
|
||||
|
||||
// if (t->type == LineEnd) {
|
||||
// if (i - 1 >= 0 && ((Token*) list->content[i - 1])->type != LineEnd)
|
||||
// printf("\n");
|
||||
if (t->Class == PunctuationClass){
|
||||
if(t->Value.Punctuation == NewLine) {
|
||||
if(i - 1 >= 0 && (((Token*)list->content[i - 1])->Class == PunctuationClass && ((Token*)list->content[i - 1])->Value.Punctuation == NewLine)) continue;
|
||||
|
||||
// continue;
|
||||
// }
|
||||
printf("\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// printf("[T: %i][C: %i] '%s' ", t->type, t->token_class, t->lexeme);
|
||||
// if (t->type == LABEL) printf("* ");
|
||||
// }
|
||||
printf("%c ", t->Value.Punctuation);
|
||||
continue;
|
||||
}
|
||||
|
||||
IRState* image = ParseTokens(list);
|
||||
//Disassemble(image);
|
||||
for(int i = 0; i < image->Opcodes->size; i++) {
|
||||
printf("%d\n", ((IROpcode*) image->Opcodes->content[i])->Mnemonic);
|
||||
if (t->Class == LabelClass) {
|
||||
printf("[L]%s* ", t->Lemexe);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t->Class == IdentifierClass) {
|
||||
printf("[I]%s ", t->Lemexe);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t->Class == RegisterClass) {
|
||||
printf("[R]%d", t->Value.Register);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t->Class == NumberClass) {
|
||||
printf("%d ", t->Value.Number);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t->Class == MnemonicClass) {
|
||||
GetMnemonicText(t->Value.Mnemonic, mnemonic);
|
||||
printf("%s ", mnemonic);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t->Class == DirectiveClass) {
|
||||
printf("[D]%d ", t->Value.Directive);
|
||||
|
||||
}
|
||||
|
||||
if (t->Class == CharacterClass) {
|
||||
printf("%s ", t->Lemexe);
|
||||
}
|
||||
}
|
||||
|
||||
//IRState* image = ParseTokens(list);
|
||||
//Disassemble(image);
|
||||
//for(int i = 0; i < image->Opcodes->size; i++) {
|
||||
// printf("%d\n", ((IROpcode*) image->Opcodes->content[i])->Mnemonic);
|
||||
//}
|
||||
|
||||
//FILE* program = fopen("program.bin", "w+b");
|
||||
|
||||
//fwrite(image, 1, image[2] + image[3], program);
|
||||
|
||||
Reference in New Issue
Block a user