失败的谓词异常

发布于 2025-02-12 09:23:19 字数 151 浏览 2 评论 0 原文

任何人都可以给我一些ANTLR中失败谓词例外的例子。

以及一些可以清楚解释的示例: - 输入不匹配 vs 失败的谓词 vs ANTLR中没有可行的ALT例外。提前致谢。

Can anyone give me some examples of Failed Predicate exception in ANTLR.

and some examples that will clearly explain :- input mismatch VS failed predicate VS no viable alt exceptions in ANTLR. thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赢得她心 2025-02-19 09:23:19

例外的名称几乎可以解释它们何时可以出现。只有失败的谓词异常有点特别。

Noviablealt

尝试将块与几个替代方案匹配而无匹配时抛弃。示例:

r: 'a' | 'b';

输入:'C'。

InputMismatch

当您具有部分匹配的输入时,将其投掷。示例:

r: 'a' 'b' 'c' EOF;

输入:'a''b'或'a''c'eof。

FailedPredicateException

在某些情况下抛出路径被谓词保护,而此路径是唯一可能的匹配(或必需的匹配),但是谓词可以防止与之匹配。例如:

... | a ({condition}? b)

但是,如果带有谓词的块是可选的(因此不需要),则不会抛出谓词异常,例如:

... | a ({condition}? b)?

有关以下更高级的使用这些异常,以生成更好的错误消息,请参见<

The names of the exceptions pretty much explain when they can appear. Only the failed predicate exception is a bit special.

NoViableAlt:

Thrown when you try to match block with several alternatives and none matches. Example:

r: 'a' | 'b';

Input: 'c'.

InputMismatch:

Thrown when you have input that partially matches. Example:

r: 'a' 'b' 'c' EOF;

Input: 'a' 'b' or 'a' 'c' EOF.

FailedPredicateException:

Thrown in certain situations where a path is guarded by a predicate and this path is the only possible match (or a required match), but the predicate prevents matching it. For example:

... | a ({condition}? b)

However if the block with the predicate is optional (so it's not required) then no predicate exception is thrown, like with:

... | a ({condition}? b)?

For more advanced use of these exceptions for generating better error messages see this error listener.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文