Antlr:“在输入中没有可行的替代方案' start 001 vs 003;”
我正在与Antlr和Python进行一些工作,并遇到了此错误消息“ 1:0”第1行,在输入中没有可行的替代方案'开始001 vs 003'”,但不知道该怎么办或如何修复它。
start: expr | <EOF>;
expr
: 'start' duration=DURATION 'fight' player_1=FILE 'vs' player_2=FILE #durationfightExpr
;
FILE : ('A'..'Z'|'a'..'z'|'0'..'9'|':'|'\\'|'/'|' '|'-'|'_'|'.')+ ;
DURATION : ('0' .. '9') + ('.' ('0' .. '9') +)?;
WS : [ \r\n\t]+ -> skip;
I am doing some work with Antlr and Python and have come across this error message "line 1:0 no viable alternative at input 'start 001 vs 003'" but have no idea what to do with it or how to fix it.
start: expr | <EOF>;
expr
: 'start' duration=DURATION 'fight' player_1=FILE 'vs' player_2=FILE #durationfightExpr
;
FILE : ('A'..'Z'|'a'..'z'|'0'..'9'|':'|'\\'|'/'|' '|'-'|'_'|'.')+ ;
DURATION : ('0' .. '9') + ('.' ('0' .. '9') +)?;
WS : [ \r\n\t]+ -> skip;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于输入
开始001 vs 003
,Lexer仅创建1 <代码>文件令牌。您可能需要从file
中排除白色空间字符:但是随后遇到了创建以下令牌的问题:
ie
001
和003
是文件
令牌。因为文件
也可以匹配此输入,并且由于它是在持续时间之前放置
,因此int/double的输入将始终成为>文件
。但是,如果您这些规则:然后输入
001
永远不会成为file> file
令牌(也许对您来说还可以,我不知道)。请注意,这些规则可以像这样更简洁:For the input
start 001 vs 003
, the lexer creates just 1FILE
token. You'll probably want to exclude the white space char fromFILE
:But then you run into the problem that the following tokens are created:
I.e. both
001
and003
areFILE
tokens. BecauseFILE
can match this input too, and because it is placed beforeDURATION
, int/double kind of input will always become aFILE
. But if you these rules:then input like
001
will never become aFILE
token (perhaps that's OK for you, I don't know). Note that these rules can be written more succinctly like this: