Java compilers or JVM languages that support goto?

前端 未结 9 2116
孤城傲影
孤城傲影 2021-01-12 20:22

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?

相关标签:
9条回答
  • 2021-01-12 20:47

    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.

    0 讨论(0)
  • 2021-01-12 20:58

    You can write your code generator to target Jasmin. You can use goto in Jasmin as much as you like. :-)

    0 讨论(0)
  • 2021-01-12 20:59

    Java does not allow using goto keyword. However, it allows using labels and using break or continue with label instead of goto. In facts, Java is not a language without goto statement, but a language with uncomfortable implementation of it.

    0 讨论(0)
  • 2021-01-12 21:01

    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.

    0 讨论(0)
  • 2021-01-12 21:02

    Apache Thrift can be used to generate source code in different programming languages from a single source. http://incubator.apache.org/thrift/

    0 讨论(0)
  • 2021-01-12 21:02

    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

    0 讨论(0)
提交回复
热议问题