gpt4 book ai didi

input - ANTLR 如何在输入结束时检测垃圾数据

转载 作者:行者123 更新时间:2023-12-01 01:35:55 24 4
gpt4 key购买 nike

当使用用 ANTLR 编写的语法时,解析器正确识别来自输入流的数据,但是如果我在输入的末尾有一些垃圾文本(不应该被语法解析),解析器不会提示。

我想这种行为没问题(我的意思是解析器完成了它的工作并解析了我说它应该解析的任何内容),但是在解析器完成其工作后,是否有任何技巧可以检测输入中何时剩余任何数据?

谢谢。

最佳答案

Scott已经在 ANTLR 邮件列表上回答了:

Hello,

When using grammars written in ANTLR, the parser correctly recognizes data from an input stream, but if I have some rubbish text at the end of the input (which rubbish text is not supposed to be parsed by the grammar) the parser does not complain.

I guess this behavior is all right (I mean the parser did its job and parsed whatever I said it should parse), but is there any trick to detect when there is any data left in the input after the parser has done its job?

Thanks, Gabi.



在开始规则的末尾添加一个 EOF token

——斯科特

关于input - ANTLR 如何在输入结束时检测垃圾数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2147964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com