views:

60

answers:

4

Hi, i'm thinking on doing an undergrad project on building an interpreter for a simple/rudimentary custom language (perl / C like). I would be be glad if someone could point me in the right direction to start. Most of the books/resources i find are on theoretical implementation of compilers. Are there any resources aimed at interpreters ? i'm thinking of implementing it in C++, but have very little knowledge on the subject of interpreter design, so any pointers to books/references will be appreciated

+3  A: 

The parsing of the source code is not very much different between a compiler and an interpreter. And that is what most textbooks on compilers are about.

Frank
+2  A: 

There are some nice tools now to implement custom languages.

You might want to checkout Xtext in the Eclipse Modelling Package (http://www.eclipse.org) or MPS (http://www.jetbrains.com/mps/), the language workbench of IntelliJ which is freely available.

Both allow you to create languages and provide the tools to generate code from the source and the tooling to help creating the code.

They also create abstract syntax trees which may be directly manipulated, i.e. executed. Then you have an interpreter.

The classical approach would be to use bison/yacc for as a lexer, respectively parser, and many newer tools are currently available like antlr. The output of the parser is then again the abstract syntax tree ready to do interprete or generate code from.

Peter Tillemans
+1  A: 

An Incremental Approach to Compiler Construction - it's about creating compilers, but it might be a good starting point to find references from.

Rekin
+1  A: 

I wrote an interpreter for reading and converting logic expressions at Uni. Wrote it in C, Lexx and Yacc which old school Unix and C programmers seem to swear by. Pretty powerful once you get the hang of them, but reasonably steep learning curve I would say.

http://www.lugbe.ch/action/reports/lex_yacc.pdf

shaw2thefloor