Assembler: a string that spells an instruction is no longer assembled as one

A token is classified after its quotes have been stripped, so a string
literal reading "ADD" looked exactly like the ADD instruction and was
assembled as one. It failed with "attempting to assemble outside the
Program Segment", a message about a mistake nobody had made.

The literal and label checks were already guarded against strings and the
instruction check was not. Mnemonics match without regard to case, so
"or" and "and" were caught by this too, and those are ordinary enough
words to want in a message.

Third of its family, after a string beginning with '0' being read as a
malformed number and a string in the Program Segment being silently
discarded. All three have the same root.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Anachronaut
2026-08-19 18:17:39 -04:00
co-authored by Claude Opus 5
parent ca34e077ad
commit be402cc9be
4 changed files with 65 additions and 10 deletions
+8 -2
View File
@@ -323,8 +323,14 @@ int loadFile(intermediateElement **intermediateArray, char *fileName, int *inter
status = VECTORS;
break;
}
// Next, check to see if it's an instruction.
} else if (checkIfInstruction(&(*intermediateArray)[*intermediateIndex])) {
// Next, check to see if it's an instruction. A string is never one, however it is
// spelled: the quotes are gone by the time anything looks at a token, so a string
// whose text happens to be a mnemonic looked exactly like that instruction and was
// assembled as one. Mnemonics are matched without regard to case, so this was not
// only a problem for a program with "ADD" in its data - "or" and "and" are ordinary
// enough words to find in a message.
} else if ((*intermediateArray)[*intermediateIndex].type != STRING
&& checkIfInstruction(&(*intermediateArray)[*intermediateIndex])) {
// We should check if we're set up to mark this for the Program Segment.
if (status != PROGRAM) {
fprintf(stderr, RED "Error: Attempting to assemble outside the Program Segment.\n Did you forget to use the #Program keyword?\n" RESET);