简体   繁体   中英

Java interpreter or compiler in java

Essentially, I'm building a very condensed point-and-click IDE for Java Au Naturel turtle programs. 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. 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? 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.)

Edit: as computerfreaker already said, this is not a duplicate. I already looked at that question before posting, and mine has nothing to do with the 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.

Have a look at ANTLR

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

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

http://unkrig.de/w/Janino

I have used Janino in serious project as embedded compiler and it was working very reliably (java 6 times). Not sure how up to date it is with new language features from java 8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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