I need to implement an interpreter for a programming language as part of a project I'm working on. I don't think the details of this project are too relevant, except that it requires me to implement an interpreter from scratch, I can't use an existing programming language (the requirements include supporting portable delimited continuations, and being able to write an interpreter for it in Javascript, and also in Java).
Obviously I would really rather avoid inventing a whole new programming language, so I'm hoping there is some very simple language I could copy, or at least draw inspiration from.
My first thought was Forth or a rudimentary Lisp-like language, however I'd really prefer the language have a syntax closer to more popular programming languages like Java, Python, or Ruby. In particular, this means supporting infix operators (a+b), and also a=b assignment of variables.
To put it another way, I'd like this language to feel reasonably familiar to people who program in PHP today, and I don't believe either Forth or Lisp meet this criteria.
Can anyone offer any suggestions for such a language?
Programming languages that use interpreters include Python, Ruby, and JavaScript, while programming languages that use compilers include Java, C++, and C.
An interpreted language executes a code line by line instead of doing it as a whole. The interpreter executes the translated code before translating the next line of code. Some of the most commonly used interpreted languages are PHP, RUBY, Python, JavaScript, Perl, and Basic.
What is Compiled Language? A compiled language is a programming language that is converted into machine code so that the processor can execute it. The compiled languages are usually compiled, not interpreted. For better understanding you can go through the types of compiled language – CLEO, COBOL, C, C++, C#, etc.
Java can be considered both a compiled and an interpreted language because its source code is first compiled into a binary byte-code. This byte-code runs on the Java Virtual Machine (JVM), which is usually a software-based interpreter.
I think that Lisp and Forth have some of the easiest naive interpreters.
You can choose a simple dynamic language, and the hardest part would be building the parser. For example, a subset of JavaScript might work. The interpreter is basically traversing the AST and doing the operations of each node.
In any case, research existing scripting languages that can be embedded in your development environment, and avoid rolling your own at all costs. Implementing compilers (in the broad sense) is very fun to do, but it can be expensive to maintain in the long run.
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