gpt4 book ai didi

java - 从新语言到 C 子集的源代码翻译器

转载 作者:行者123 更新时间:2023-12-02 08:00:50 25 4
gpt4 key购买 nike

我正在开发一个项目,该项目已经实现了新的语言。我被分配的任务是为该语言构建一个翻译器。翻译器应该用 Java 构建,翻译输出应该将新语言的子集生成为 C 语言。对此我有几个问题:1. 如何进行?2.我应该更强调哪个阶段?它应该是编译器的代码生成器阶段吗?3. 我还需要掌握目标语言的语法吗?

提前致谢。

最佳答案

如果您至少还没有意识到的话,我会研究 ANTLR。来自 http://www.antlr.org/about.html (强调我的):

ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, compilers, and translators from grammatical descriptions containing actions in a variety of target languages. ANTLR automates the construction of language recognizers. From a formal grammar, ANTLR generates a program that determines whether sentences conform to that language. In other words, it's a program that writes other programs. By adding code snippets to the grammar, the recognizer becomes a translator or interpreter. ANTLR provides excellent support for intermediate-form tree construction, tree walking, translation and provides sophisticated automatic error recovery and reporting.

作为一个额外的好处,ANTLR 是用 Java 编写的并且可以轻松地由 Java 调用。

更多详细信息请访问 http://en.wikipedia.org/wiki/ANTLR .

关于java - 从新语言到 C 子集的源代码翻译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8936178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com