我应该使用哪种语言编写文本解析器并以用户友好的方式显示结果? [英] What language should I use to write a text parser and display the results in a user friendly manner?

查看:76
本文介绍了我应该使用哪种语言编写文本解析器并以用户友好的方式显示结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司的专有软件生成了一个日志文件,如果对其进行分析,该文件将更易于使用.我们所有人都使用的日志解析器是由另一位员工作为辅助项目编写的,它的性能令人震惊.

My company's proprietary software generates a log file that is much easier to use if it is parsed. The log parser we all use was written by another employee as a side project, and it has horrible performance.

这些日志文件很快就会增长到10兆字节,如果日志文件大于1兆字节,我们当前使用的解析器会出现问题.

These log files can grow to 10s of megabytes very quickly, and the parser we currently use has issues if a log file is bigger than 1 megabyte.

因此,我想编写一个程序,可以在尽可能短的时间内解析大量文本.我们仅使用Windows,因此必须在Windows上运行.我们当前的实现在本地Web服务器上运行,我坚信将其作为应用程序运行将必须更快.

So, I want to write a program that can parse this massive amount of text in the shortest amount of time possible. We use Windows exclusively, so running on Windows is a must. Our current implementation runs on a local web server, and I'm convinced that running it as an application would have to be faster.

所有建议都会有所帮助.谢谢.

All suggestions will be helpful. Thanks.

编辑:我的最终目标是解析文本,并以更加友好的方式使用颜色等显示文本.您可以使用Perl和Python做到这一点吗?我知道您可以使用Java和C ++做到这一点.因此,它的功能类似于打开日志文件的记事本,但是在屏幕上显示的是用户友好格式,而不是原始文件.

My ultimate goal is to parse the text and display it in a much more user friendly manner with colors and such. Can you do this with Perl and Python? I know you can do this with Java and C++. So, it will function like Notepad where you open a log file, but on the screen you display the user-friendly format instead of the raw file.

编辑:因此,我无法选择最佳答案,那就是选择一种能够最好地显示我想要的语言,然后在其中编写解析器.同样,使用ANTLR可能会使此过程更加容易.我更改了最初的问题,因为我想我没有问我真正要寻找的是什么.谢谢大家!

So, I cant choose the best answer, and that was to choose a language that can best display what I'm going for, and then write the parser in that. Also, using ANTLR will probably make this process much easier. I changed the original question, since I guess I didn't ask what I was really looking for. Thanks everyone!

推荐答案

嗯,随你所知"是一个很好的答案. Perl是为这种事情而设计的(但是imo非常适合简单的解析,但是我个人会避免在复杂的项目中使用它).

Hmmm, "go with what you know" was a good answer. Perl was designed for this sort of thing (but imo is well suited for simple parsing, but I'd personally avoid it for complex projects).

如果变得有点复杂,为什么不使用正确的语法和语法设置?

If it gets even a little complex, why not use a proper syntax and grammar set-up?

Lex& Yacc(或Flex& Bison)浮现在脑海,但就我个人而言,我总是会联系 Antlr

Lex & Yacc (or Flex & Bison) spring to mind, but personally I would always reach for Antlr

根据模式(语法)定义各种单词",并结合这些单词(语法)和Antlr的规则将吐出一个程序来解析您的输入(您可以使用Java,C,C ++等语言编写该程序) (您担心解析时间,因此请选择一种编译语言).

Define various "words" in terms of patterns (syntax), and rules to combine those words (grammar) and Antlr will spit out a program to parse your input (you can have the program in Java, C, C++ and more (you are worried about parse time, so choose a compiled language, of course)).

我个人认为手工解析器很麻烦,调试它们甚至更乏味,但是 AntlrWorks a>是一个可爱的IDE,确实使它成为小菜一碟...

I personally find it tedious to hand-craft parsers, and even more tedious to debug them, but AntlrWorks is a lovely IDE which really makes it a piece of cake ...

底部的那一点是在定义语法规则.

That bit at the bottom is defining a grammar rule.

如果您弄乱了语法规则,则会被告知.手工解析器不是这种情况,您只需刮擦body part并想知道奇怪的结果" ...

If you mess up your grammar rules, you will be informed. This is not the case with hand-crafted parsers, where you just scratch your body part and wonder about the "strange results"...

检查一下.即使您认为您的项目现在微不足道,它也可能会发展壮大.而且,如果您对解析有兴趣,则应归功于自己至少熟悉lex/yacc,尤其是Antlr(Works)

Check it out. Even if you think your project is trivial now, it may well grow. And if you have any interest in parsing you do owe it to yourself to at least be familiar with lex/yacc, but especially Antlr(Works)

这篇关于我应该使用哪种语言编写文本解析器并以用户友好的方式显示结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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