[antlr-interest] Antlr vs Spirit
braden at endoframe.com
Fri Feb 25 03:01:26 PST 2005
On Sun, 2005-02-20 at 11:36 +0100, Hrvoje Nezic wrote:
> I hope that this subject is not off topic (please excuse me if it
> A few days ago I had a heated discussion with my colleagues
> at work about parser generators. I use Antlr while some other
> people use Spirit. It seems that Spirit is rather popular in the C++
> "Spirit is an object oriented recursive descent parser generator
> framework implemented using template meta-programming techniques." "
> Parser objects are composed through operator overloading and the
> result is a backtracking LL(inf) parser that is capable of parsing
> rather ambiguous grammars. "
> Antlr documentation or web site mentions other parser generators like
> JavaCC, but it doesn't mention Spirit. Does Spirit bring something new
> regarding computation of lookahead sets (like Antlr's approximate
I don't think so. Spirit keeps looking ahead until it finds--or
definitely does not find--a match.
> Actually I don't understand how complex algorithms that should analyze
> complex grammars could be implemented with C++ templates, but that is
> another question.
And one that can only be answered by furthering your understanding of
C++ templates. Some books you may want to look at on the subject are
"C++ Templates" by Vandevoorde and Josuttis, and "C++ Template
Metaprogramming" by Abrahams and Gurtovoy.
> Perhaps I should address these questions to the Spirit mailing list,
> but I thought it would be interesting to hear opinions from Antlr
> community. BTW, I don't intend to move to Spirit :)
I have used both. The main accomplishment of Spirit is what it manages
to let you do without having to resort to a code generator like antlr
(or yacc, etc.). I don't buy the assertion that it is inherently Good
for a grammar to be in a language distinct from the parser
implementation language; most grammars only get implemented by one
parser written in one programming language. What's important is that the
grammar is readable; and Spirit accomplishes that.
But while *what* a Spirit parser is supposed to do is generally lucid,
*how* it does it is a bit obfuscated. As Spirit becomes more featureful
and robust, the need for users to understand these obfuscated bits is
diminished. But I don't think Spirit is "there" yet.
Spirit's feature set is not well-geared to writing parsers for large-,
and probably most medium-, sized languages. I think that is likely to
change as the project continues to evolve. But today it is outclassed in
that role. Spirit does excel at the larger end of small parsing tasks,
where regular expressions would be too unwieldy and writing a parser in
something like antlr is just too inconvenient. Since all you need for
Spirit is a modern C++ compiler *and it imposes no runtime dependency*,
the barrier to entry is pretty low (notwithstanding the prospective
user's understanding of C++ templates).
Braden McDaniel e-mail: <braden at endoframe.com>
<http://endoframe.com> Jabber: <braden at jabber.org>
More information about the antlr-interest