Support redefinition of instruction symbols
Opened this issue · 1 comments
Some programs, like STPWCH, redefine instruction symbols. My best guess is this was to permit assembling these programs in older assemblers that did not have these instructions in their default symbol tables, but it causes problems for the current implementation:
Illegal symbol 'LexToken(EQUALS,'=',2,8)'
Error
Traceback (most recent call last):
File "/Users/julian/Documents/GitHub/pdp12-asm/test/test_asm_programs.py", line 53, in test_stpwch
result, expected = self.read_and_assemble('STPWCH')
File "/Users/julian/Documents/GitHub/pdp12-asm/test/test_asm_programs.py", line 20, in read_and_assemble
result = asm_parse.parse(listing.read())
File "/Users/julian/Documents/GitHub/pdp12-asm/src/asm_parse.py", line 221, in parse
mc = p.parse(file)
File "/Users/julian/Documents/GitHub/pdp12-asm/venv/lib/python3.9/site-packages/ply/yacc.py", line 333, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/Users/julian/Documents/GitHub/pdp12-asm/venv/lib/python3.9/site-packages/ply/yacc.py", line 1120, in parseopt_notrack
p.callable(pslice)
File "/Users/julian/Documents/GitHub/pdp12-asm/src/asm_parse.py", line 87, in p_machine_code
p[0] = s['opcode'] | 0o400
TypeError: 'int' object is not subscriptable
I can think of two approaches to solving this problem:
- Treat instructions no differently than any other symbol, but preload the symbol table with them at start time
- Keep instructions separate and add a parsing rule to replace the assignment with
empty
As I understand things, the first option is closer to the way LAP6-DIAL and PAL-8 work. However, I am not sure how the LMODE
and PMODE
pseudo-ops would interact with this... it seems like I would still need to keep track of which symbols were defined by the user and which were predefined. The second option seems more attractive, it would just require looking up instructions in the user symbol table before the predefined table.
Having thought about this problem a bit over the last 10 months, it seems like straying from the behavior of existing assemblers would probably cause headaches. For all I know there were programmers that leveraged the ability to redefine any symbol just to make reading their code hard but there's no reason it's not valid assembler input.