支持 goto 的 Java 编译器或 JVM 语言?
是否有一个 java 编译器标志允许我使用 goto
作为有效的构造? 如果没有,是否有第三方java编译器支持goto
? 如果没有,是否有其他语言支持goto
,同时可以轻松调用Java编写的方法?
原因是我正在编写一种用 Java 实现的语言。 Goto 是我的语言的重要组成部分; 我希望能够将其编译为本机或 JVM 字节码,尽管它必须能够轻松使用 Java 库(即 C 支持 goto
,但要使用它,我必须重写C 中的库)。
我想生成 C 或 Java 等源文件,而不是字节码或机器代码。 我正在使用第三方编译器来做到这一点。
Is there a java compiler flag that allows me to use goto
as a valid construct? If not, are there any third-party java compilers that supports goto
? If not, are there any other languages that support goto
while at the same time can easily call methods written in Java?
The reason is I'm making a language that is implemented in Java. Gotos are an important part of my language; I want to be able to compile it to native or JVM bytecode, although it has to be able to easily use Java libraries (ie. C supports goto
, but to use it I'd have to rewrite the libraries in C).
I want to generate C or Java, etc source files, and not bytecode or machine code. I'm using a third-party compiler to do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
JVM 支持字节码级别的 goto。
如果您使用自己的语言,则应该使用 BCEL 或 ASM,不生成 .java 文件。
JVM support goto at bytecode level.
If you are doing your own language, you should use libraries like BCEL or ASM, not generating .java file.
JVM 字节码包含 goto 指令(例如,请参阅 BCEL 文档)。
不要忘记 Java 本身支持跳转到标签的概念,使用:
或
请参阅此 JDC 技术提示了解更多信息。 如果您的语言被编译为 JVM 字节码,那么您也许可以利用它。
The JVM bytecode contains a goto instruction (e.g. see the BCEL documentation).
Don't forget that Java itself supports the concept of jumping to labels, using:
or
See this JDC tech tip for more info. If your language is compiled to JVM bytecode, then you may be able to make use of this.
根据定义,没有 Java 编译器允许 goto。 Java 编译器必须实现 JLS,并且 JLS 不允许 goto。 然而,显然也可以编译带有 goto 的语言到 JVM。 AMPC 是一种 C 到 JVM 编译器,声称支持 C89。
另请注意,Java 字节码有一个 goto 指令,尽管它显然是基于指令的而不是基于行的。
By definition, no Java compiler allows goto. Java compilers must implement the JLS, and the JLS does not allow gotos. However, it is also clearly possible to compile a language with gotos to the JVM. AMPC is one C-to-JVM compiler that claims to support C89.
Also note that Java bytecode has a goto instruction, though it's obviously instruction-based not line-based.
您可以编写代码生成器来定位 Jasmin。 您可以在 Jasmin 中随意使用 goto。 :-)
You can write your code generator to target Jasmin. You can use goto in Jasmin as much as you like. :-)
几乎任何你能用 goto 完成的事情都可以用循环完成。 goto 确实是一种多余且普遍不可信的编程方式。 恕我直言。
如果你想向后移动
如果你想向前移动
Pretty much anything you can do with goto you can do with a loop. goto is really redundant and generally discredited way to program. IMHO.
If you want to goto backwards
If you want to goto forwards
goto
关键字是保留的,但在 Java 编程语言中未使用。 (来自 第 3.9 节 < a href="http://docs.oracle.com/javase/specs/jls/se5.0/html/j3TOC.html" rel="nofollow noreferrer">Java 语言规范。)因此,在至少在Java编程语言中,没有办法启用
goto
。但是,正如已经指出的,
Java 虚拟机中的 goto
opcode 是有功能的,当 Java 编译器从源代码生成字节码时使用。第 7 章:编译 Java 虚拟机< /a> 来自 Java 虚拟机规范< /a> 在实现 JVM 语言时可能会感兴趣。
The
goto
keyword is reserved but unused in the Java programming language. (From Section 3.9 of The Java Language Specification.)Therefore, at least in the Java programming language, there is no way to enable the use of
goto
.However, as already noted, the
goto
opcode in the Java virtual machine is functional, and used when the Java compiler produces bytecode from the source.Chapter 7: Compiling for the Java Virtual Machine from The Java Virtual Machine Specification may be of interest when implementing a JVM language.
Apache Thrift 可用于从单一源生成不同编程语言的源代码。 http://incubator.apache.org/thrift/
Apache Thrift can be used to generate source code in different programming languages from a single source. http://incubator.apache.org/thrift/
Java 不允许使用
goto
关键字。 但是,它允许使用标签并使用带有标签的break
或continue
而不是goto
。 事实上,Java并不是一种没有goto语句的语言,而是一种执行起来很不舒服的语言。Java does not allow using
goto
keyword. However, it allows using labels and usingbreak
orcontinue
with label instead ofgoto
. In facts, Java is not a language without goto statement, but a language with uncomfortable implementation of it.你永远不应该使用 goto,因为它是邪恶的;-)
更严重的是,也许你可以看看 E. Dijkstra 的著名文章:
http://www.u.arizona.edu/~rubinson/copyright_violations/ Go_To_Considered_Harmful.html
You shouldn't, ever, use goto, as it's EVIL ;-)
More seriously, maybe you could have a look at the famous article from E. Dijkstra :
http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html