tags:

views:

63

answers:

1

Creating a Lisp syntax like DSL - very small specific application - but very fast - code generation in C, Antlr a good choice?

It is necessary for many reasons that it be very fast and it will internally call a lot of C++ APIs, hence I cannot write it in a language other than C/C++.

The last time I did something in compilers was in school around 5 years ago in flex/bison.

This time however, I have to write production ready maintainable code for this task. I've been looking into Antlr for quite a while and it seems good. But I've the following concerns:-

  • Is support for C/C++ target good?
  • Is Antlr suitable for building a Lisp syntax like DSL?
  • Overall, will it be better than using flex/bison for this particular application?

Also, if you could let me know what topics/parts of Antlr I should be really good at then it would be great.

Thanks

+1  A: 

ANTLR is good when your syntax is complex.

LISP syntax is not complex, by design. Everything is pretty much handled by two grammar rules:

sexp  = identifier | number | string | '(' sexps ')' ;
sexps = empty | sexps sexp ;

Its such a simple lexer and parser that you can easily implement this as a recursive descent parser (in C or in any other langauge; older LISPs implement this in LISP so they can implement LISP interpreters and compilers directly in LISP).

You can use ANTLR for this, but I think its overkill. If you langauge is actually more complex than you suggest, then ANTLR may be a good choice.

Ira Baxter