向 clang 添加替代语法
我遇到了 C++ 的 SPECS 替代语法,而我'我不确定我是否喜欢他们所做的一些更无端的语法更改(例如,将指针从 * 更改为 ^),这让我产生了调整和实现新语法的想法。 SPECS 声称在语义上与 C++ 相同,并且 Clang 非常模块化,因此我认为编写 Clang 的 AST 并利用所有预先存在的代码应该不会太难。
话虽这么说,我不太确定修改 Clang 当前的 Lexer 和 Parser 以接受不同的标记和排序(从而利用它们的错误消息)有多容易,或者是否更容易做到这一点而不是编写一个单独的解析器,只调用 Clang 的 AST。过去几天我一直在研究文档,但我想知道这里是否有对代码库有更多经验的人可以给我一些关于我是否应该搜索
- API 来更改词法/解析功能
- 类 的意见为了实现我想要的功能而彻底更改/子类化,
- 最好的方法是编写我自己的解析以与 AST 交互。
I ran across the SPECS alternate grammar for C++, and while I'm not sure I like some of the more gratuitous syntax changes they made (changing pointers from * to ^, for instance), it turned me on to the idea of tweaking and implementing the new syntax. SPECS claims to be semantically identical to C++, and Clang is pretty modular, so I figured it shouldn't be too hard to write to Clang's AST, and take advantage of all the preexisting code.
That being said, I'm not really sure how easy it would be to modify Clang's current Lexer and Parser to accept different tokens and orderings (thereby taking advantage of their great error messages), or whether it would be easier to do that instead of writing a separate parser that just makes calls to Clang's AST. I've been poking around with the documentation over the past couple days, but I was wondering if someone out here with more experience with the codebase could give me some input on whether I should be searching for
- APIs to change the lexing/parsing functionality
- classes to outright change/subclass for my desired functionality
- the best ways to write my own parsing to interface with the ASTs instead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论