开发者

A small lisp like DSL that gets compiled into C/C++ code -- Antlr a good choice?

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开发者_如何学Go 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


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 language; 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 your language is actually more complex than you suggest, then ANTLR may be a good choice.

Building a good DSL usually requires a LOT more than just parsing. See my essay on "Life After Parsing" (via bio) for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜