使用 ANTLR 解析字符串文字时出现 NoViableAltException
我对 ANTLR 很陌生,试图解析一个简单的 PL/SQL 函数。如果这是一个愚蠢的问题,我很抱歉。
function MyFunc return boolean is
begin
IF :USER_ID_P IS NULL THEN
:USER_ID_P := 'PUBLIC';
END IF;
return (TRUE);
end;
应该捕获它的语法摘录:
atom
: variable_or_function_call ( PERCENT attribute )?
| SQL PERCENT attribute
| string_literal
| numeric_atom
| boolean_atom
| NULL
| LPAREN expression RPAREN
;
string_literal
: QUOTED_STRING
;
QUOTED_STRING
: ( 'n' )? '\'' ( '\'\'' | ~('\'') )* '\''
;
它到达“atom”规则,然后给出此错误:
NoViableAltException: line 6:0 no viable alternative for input 'END'
如果我将以下内容添加到“atom”规则中,则会拾取该字符串:
| '\'PUBLIC\''
I am very new to ANTLR, trying to parse a simple PL/SQL function. My apologies if this is a silly question.
function MyFunc return boolean is
begin
IF :USER_ID_P IS NULL THEN
:USER_ID_P := 'PUBLIC';
END IF;
return (TRUE);
end;
Grammar excerpt that is supposed to catch it:
atom
: variable_or_function_call ( PERCENT attribute )?
| SQL PERCENT attribute
| string_literal
| numeric_atom
| boolean_atom
| NULL
| LPAREN expression RPAREN
;
string_literal
: QUOTED_STRING
;
QUOTED_STRING
: ( 'n' )? '\'' ( '\'\'' | ~('\'') )* '\''
;
It gets to the "atom" rule and then gives this error:
NoViableAltException: line 6:0 no viable alternative for input 'END'
The string gets picked up if I add the following to the "atom" rule:
| '\'PUBLIC\''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您收到此错误是因为其他规则(或缺乏规则)。它表示它已到达 END 令牌,但无法匹配任何规则。例如,您可能在规则中的某处错过了分号标记。无论如何,需要完整的语法才能理解它。
I think you are getting this error because of other rules (or lack of them.) It says it got as far as the END token but couldn't match any rule. You might have missed a semicolon token somewhere in your rules for instance. In any case, the full grammar is needed to understand it.