Results 1 to 20 of 23
Thread: creating new jvm language
- 06-17-2010, 01:04 PM #1
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
creating new jvm language
I am trying to create a new basic language to the jvm Just to keep for myself and learn more.
I have created a parser and lexical analyzer and it looks like I have two options: interpreted and compiled.
I really want to compile my code in valid class files and not to be interpreted by my jar.
But how do I do that? I have heard of becel, are there any other possibilities?
- 06-17-2010, 01:07 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 06-17-2010, 01:19 PM #3
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
thats the problem: the jvm bytecode is pretty hard.
Is there a way to make it less complicate?
- 06-17-2010, 01:22 PM #4
Sort of a contradiction. If you create java class files, the only way to execute them is to have a JVM interpret them. Placing them in a jar file is not relevant.I really want to compile my code in valid class files and not to be interpreted by my jar
If you create native code, then the linker will be needed to create an executable.
Could you explain more about what you want to create? It sounds like you want your own language that you can compile into java class files.
There is a Java Virtual Machine Specification document somewhere that explains the contents of class files.
- 06-17-2010, 01:28 PM #5
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
I know it sounds like a contradiction but on all tutorials I followed they came to a certain point where the lexar analyzer and scanner was finished and they say "you have now to options, building an inerpreter or building a compiler" and they all made an interpreter written in java.
like here:Create Your Own Programming Language - CodeProject
- 06-17-2010, 01:48 PM #6
As has been said, it is complicated.
- 06-17-2010, 01:55 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Nope; unless you want to generate inefficient 'baby code' and only use a fraction of the instruction set. You want to compile to abstract machine code so you have to go the whole nine yards ... unless you want to build an interpreter (which is much easier but still not a trivial task to accomplish).
kind regards,
Jos
- 06-17-2010, 02:27 PM #8
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
thanks for the info so far :)
- 06-17-2010, 03:41 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
I don't know how proficient you are w.r.t. compilers and code generation but here you have to do a bit more: your generated code has to be a class (with the proper access rights) and it has to have initialization code as well as a constructor <init> (if you want to create objects from your class) and a whole lot more structure is imposed by the jvm. It's a hell of a task to do and ASM can help you only partly. Why not cross compile to java source code and let javac do the hard part?
kind regards,
Jos
- 06-17-2010, 06:45 PM #10
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
well, I am hesitating.
I have concluded its to hard to write a real compiler and looking for a solution. Its cross compile to java or cross compile to something like jamaica, I am not sure yet
- 06-17-2010, 08:13 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 06-17-2010, 08:46 PM #12
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
good point. But java is high level, If I wanted to implement things I am afraid it would be rather inefficient to write in java.
Would the jvm optimize this enough, would there be a big difference compared to pure bytecode?
- 06-18-2010, 03:35 AM #13
to write your own lang you have to write your own jvm :) that is the question...
programming language is a big diffrence of a scripting language ;) So as I can hear you try to write a scripting lang using Java...
But ti write a real lang you shall have to come right to the bottom of coding to the precessor depending bin things
I hope you are much patient person as for this 0-1 thing+ 1 my REP
Good Luck :)
- 06-18-2010, 06:50 AM #14
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
why would I have to write my own jvm?
But yes, I have lack of patience :)
And I do try to make a real programming language but very limited, the whole thing is more for education then real use
- 06-18-2010, 07:28 AM #15
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
If the scenario is: your language --> java source code --> virtual machine code --> real machine code, you need your own compiler (step #1), javac (step #2) and the jit compiler (step #3). Depending on how good your code generator is (step #1) the resulting machine code can be quite fast and efficient. Javac and the jit compiler are already written and heavily optimized so it's up to you ;-)
If your language is for educational purposes only, I'd go for the interpreter scenario instead. I have written several compilers and interpreters for the jvm and they we're all quite fast (but not trivial to implement).
kind regards,
Jos
- 06-18-2010, 12:40 PM #16
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
josah, would you mind sharing some code.
I want to have some ideas how to do this the "best" way
- 06-18-2010, 01:20 PM #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 06-18-2010, 03:52 PM #18
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
antlr looks promissing, thanks
- 06-24-2010, 01:15 PM #19
Member
- Join Date
- Jun 2010
- Posts
- 26
- Rep Power
- 0
to generate valid bytecode, you have a range of options, for example ObjectWebASM
- 08-07-2010, 09:40 PM #20
Member
- Join Date
- Aug 2010
- Posts
- 3
- Rep Power
- 0
I did wrote a new language with closures, goto opertator and some other more special features and generated java source code. It worked great and is intended for work, not for research (and therefore it can not be published, it is not an open source).
And now I am thinking about writing an eclipse debugger plugin for it. I hope it can use existing eclipse java debugger and just map between the source code and variables of this language and the java source code and java variables.
I doubt there is a better and faster way to get the good result.
Regards,
Dimitry
Similar Threads
-
How to do to change from a language to an other language?
By Ravanelly in forum New To JavaReplies: 5Last Post: 08-25-2009, 09:41 AM -
Creating a new programming language?
By hawaiifiver in forum Forum LobbyReplies: 0Last Post: 03-21-2009, 08:46 PM -
Is this the right language?
By rws in forum New To JavaReplies: 9Last Post: 11-15-2008, 03:27 PM -
IDE for new language
By mitra2008 in forum EclipseReplies: 2Last Post: 06-23-2008, 06:43 PM -
V language 0.004
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-19-2007, 03:18 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks