I've wrote a grammar rule for a language in ANTLR as below:
variable: idlist COLON type (EQUAL explist)? SEMI;
idlist: identifier (COMMA identifier)*;
explist: exp (COMMA exp)*;
COLON: ':';
EQUAL: '=';
SEMI: ';';
COMMA: ',';
This input is valid for above grammar:
a, b, c: integer = 3, 4, 6;
But now if I want this input:
a, b, c, d: integer = 3, 4, 6;
or this:
a, b, c: integer = 3, 4, 6, 1;
becomes invalid due to inequality between amount of ID in idlist and value in explist, how I rewrite my grammar? Tks