解析javacc中的特定行数
我有一个想要解析的特定格式的文件。在这个文件中,我在一行上有一个数字,它指定了后面的行数。
文件示例摘录:
3 // number of lines to follow = 3
1 3 // 1st line
3 5 // 2nd line
2 7 // 3rd line
我想读取数字(本例中为 3),然后仅读取以下 3 行。如果行数较少或较多,我想生成错误。我怎样才能在javacc中做到这一点?
谢谢
I have a file with a specific format that I would like to parse. In this file I have a number on a line which specifies the number of lines to follow it.
example excerpt from the file:
3 // number of lines to follow = 3
1 3 // 1st line
3 5 // 2nd line
2 7 // 3rd line
I want to read the number (3 in this example) and then read the following 3 lines only. If there are less or more lines I want to generate an error. How can I do this in javacc?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是:
Lines.parse() : int
方法返回它应该读取的行数与实际读取的行数之间的差异。像这样生成解析器:
编译所有类:
并向其提供测试数据(
test.txt
):像这样:
生成输出:
Here's a way:
The
Lines.parse() : int
method returns the difference between the number of lines it is supposed to read, and the actual number of lines that are read.Generate the parser like this:
compile all classes:
And feed it your test data (
test.txt
):like this:
which produces the output: