ANTLR的AST树更新

发布于 2024-12-21 07:49:37 字数 165 浏览 4 评论 0原文

我使用 ANTLR 工具生成的 Lexer 和 Parser 类(针对 C#)。假设我已经解析了一些代码并得到了它的 AST 树。如果我的部分初始代码已更改并且我只想更新树的相应部分怎么办?有一个通用的方法可以做到这一点吗? 例如,在某些函数体内插入了一行代码。我只想重建表示该函数的树的部分并更新后续函数标记的位置

I use Lexer and Parser classes generated by ANTLR tool (targeting C#). Assume I have parsed some code and got an AST tree for it. What if part of my initial code has changed and I want to update just the corresponding parts of the tree? Is there a common way to do that?
For example a line of code was inserted inside some functions body. And I want to rebuild just the part of the tree representing this function and update positions of subsequent functions tokens

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

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

发布评论

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

评论(1

携君以终年 2024-12-28 07:49:37

有一些项目可以实现您可能想要完成的任务。
但不知道ANTLR是否支持这个。
您可以查看:http://en.wikipedia.org/wiki/Incremental_compiler

语法突出显示仅建议,我建议对语法中的不同标记使用正则表达式。 (如果您仅更新正在处理的行,则不应出现任何性能问题。)

There are a few projects out there which do what you might want to accomplish.
But I don't know if ANTLR supports this.
You might take a look at: http://en.wikipedia.org/wiki/Incremental_compiler

For syntax highlighting propose only, I suggest using regular expression for the different token in your syntax. (If you update just the line you're working on you should not get any performance problems.)

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