开发者

ANTLR - The following alternatives can never be matched

开发者 https://www.devze.com 2023-03-30 12:07 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消