I try to use ANTLR to construct a very simple rules as following:
number :
INT
;
INT : '0'..'9'+
;
It would accept 123 as number, but I am not sure why it also accepts abc123 as number?
How can I correct the rules to parse number?
Thanks for any advice!
It doesn’t.
Perhaps you’re using some 3rd party tool/editor in which it is difficult to see the error message(s) printed to the console, but they’re there. The parser is probably just recovering from the mismatched input making it look like
INTaccepts input like"abc123".