Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What programming languages have the most easily-implemented interpreters?

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?

like image 582
sanity Avatar asked Oct 13 '10 22:10

sanity


People also ask

Which programming languages use interpreters?

Programming languages that use interpreters include Python, Ruby, and JavaScript, while programming languages that use compilers include Java, C++, and C.

What is the most commonly used interpreted language?

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.

Is C++ interpreted or compiled?

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.

What programming languages use both compilers and interpreters?

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.


1 Answers

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.

like image 178
juancn Avatar answered Sep 22 '22 05:09

juancn