如何解析 Java 中的 REXX 代码?

发布于 2024-07-16 04:26:19 字数 135 浏览 9 评论 0 原文

我想解析 REXX 源代码,以便我可以从 Java 分析程序的结构。

我需要做一些事情,比如标准化源代码中语法不同的等效逻辑结构、查找重复的变量声明等,而且我已经有 Java 背景。

有比编写大量代码更简单的方法吗?

I'd like to parse REXX source so that I can analyse the structure of the program from Java.

I need to do things like normalise equivalent logic structures in the source that are syntactically different, find duplicate variable declarations, etc. and I already have a Java background.

Any easier ways to do this than writing a load of code?

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

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

发布评论

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

评论(3

从此见与不见 2024-07-23 04:26:19

REXX 不是一种容易用常用工具解析的语言,尤其是那些需要 BNF 语法的语言。 与大多数接触 C 的人设计的语言不同,REXX 没有任何保留字,这使得任务有些复杂。 每个看起来像保留字的术语实际上仅在其特定上下文中解析(例如,“PULL”仅保留为 PULL 指令的第一个字或第二个字) PARSE PULL 指令的单词 - 您还可以有一个名为 PULL 的变量(“PULL = 1 + 2”))。 另外,评论还有一些非常令人惊讶的效果。 但是 ANSI REXX 标准 具有完整的语法和所有规则。

REXX is not an easy language to parse with common tools, especially those that expect a BNF grammar. Unlike most languages designed by people exposed to C, REXX doesn't have any reserved words, making the task somewhat complicated. Every term that looks like a reserved word is actually only resolved in its specific context (e.g., "PULL" is only reserved as the first word of a PULL instruction or the second word of a PARSE PULL instruction - you can also have a variable called PULL ("PULL = 1 + 2")). Plus there are some very surprising effects of comments. But the ANSI REXX standard has the full syntax and all the rules.

西瓜 2024-07-23 04:26:19

如果您有 BNF Rexx 语法,则javacc 可以帮助你构建一个 AST(抽象语法树)表示。

更准确地说,javacc 将构建 Java 类,它将:

  • 解析 Rexx 代码并
  • 实际构建 AST。

仍然会有“代码负载”,但您不会是为该 Rexx 代码解析器编写类的人。 只有它的一代。

If you have BNF Rexx grammar, then javacc can help you build an AST (Abstract Syntax Tree) representation of that Rexx code.

More accurately, javacc will build the Java classes which will :

  • parse Rexx code and
  • actually builds the AST.

There would still be "load of code", but you would not to be the one doing the writing of the classes for that Rexx code parser. Only its generation.

感情旳空白 2024-07-23 04:26:19

看看 ANTLR,它确实在构建 AST、转换它等方面做得很好......
它有一个很好的编辑器(ANTLRWorks),基于 Java 构建,并且可以在解析器/树遍历器在您的应用程序中运行时对其进行调试。 对于任何类型的解析工作都确实值得研究。

Have a look at ANTLR, it really does a nice work of building an AST, transforming it etc...
It has a nice editor (ANTLRWorks), is built on Java, and can debug your parser / tree walkers while they run in your application. Really worth investigating for any kind of parsing job.

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