我正在尝试在EBNF中写下6809 assembly来编写tree-sitter解析器。
我被困在某一部作品上。在6809汇编中,可以将寄存器用作操作数,并对其进行除法或递增操作:
LDA 0,X+ ; loads A from X then bumps X by 1
LDD ,Y++ ; loads D from Y then bumps Y by 2
LDA 0,-U ; decrements U by 1 then loads A from address in U
LDU ,--S ; decrements S by 2 then loads U from address in S
在第二行代码中记住“缺失的”第一个操作数。这是我写的作品:
instruction = opcode, [operand], ["," , register_exp];
...
register_exp = [{operator}], register | register, [{operator}];
register = "X" | "Y" | "U" | etc. ;
operator = "+" | "-";
问题是register_exp = ...
。我觉得可能会有一种更优雅的方式来定义这种制作方式。另外,如果仅将寄存器分配给register_exp
,会发生什么情况?
答案 0 :(得分:1)
您可能需要
register_exp = [{operator}], register | register, [{operator}] | register;
允许没有操作符的寄存器名称。为什么您觉得它不太优雅?很有描述性。