Search code examples
scalallvmparser-combinators

What would be a good approach to generate native code from an interpreter written with scala parser combinators?


I already have an interpreter for my language. It is implemented with:

  • parser -> scala parser combinators;
  • AST -> scala case classes;
  • evaluator -> scala pattern matching.

Now I want to compile AST to native code and hopefully Java bytecode. I am thinking of two main options to accomplish at least one of these two tasks:

  • generate LLVM IR code;
  • generate C code and/or Java code;

obs.: GCJ and SLEM seem to be unusable (GCJ works with simple code, as I could test)


Solution

  • I agree with @Oak about the choice of ByteCode as the most simple target. A possible Scala library to generate ByteCode is CafeBabe by @psuter.

    You cannot do everything with it, but for small project it could be sufficient. The syntax is also very clear. Please see the project Wiki for more information.