失败的谓词异常
任何人都可以给我一些ANTLR中失败谓词例外的例子。
以及一些可以清楚解释的示例: - 输入不匹配 vs 失败的谓词 vs ANTLR中没有可行的ALT例外。提前致谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
任何人都可以给我一些ANTLR中失败谓词例外的例子。
以及一些可以清楚解释的示例: - 输入不匹配 vs 失败的谓词 vs ANTLR中没有可行的ALT例外。提前致谢。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
例外的名称几乎可以解释它们何时可以出现。只有失败的谓词异常有点特别。
Noviablealt
:尝试将块与几个替代方案匹配而无匹配时抛弃。示例:
输入:'C'。
InputMismatch
:当您具有部分匹配的输入时,将其投掷。示例:
输入:'a''b'或'a''c'eof。
FailedPredicateException
:在某些情况下抛出路径被谓词保护,而此路径是唯一可能的匹配(或必需的匹配),但是谓词可以防止与之匹配。例如:
但是,如果带有谓词的块是可选的(因此不需要),则不会抛出谓词异常,例如:
有关以下更高级的使用这些异常,以生成更好的错误消息,请参见<。
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:
Input: 'c'.
InputMismatch
:Thrown when you have input that partially matches. Example:
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:
However if the block with the predicate is optional (so it's not required) then no predicate exception is thrown, like with:
For more advanced use of these exceptions for generating better error messages see this error listener.