-1

I have my grammar ready and tested in Antlr4 actually I want to have my language source files to become executable and fast enough so I think I have these solutions:

  1. LLVM
  2. JVM
  3. Generating a source code in another language and then compile the generated file(s)

my question is about the solution number 3

what's your opinions? is it a bad practice? what are the challanges? and negative points? is there any tips or suggestions here? about target lang, optimizing, any sources to read, etc

thanks

2 Answers2

1

To get to a minimum viable product (a prototype, a version 0.01) fast I would do the 3rd. For example translate to C. I read somewhere that the hardest parts of creating a good compiler is to return good error messages and to optimize well for the intended CPU or VM. If you chose the 3rd alternative you get (some) optimization for free. And if the compiler proves to be worthwhile improving then LLVM and/or JVM and/or compile directly to binary/assembly. If you have all the time in the world. Whats best also depends on what type of language you've created I guess. First I would check if you have something unique and useful not found in other languages. If not, whats the point of adding yet another language to an already very long list?

Kjetil S.
  • 3,468
  • 20
  • 22
0

One huge drawback in using another text-based language as a backend for your language is in losing precise debugging information - variables, locations, etc.

If you're using a language with rich metadata, such as LLVM IR (and yes, it's not too much lower level than C anyway), you can stuff in all the debugging information you want. It's almost as easy to target LLVM as C.

Another alternative, if you want to benefit from very high level language features and build your new language on top is to use an extensible language as your base - e.g., implement your language as a syntax extension on top of Racket or Common Lisp.

SK-logic
  • 9,605
  • 1
  • 23
  • 35
  • Actually I am agree with you but the problem is I am not familiar with llvm and couldn't understand it...I will work on that but to start I just thought maybe it's better to target another language that I know to be able to atleast make a demo of it – Navid Dezashibi Jul 16 '20 at 18:29
  • @NavidDezashibi for a quick implementation something like Racket is probably the easiest way to go then. Compiling to C or even C++ is also quite easy, as long as you don't care about precise debugging information (you can have some with #line pragma). – SK-logic Jul 16 '20 at 21:20
  • Thank you for the suggestion I'll check racket – Navid Dezashibi Jul 17 '20 at 02:32
  • @NavidDezashibi more details here: https://github.com/racket/racket/wiki/Creating-Languages – SK-logic Jul 17 '20 at 08:17