ANTLR如何在输入结束时检测垃圾数据 [英] ANTLR how to detect rubbish data at end of input

查看:86
本文介绍了ANTLR如何在输入结束时检测垃圾数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用以ANTLR编写的语法时,解析器可以正确识别输入流中的数据,但是如果我在输入末尾有一些垃圾文本(语法不应该对此进行解析),则解析器不会抱怨

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 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?

谢谢.

推荐答案

由于 Scott 已在ANTLR上回答邮件列表:

As Scott already answered on the ANTLR mailing list:

你好

使用ANTLR编写的语法时,解析器可以正确识别 来自输入流的数据,但是如果我在结尾处有一些垃圾文本 输入(语法不应该解析那些垃圾文本) 解析器不会抱怨.

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令牌

Add an EOF token to the end of your start rule

-斯科特

这篇关于ANTLR如何在输入结束时检测垃圾数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆