You could add a predicate at the end of your forloop
rule that enforces that both VARNAME
s are equal:
forloop
: FOR a=VARNAME EQUAL INT TO INT instructions NEXT b=VARNAME
{$a.getText().equals($b.getText())}?
;
But a (IMO) better way would be to let the parser just accept the unequal VARNAME
s and check them after the parse has been completed (in some sort of validation listener that traverses the parse tree).