I want to create a very simple experimental programming language. What are some resources can i check out to get an overview of the process of creating an interpreted language. I will be using c++ to build and compile the interpreter.

- 26,308
- 17
- 56
- 95

- 18,300
- 28
- 78
- 125
-
1That one is a bit too LISP specific. – Georg Fritzsche May 27 '10 at 17:28
-
1@Neil:while similar, that's not really a duplicate -- it asks about a Lisp interpreter, and the answers are mostly exclusive to Lisp as well. While the OP's language *might* be enough like Lisp for those to apply, there's no certainty of it. – Jerry Coffin May 27 '10 at 17:28
-
Related: http://stackoverflow.com/questions/1669/learning-to-write-a-compiler – Georg Fritzsche May 27 '10 at 17:32
-
1"How do I make an interpreted language?" "How about you check out all of this stuff about compilers that isn't really relevant" – JamEngulfer Sep 27 '16 at 21:28
4 Answers
You need to implement both a parser and an interpreter.
There is a great free text book called "Programming Languages: Application and Interpretation" that uses scheme to build increasingly more complex interpreters. It also serves as a great introduction to programming language features.
Check it out here: http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/
If Scheme isn't your cup of tea it may be worth looking into.

- 66
- 3
-
2
-
I understand C++ and scheme are nowhere near each other on the spectrum of languages, but the approach this book takes with Scheme may result in the asker learning more about the underlying principles of language design. – Ben May 27 '10 at 17:38
A few steps:
First, build the lexer and parser. This is really easy to do with common tools such as lex and yacc, or using a more modern framework such as Antlr (which is what I recommend). These tools will generate source code for your target language that you can then compile and include in your project.
The lexer and parser will build the internal representation of the source file. There are a few different ways of approaching this:
- In the bytecode model, the source file is compiled into a low-level internal language, for which you write a bytecode interpreter that directly executes the operations. This is the way that Perl and the .NET languages work, for example.
- In the object tree model, the source file is compiled into an object tree where every object knows how to execute itself. Once parsing is completed, you just call
Exec()
on the root object (which in turn callsExec()
on its children, etc.). This is basically the method that I use for my interpreted domain-specific language Phonix.

- 40,684
- 18
- 101
- 169
To create an interpreted language, you need to create two things:
- A formal definition of the language's grammar
- A parser that can read and interpret the language
Once you have defined the language itself, there are several tools available to assist in creating a language parser. The classic tools are lex and yacc, and their open-source versions flex and bison.

- 43,959
- 6
- 69
- 99