ANTLR - The following alternatives can never be matched
I am unable to understand why this simple grammar -
grammar Test;
file : ID;
ID : .*;
leads to this error -
Test.g:3:6: The follo开发者_开发问答wing alternatives can never be matched: 1
Why is this happening?
Using .*
and .+
at the end of a lexer rule is illegal in ANTLR:
ID : .*; // illegal
ID : 'bar' .*; // illegal
ID : .* 'bar'; // legal
In parser rules, this is not the case.
精彩评论