simon987 / Much-Assembly-Required

Assembly programming game
https://muchassemblyrequired.com
GNU General Public License v3.0
926 stars 88 forks source link

Label parsing inconsistency #187

Closed DBJ314 closed 5 years ago

DBJ314 commented 5 years ago

The current regex used for parsing labels, ^\\s*\\b\\w*\\b:, allows labels to consist entirely of numeric characters. The DW directive trys to treat an operand as a label before seeing if it is a number, but the instruction parsing does it the other way around. You can use numbers as labels in DW directives, but not in instructions.

.text JMP after_test test: DW 999 999: after_test: MOV A, 1 MOV B, 999 SUB B, [test];should be 0, right? HWI 9 BRK

kevinramharak commented 5 years ago

So it interprets the 999: as a valid label and therefore MOV B, 999 will use 999 as a label for a memory adress?

DBJ314 commented 5 years ago

999 is a valid label, but MOV B, 999 just does 999. DW 999, on the other hand, resolves to the address of 999.

kevinramharak commented 5 years ago

Right. What would be a valid label regex? Would an identifier be sufficient? ^[a-zA-Z_][a-zA-Z0-9_]+:?

DBJ314 commented 5 years ago

I think ^[a-zA-Z_]\w*:. \w is a convenient shortcut for [a-zA-Z0-9_]