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:
+13
-5
@@ -40,13 +40,14 @@ void ParseTokens(List* tokens) {
|
||||
case IDENTIFIER:
|
||||
case LABEL:
|
||||
AddSymbol(t, ProgramCounter);
|
||||
AdvanceParser();
|
||||
break;
|
||||
case STRING:
|
||||
ProgramCounter += strlen(t->lexeme);
|
||||
break;
|
||||
case NUMBER: //Number's will be 2 bytes
|
||||
ProgramCounter += 2;
|
||||
break;
|
||||
//case NUMBER: //Number's will be 2 bytes
|
||||
// ProgramCounter += 2;
|
||||
// break;
|
||||
default: //Instructions are 1 byte wide.
|
||||
if (t->token_class == Opcode) {
|
||||
ProgramCounter++;
|
||||
@@ -71,11 +72,15 @@ void HandleOperation(void) {
|
||||
|
||||
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);
|
||||
AdvanceParser();
|
||||
}
|
||||
|
||||
if (inst->parameter_two == None) return;
|
||||
|
||||
if (PeekToken()->type == COMMA) {
|
||||
AdvanceParser();
|
||||
} else {
|
||||
@@ -84,9 +89,12 @@ void HandleOperation(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inst->parameter_two && PeekToken()->token_class == 1) {
|
||||
if (inst->parameter_two && PeekToken()->token_class > 0) {
|
||||
printf("Matched 2 '%s'\n", PeekToken()->lexeme);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user