Got the Parser to, so far, correctly (minus memory leaks) parse out and report errors with opcodes and their parameters.

This commit is contained in:
2022-05-12 23:16:02 -05:00
parent 2de3538d80
commit 5265666178
+13 -5
View File
@@ -40,13 +40,14 @@ void ParseTokens(List* tokens) {
case IDENTIFIER: case IDENTIFIER:
case LABEL: case LABEL:
AddSymbol(t, ProgramCounter); AddSymbol(t, ProgramCounter);
AdvanceParser();
break; break;
case STRING: case STRING:
ProgramCounter += strlen(t->lexeme); ProgramCounter += strlen(t->lexeme);
break; break;
case NUMBER: //Number's will be 2 bytes //case NUMBER: //Number's will be 2 bytes
ProgramCounter += 2; // ProgramCounter += 2;
break; // break;
default: //Instructions are 1 byte wide. default: //Instructions are 1 byte wide.
if (t->token_class == Opcode) { if (t->token_class == Opcode) {
ProgramCounter++; ProgramCounter++;
@@ -71,11 +72,15 @@ void HandleOperation(void) {
AdvanceParser(); AdvanceParser();
if (inst->parameter_one && PeekToken()->token_class == 1) { if (inst->parameter_one == None) return;
if (inst->parameter_one && PeekToken()->token_class > 0) {
printf("Matched '%s'\n", PeekToken()->lexeme); printf("Matched '%s'\n", PeekToken()->lexeme);
AdvanceParser(); AdvanceParser();
} }
if (inst->parameter_two == None) return;
if (PeekToken()->type == COMMA) { if (PeekToken()->type == COMMA) {
AdvanceParser(); AdvanceParser();
} else { } else {
@@ -84,9 +89,12 @@ void HandleOperation(void) {
return; return;
} }
if (inst->parameter_two && PeekToken()->token_class == 1) { if (inst->parameter_two && PeekToken()->token_class > 0) {
printf("Matched 2 '%s'\n", PeekToken()->lexeme); printf("Matched 2 '%s'\n", PeekToken()->lexeme);
AdvanceParser(); AdvanceParser();
} else {
printf("Failed to match %s (class: %d)\n", PeekToken()->lexeme, PeekToken()->token_class);
printf("Inst %s (class: %x)\n", inst->lexeme, inst->parameter_two);
} }
} }