我将如何编写语法检查器?
我有兴趣为某种语言编写语法检查器。基本上我想做的是制作一个 cli 工具,它将接受输入文件,然后写入它发现的错误。我想要解析的语言基本上类似于图灵,而且它相当丑陋,有时使用起来很痛苦。必须使用唯一的其他语法检查器
我应该使用什么语言?我想我会用 Ruby 编写它,但 Python 可能更快或者有更好的解析库。
我应该使用 Ruby 还是 Pearl 中的哪些库?这会更容易。
是否有定义语法的入门读本?这样的任务可能会变得令人困惑,我不知道如何处理它。
I am interested in writing a syntax checker for a language. Basically what I want to do is make a cli tool that will take an input file, and then write errors that it finds. The language I would want to parse is basically similar to Turing, and it is rather ugly and sometimes a pain to work with. The only other syntax checker for it must be used
What language should I use? I figured I would write it in Ruby, but Python may be faster or have better parsing libraries.
What libraries should I use, in Ruby or Pearl? Which would be easier.
Is there a primer to read for defining a grammar? Such a task can become confusing, and I'm not sure how I would handle it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果是我,我会用 Ruby 写,然后再担心速度。如果该程序非常受欢迎,我可能会添加一个原生 gem 来加速最慢的部分,但将大部分保留在 Ruby 中。如果它成为世界上最重要的程序,或者如果我没有其他事情可做,那么我可能会在那时用 C 或 C++ 重写它,但不是之前。
我会使用 Treetop 来完成所有解析。
我可能会补充一点,直接用 C 编写和优化语言解析器是一种有趣的学习经历。您几乎没有得到任何字符串处理帮助,因此您最终会完成所有解析,但您有机会只进行最少量的处理。这有点与 Ruby 体验相反。为了获得最大速度,您最终会做一些事情,例如为 malloc 编写前端,其中您知道永远不必释放的多个对象会在 malloc 块中永久分配。尽管通常将 yacc(1) 与 C/C++ 结合使用,但您当然可以编写递归下降解析器并获得更深入的学习体验。
当然,在完成所有这些之后,我很高兴这些天继续使用 Ruby。
If it were me, I would write it in Ruby, and worry about speed later. If the program is a runaway hit, I might add a native gem to speed up the slowest bit, but leave most of it in Ruby. If it becomes the most important program in the world, or if I had nothing else to do, I might rewrite it in C or C++ at that point, but not before.
And I would do all parsing using Treetop.
I might add that writing and optimizing a language parser directly in C is an interesting learning experience. You get roughly no string handling help, so you end up doing all the parsing, but you have a chance to do only the minimum amount of processing. It's sort of the opposite of the Ruby experience. To get maximum speed you end up doing things like writing frond-ends for malloc, where multiple objects you know you never have to free get allocated permanently within a malloced block. Although it is typical to use yacc(1) with C/C++, you can certainly write a recursive-descent parser and have an even deeper learning experience.
Of course, having done all that already, I'm happy to stick with Ruby these days.