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);
|
||||
|
||||
+22
-1
@@ -156,9 +156,30 @@ int IsRegister(const char* text, Registers* reg) {
|
||||
if (!text) return 0;
|
||||
|
||||
int length = strlen(text);
|
||||
Registers r = R8;
|
||||
|
||||
if (length != 2) return 0;
|
||||
if (text[0] != 'r') return 0;
|
||||
|
||||
return text[1] >= '1' && text[1] <= '8';
|
||||
switch(text[1]) {
|
||||
case '1':
|
||||
r--;
|
||||
case '2':
|
||||
r--;
|
||||
case '3':
|
||||
r--;
|
||||
case '4':
|
||||
r--;
|
||||
case '5':
|
||||
r--;
|
||||
case '6':
|
||||
r--;
|
||||
case '7':
|
||||
r--;
|
||||
case '8':
|
||||
if (reg) *reg = r;
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user