Limitations of a two-pass assembler
I've come to realize that supporting foward references in a two-pass assembler [1] isn't always easy. The simple case of forward references I support:
lda #alpha alpha equ 5
On pass 1, alpha isn't defined, but by pass two, we have its value—5.
With this code, however:
lda #alpha alpha equ bravo bravo equ 5
alpha is undefined on line 1, and it remains undefined even on line 2 because we haven't defined bravo yet. Thus when we end pass 1, alpha is still undefined. That it took me two years to even stumble across this issue is a bit surprising to me. I just haven't written 6809 assembly code like this.
Can I fix this? If I add another pass, probably. If I don't want to add another pass … I don't know. I would have to track expressions that aren't fully defined in pass 1, which could be a lot of work for an issue that might not come up all that often (if my own code is to go by). I mean, things can get quite pathological:
lda #Alpha Alpha equ Bravo+1 Bravo equ Charlie+1 Charlie equ Delta+1 Delta equ Echo+1 Echo equ Foxtrot+1 Foxtrot equ Golf+1 Golf equ Hotel+1 Hotel equ India+1 India equ Juliet+1 Juliet equ Kilo+1 Kilo equ Lima+1 Lima equ Mike+1 Mike equ November+1 November equ Oscar+1 Oscar equ Papa+1 Papa equ Quebec+1 Quebec equ Romeo+1 Romeo equ Sierra+1 Sierra equ Tango+1 Tango equ Uniform+1 Uniform equ Victor+1 Victor equ Whiskey+1 Whiskey equ Xray+1 Xray equ Yankee+1 Yankee equ Zulu+1 Zulu equ 1
lsawm (part of LWTools [2]) does properly handle this pathological case but it does six passes, not two. The other 6809 assembler I have, an older one written back in the 90s, doesn't and issues deceptive error messages, so it's not like I'm the only one to not handle this properly.
As of now, I just issue an error and let the programmer deal with it.