简体   繁体   English

Java 中的 Java 解释器或编译器

[英]Java interpreter or compiler in java

Essentially, I'm building a very condensed point-and-click IDE for Java Au Naturel turtle programs.本质上,我正在为 Java Au Naturel 海龟程序构建一个非常简洁的点击式 IDE。 The most key part of this is my current interpreter.其中最关键的部分是我目前的口译员。 I've gone through and built each piece from the ground up to properly write commands to a list, then parse the list and execute the related methods.我已经完成并从头开始构建每个部分,以将命令正确写入列表,然后解析列表并执行相关方法。

Unfortunately, this has been something I've held together with the programming equivalent of duct tape to get my proof of concept off the ground, and now doing anything other than turtle-specific methods (think loops, variables, conditional statements) is leaving me stumped.不幸的是,这一直是我与管道胶带等价的编程结合在一起的东西,以实现我的概念证明,现在除了特定于海龟的方法(想想循环、变量、条件语句)之外的任何事情都让我离开了难倒。

I've written an interpreter that uses real java syntax thus far so people can see the code and maybe even export it to work in a more traditional manner when they get comfortable.到目前为止,我已经编写了一个使用真正的 Java 语法的解释器,因此人们可以看到代码,甚至可以在他们感到舒服时将其导出以更传统的方式工作。 I'd like to keep it that way.我想保持这种状态。

Is there perhaps a simpler way to write and run a Java program from within another one?是否有一种更简单的方法可以从另一个程序中编写运行Java 程序? If not, any advice or resources about writing an interpreter are greatly appreciated.如果没有,非常感谢有关编写解释器的任何建议或资源。 Thank you ^~^谢谢^~^

(You may recognise this question from Stack Exchange Programmers... not entirely sure how I ended up on that site instead of this one, but I am still an enthusiast, not a professional, so the question's better posed here.) (您可能从 Stack Exchange Programmers 那里认出了这个问题……不完全确定我是如何在那个网站而不是这个网站上结束的,但我仍然是一个爱好者,而不是专业人士,所以这个问题最好在这里提出。)

Edit: as computerfreaker already said, this is not a duplicate.编辑:正如computerfreaker 已经说过的,这不是重复的。 I already looked at that question before posting, and mine has nothing to do with the JVM.我在发布之前已经看过那个问题,我的与 JVM 无关。 It's not a question of what anything is.这不是什么是什么的问题。 My question is whether there is an easier way to make and run a .java file from within a program, or if I should just keep trying to write an interpreter.我的问题是是否有一种更简单的方法可以从程序中创建和运行 .java 文件,或者我是否应该继续尝试编写解释器。

Have a look at ANTLR看看 ANTLR

http://www.antlr.org/ http://www.antlr.org/

It's a very easy way to get an interpreter or compiler up and running and there are grammars for Java这是启动并运行解释器或编译器的一种非常简单的方法,并且有 Java 语法

https://github.com/antlr/grammars-v4 https://github.com/antlr/grammars-v4

There are dozens more than this but it will give you an idea of what you need to do.还有几十个,但它会让你知道你需要做什么。

Please take a look at these two请看看这两个

https://github.com/albertlatacz/java-repl https://github.com/albertlatacz/java-repl

http://unkrig.de/w/Janino http://unkrig.de/w/Janino

I have used Janino in serious project as embedded compiler and it was working very reliably (java 6 times).我在严肃的项目中使用过 Janino 作为嵌入式编译器,它工作得非常可靠(Java 6 次)。 Not sure how up to date it is with new language features from java 8.不确定 Java 8 的新语言功能的最新情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM