如何在 Ruby 中通过 S 表达式构建 AST?

发布于 2024-12-21 15:42:05 字数 185 浏览 2 评论 0原文

我不知道如何构建 S-exp。 我想这样做,因为我需要为我的语言构建 AST。 一开始我使用RubyParser将其解析为sexp,然后代码gen。 但我认为它一定是 ruby​​ 的子集。我无法定义我想要的语言。 现在我需要为我的语言实现解析器。
那么有人可以推荐任何为 S 表达式构建 AST 的 ruby​​ 工具吗?

谢谢!

I have no idea how to build S-exp.
I want to do it, because I need to build AST for my langauge.
At the beginning I used RubyParser to parse it to sexp then code gen.
But it must be ruby's subset I think.I cant define the language what I want.
Now I need to implement parser for my language.
So anyone could recommend any ruby tool that building AST for S-expression ?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

靑春怀旧 2024-12-28 15:42:05

从你的问题中并不清楚你到底需要什么,但简单的谷歌搜索给出了一些有趣的链接来检查。也许在检查这些链接后,如果它们不是您问题的答案,您可以编辑问题并使其更加精确和具体。

http://thingsaaronmade.com/blog/writing-an -s-表达式-解析器-in-ruby.html
https://github.com/aarongough/sexpistol

It is not very clear from your question what exactly do you need, but simple Google search gives some interesting links to check. Maybe after checking these links, if they are not the answer to your question, you can edit question and make it more precise and concrete.

http://thingsaaronmade.com/blog/writing-an-s-expression-parser-in-ruby.html
https://github.com/aarongough/sexpistol

想念有你 2024-12-28 15:42:05

您可以在 http://github.com/bendiken/sxp-ruby。我将它用于 SPARQL S 表达式 (SSE) 以及管理 Ruby 中抽象语法树的类似方法。

You might try the sxp-ruby gem at http://github.com/bendiken/sxp-ruby. I use it for SPARQL S-Expressions (SSE) and similar methods for managing Abstract Syntax Trees in Ruby.

盛装女皇 2024-12-28 15:42:05

也许你可以看看这个名为 Astrapi 的 gem。

这只是一个实验:

  • 在“mm”文件(抽象语法)中描述您的语言元素(概念),
  • 在此文件上运行 astrapi
  • astrapi 会生成一个解析器,该解析器能够根据以 s 表达式表示的输入源来填充您的 AST (你的概念的具体语法)。

我在此处放置了一份适度的文档。

Maybe you could have a look at this gem named Astrapi.

This is just an experiment :

  • describe your language elements (concepts) in a "mm" file (abstract syntax)
  • run astrapi on this file
  • astrapi generates a parser that is able to fill up your AST, from your input source expressed in s-expression (concrete syntax of your concepts).

I have put a modest documentation here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文