Fixed a bug with single parameter instructions that land at the end of a file expecting a comma.

This commit is contained in:
2022-10-08 22:02:51 -05:00
parent fd44e03b1b
commit bca2ad67f1
+14 -11
View File
@@ -37,7 +37,7 @@ IRState* ParseTokens(List* tokens) {
Symbol* symbol = TryGetSymbol(t->Lemexe, MachineState.SymbolsTable);
if (symbol && symbol->Type != UnresolvedSymbol) {
fprintf(stderr, "[Error] Line %d: Redefinition of symbol '%s'\n", t->LineNumber, t->Lemexe);
fprintf(stderr, "[Error] Line %d: Redefinition of symbol '%s' (type: %d)\n", t->LineNumber, t->Lemexe, symbol->Type);
exit(1);
}
@@ -51,7 +51,7 @@ IRState* ParseTokens(List* tokens) {
Instruction* ins = HandleOperation();
if (!ins) {
fprintf(stderr, "[Error] Line %d: Expected instruction following label %s\n", t->LineNumber, t->Lemexe);
fprintf(stderr, "[Error] Line %d: Expected instruction following label '%s'.\n", t->LineNumber, t->Lemexe);
exit(1);
}
@@ -111,14 +111,12 @@ void HandleAssemblerDirective() {
if (token->Class != NumberClass) {
fprintf(stderr, "[Error] Line %d: Expected terminating byte.\n", token->LineNumber);
IgnoreParserLine();
return;
exit(1);
}
if (token->Value.Number > 255) {
fprintf(stderr, "[Error] Line %d: Number must fit within a byte.\n", token->LineNumber);
IgnoreParserLine();
return;
fprintf(stderr, "[Error] Line %d: The terminating byte must be smaller than 256, got %d.\n", token->LineNumber, token->Value.Number);
exit(1);
}
s->Value.String = CreateSymbolString(string, 1);
@@ -242,8 +240,13 @@ Parameter* GetParameterType() {
}
Instruction* HandleOperation() {
if (ParserAtEnd()) {
//fprintf(stderr, "[Error] Expected instruction mnemonic\n");
return NULL;
}
Token* token = PeekToken();
char mn[12];
//char mn[12];
if (token->Class != MnemonicClass) {
fprintf(stderr, "[Error] Line %d: Expected instruction mnemonic\n", token->LineNumber);
@@ -253,7 +256,7 @@ Instruction* HandleOperation() {
Instruction* ins = CreateInstruction(token->Value.Mnemonic);
GetMnemonicText(ins->Mnemonic, mn);
//GetMnemonicText(ins->Mnemonic, mn);
AdvanceParser();
@@ -274,13 +277,13 @@ Instruction* HandleOperation() {
goto InsertInstruction;
}
if (PeekToken()->Class == PunctuationClass && PeekToken()->Value.Punctuation == NewLine) {
if (PeekToken()->EndOfFile || (PeekToken()->Class == PunctuationClass && PeekToken()->Value.Punctuation == NewLine)) {
goto InsertInstruction;
}
if (PeekToken()->Class != PunctuationClass || PeekToken()->Value.Punctuation != Comma) {
//Syntax error
fprintf(stderr, "[Error] Line %d: Expected comma.\n", token->LineNumber);
fprintf(stderr, "[Error] Line %d: Expected comma got %d.\n", token->LineNumber, token->Class);
exit(1);
}