Our company uses own (built in here) scripting language for programming, but they would like to create interpreter that will translate this script codes to Java. This scripting language is quite serious, so it's no small thing.
I've been asked about this task, but it doesn't seem like trivial challenge. Now before I do anything stupid and start writing billions of lines of parsing, what should I know? Where should I start to make this properly?
PS: I want to translate script files to .java sources, not directly to bytecode.
If you want to translate your script to Java, it's not an interpreter, but a compiler. If you are thinking about just executing the script during reading, it is interpreter.
However, you should look at JavaCC or Antlr. They are both suitable even for compiling or interpreter tasks. You have to specify the language's syntax rules and you have to write some additional logic in Java, implementing semantics of your script language. If you want to make an interpreter, the Java code you write, will generate further Java (or any) code. If you want a compiler, the Java code you write will directly execute the script.
One more concept to good to know about is Abstract Syntax Tree.
Here is a comprehensive list about more lexer and parser generators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With