EBNF:汇编代码生成中的类似前缀和后缀的运算符

EBNF: prefix and suffix-like operator in assembly code production

我正在尝试写下 6809 assembly in EBNF to write a 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

注意第二行代码中的"missing"第一个操作数。以下是我写的作品:

instruction = opcode, [operand], ["," , register_exp];
...
register_exp = [{operator}], register | register, [{operator}];
register = "X" | "Y" | "U" | etc. ;
operator = "+" | "-";

问题是register_exp = ...。我觉得可以用更优雅的方式来定义这个作品。另外,如果只给 register_exp 一个寄存器会发生什么?

你可能需要

register_exp = [{operator}], register | register, [{operator}] | register;

允许不带运算符的注册名称。为什么你觉得它不那么优雅?描述性很强。