views:

447

answers:

7

What real programming languages are easy to write interpreters for?

"Real" languages for me, are languages you can actually write a small project with, not one of the easy Esoteric programming languages.

(I'm asking because I want to do some hobby project.)

+5  A: 

The original Wirth's Pascal is a good candidate, and often used as a demo in parser generators. Its grammar is LL(1), and otherwise fairly strict, so it's easy to parse. Feature-wise it's pretty limited as well.

You might want to fiddle with it a bit a bit, though - e.g. you might want to ignore pointers, but support first-class strings.

Pavel Minaev
+3  A: 

Scheme, or any lisp variant.

ראובן
This is a bit deceptive; while the syntax is certainly not difficult to parse, the functionality of Scheme and other LISP variants can be quite difficult to implement in an interpreter. Lambdas and tail recursion in particular have a lot of pitfalls.
Imagist
+9  A: 

The Metacircular Evaluator in SICP is an exercise for writing a Scheme interpreter in Scheme. It's a common first-year CS project.

Meredith L. Patterson
For those who don't know, SICP is a book (free online) called Structure and Interpretation of Computer Programs.
trinithis
A: 

I would think a markup syntax language, Liran. The syntax structure makes for easy parsing since code blocks are clearly delineated between begin and end tags. You could theoretically easily build a level 1 interpreter that parses and runs the code directly.

That said there aren't any markup languages out there that do meaningful things in the context I seem you are aiming at (you may want to write your own). Next best choice would probably languages with minimum functionality and preferably not supporting procedural programming. A language like BASIC should be easy to build a level 1 interpreter for.

Next best thing perhaps is early script languages which didn't offer many syntactic elements and were rather short in complexity. I fail to think of any though.

But perhaps the best option of all is for you to design your own language. The interpreter becomes easier to build because you have a deep knowledge of the language syntax and can rule your own language structure and semantics in the interpreter.

...

The insistence on level 1 interpreter is because you did mention you want it easy.

Krugar
+1  A: 

In my college operating systems class we wrote an interpreter for Db (D-flat). It was very simple and well-defined.

bkritzer
Could you please provide a link to something related to this language, I can't seem to find it...
Liran Orevi
You're right. I couldn't find it anywhere online either, except the website for the class. Perhaps it's a made-up language for our class. Either way, here's a link to the formal language definition:http://users.csc.calpoly.edu/~akeen/courses/csc430/handouts/assignments/hw3.pdf
bkritzer
Perhaps it's based on the system described in Dr. Dobbs Journal (anyone around that knows about DDJ?). In this article (http://www.drdobbs.com/184410754) Al Stevens announced the idea for D-Flat and in subsequent articles described it's development.
Kwebble
+2  A: 

Forth. Okay, now I'm only typing this because I need at least 15 characters in the answer, but the smallest Forth implementations are a couple of KB. It's hard to think of any other language that could have such a small core. Maybe the original McCarthy 1958 Lisp, where the functions were hand compiled.

David Plumpton
+4  A: 

It is very easy to write an interpreter for the programming language Forth (once you know how - but it is well documented). Forth has been in use for real-world problems for more than 40 years.

Perhaps it is too easy, but you will learn a lot in the process.

A light-hearted (online) introduction is in chapter 9 of Leo Brodie's "Starting FORTH".

Peter Mortensen
Thanks for the link.
Liran Orevi