使用不支持的语言进行语法检查

发布于 2024-10-29 04:37:31 字数 473 浏览 1 评论 0原文

我有一些文件具有类似于 ada 的特定语法(尽管不完全相同),但是我想在运行它们之前验证语法。这些文件没有编译器,因此我无法在使用它们之前检查它们。我尝试使用以下内容:

gcc -c -gnats <file>

但这表示需要编译单元。我已经尝试了一些变体,但没有成功。

我只是想在使用文件之前确保该文件在语法上正确,但我不确定如何做到这一点,而且我真的不想为此编写整个语法检查器。

是否有某种方法可以在不重新编译的情况下将其他不受支持的语言包含到 gcc 中?这是否只是一个文件,向 gcc 详细说明语法结构是什么,或者需要什么?我不需要完整的编译,只需要语法检查。

或者,是否有任何我可以使用的语法检查器,我可以通过该语言所需的少量更改来更新 ada 语法检查?

我将 Ada 列为标签,因为语法几乎相同,并且找到无需编译即可进行 ada 语法检查的东西对我来说是 90% 的解决方案。

I have some files that have a particular syntax that is similar to ada (not identical though), however I would like to verify the syntax before going and running them. There isn't a compiler for these files, so I can't check them before using them. I tried to use the following:

gcc -c -gnats <file>

However this says compilation unit expected. I've tried a few variations on this, but to no avail.

I just want to make sure the file is syntactically correct before using it, but I'm not sure how to do it, and I really don't want to write an entire syntax checker just for this.

Is there some way to include an additional unsupported language to gcc without going through a recompile? Also is this simply a file that details to gcc what the syntax constructs are, or what would be entailed? I don't need a full compile, only a syntax check.

Alternately, are there any syntax checkers I can use that I can update an ada syntax check with the small number of changes required for this language?

I've listed Ada as a tag, since the syntax is nearly identical, and finding something that will do ada syntax checking without compiling will be a 90% solution for me.

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

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

发布评论

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

评论(1

苍暮颜 2024-11-05 04:37:31

您可以先尝试通过 gnathop 运行文件。 GCC Ada 编译器相当独特,因为它期望文件名与文件内的主要单元名称匹配。这可能就是您的错误消息想要表达的内容。

gnatchop 将遍历您提供的所有文件,并用适当的名称写出 Ada 源文件,以使 gcc 满意(甚至在需要时将文件拆分为多个文件)。

您可能感兴趣的另一个选项是 OpenToken。它是一个用 Ada 编写的解析器构建工具包,可以让您相当轻松地构建自己的解析器。它附带了 Ada 语法识别器,因此您可以根据自己的需要对其进行一些调整。

You could try running the files through gnatchop first. The GCC Ada compiler is rather unique in that it expects filenames to match up with the main unit names inside the file. That may be what your error message is trying to say.

gnatchop will go through any files you give it and write out Ada source files with the appropriate names to make gcc happy (even splitting files into multiple files if needed).

Another option you might be interested in is OpenToken. It is a parser construction toolkit, written in Ada, that allows you to build your own parsers fairly easily. It comes with a syntax recognizer for Ada, so you may just be able to tweak that a bit for your needs.

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