Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default 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?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dinosoep View Post
    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?
    There's also 'asm'; it allows you to create, read and manipulate classes in the jvm itself; it's complicated stuff ...

    kind regards,

    Jos

  3. #3
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    thats the problem: the jvm bytecode is pretty hard.
    Is there a way to make it less complicate?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    I really want to compile my code in valid class files and not to be interpreted by my jar
    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.
    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.

  5. #5
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    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

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    As has been said, it is complicated.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dinosoep View Post
    thats the problem: the jvm bytecode is pretty hard.
    Is there a way to make it less complicate?
    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

  8. #8
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    thanks for the info so far :)

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dinosoep View Post
    thanks for the info so far :)
    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

  10. #10
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    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

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dinosoep View Post
    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
    Well, since you posted your question in a Java forum and because you have probably implemented your lexical analyzer and parser in Java why not stick to Java?

    kind regards,

    Jos

  12. #12
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    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?

  13. #13
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Default

    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 :)

  14. #14
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    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

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dinosoep View Post
    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?
    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

  16. #16
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    josah, would you mind sharing some code.
    I want to have some ideas how to do this the "best" way

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dinosoep View Post
    josah, would you mind sharing some code.
    I want to have some ideas how to do this the "best" way
    When it comes to compiler technology the best resource is "The Dragon Book" by Aho (Sethi) and Ullman (sp?) Currently I'm playing with ANTLR, a very powerful parser generator (and it generates the lexical analyzer with it).

    kind regards,

    Jos

  18. #18
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    antlr looks promissing, thanks

  19. #19
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    to generate valid bytecode, you have a range of options, for example ObjectWebASM

  20. #20
    pld
    pld is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default

    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

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 08-25-2009, 09:41 AM
  2. Creating a new programming language?
    By hawaiifiver in forum Forum Lobby
    Replies: 0
    Last Post: 03-21-2009, 08:46 PM
  3. Is this the right language?
    By rws in forum New To Java
    Replies: 9
    Last Post: 11-15-2008, 03:27 PM
  4. IDE for new language
    By mitra2008 in forum Eclipse
    Replies: 2
    Last Post: 06-23-2008, 06:43 PM
  5. V language 0.004
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-19-2007, 03:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •