0

Are there any frameworks similar to the LLVM or Parrot Compiler Toolkit that makes writing compilers targeting JVM easier?

I'm hoping for the framework to have AST to code generator. So, I could write a language frontend which constructs the AST based on the framework libraries, then the framework can do the rest and compile into JVM bytecode.

Polyglot looks like a project that would be useful for what I'm trying to do.

ruben2020
  • 1,549
  • 14
  • 24

2 Answers2

1

To start with, I would generate Java code which you can compile (optionally in memory). This will save you a lot of grief in terms of debugging, verify errors, and development time. Once you have something stable and working you can look at making it more efficient by writing byte code instead.

This library Java Runtime Compiler allows you to compile a class and nested classes in memory at runtime. When you are debugging it can write the files to disk allowing you to step into your generated code.

You get high level, descriptive error messages, and can see exactly what the code is trying to do.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

This sentence

I'm hoping for the framework to have AST to code generator.

tells me that you've got a long way before you.

Just one uncomfortable truth: There is no such thing as the AST.

When you design your language, you somehow also define the set of possible syntax trees. Think about how unlikely it is that someone wrote a code generator for your language before you even designed it.

Ingo
  • 36,037
  • 5
  • 53
  • 100