views:

177

answers:

3

In my ongoing effort to quench my undying thirst for more programming knowledge I have come up with the idea of attempting to write a (at least for now) simple programming language that compiles into bytecode. The problem is I don't know the first thing about language design. Does anyone have any advice on a methodology to build a parser and what the basic features every language should have? What reading would you recommend for language design? How high level should I be shooting for? Is it unrealistic to hope to be able to include a feature to allow one to inline bytecode in a way similar to gcc allowing inline assembler? Seeing I primarily code in C and Java which would be better for compiler writing?

+1  A: 

You might want to read a book on compilers first.

For really understanding what's going on, you'll likely want to write your code in C.

Java wouldn't be a bad choice if you wanted to write an interpreted language, such as Jython. But since it sounds like you want to compile down to machine code, it might be easier in C.

Jweede
+1  A: 

I recommend reading the following books:

ANTLR

Language Design Patterns

This will give you tools and techniques for creating parsers, lexers, and compilers for custom languages.

Todd Stout
+2  A: 

There are so many ways...

You could look into stack languages and Forth. It's not very useful when it comes to designing other languages, but it's something that can be done very quickly.

You could look into functional languages. Most of them are based on a few simple concepts, and have simple parsing. And, yet, they are very powerful.

And, then, the traditional languages. They are the hardest. You'll need to learn about lexical analysers, parsers, LALR grammars, LL grammars, EBNF and regular languages just to get past the parsing.

Targetting a bytecode is not simply a good idea, it's just insane, and mostly useless, to do otherwise as a learning exercise.

Do yourself a favour, and look up books and tutorials about compilers.

Either C or Java will do. Java probably has an advantage, as object orientation is a good match for this type of task. My personal recommendation is Scala. It's a good language to do this type of thing, and it will teach you interesting things about language design along the way.

Daniel