我在 ANTLR 中为一种语言编写了如下语法规则:
variable: idlist COLON type (EQUAL explist)? SEMI;
idlist: identifier (COMMA identifier)*;
explist: exp (COMMA exp)*;
COLON: ':';
EQUAL: '=';
SEMI: ';';
COMMA: ',';
此输入对以上语法有效:
a, b, c: integer = 3, 4, 6;
但是现在如果我想要这个输入:
a, b, c, d: integer = 3, 4, 6;
或者这个:
a, b, c: integer = 3, 4, 6, 1;
由于 idlist 中的 ID 数量与 explist 中的值之间的不等而变得无效,我如何重写我的语法?谢谢