Summary
My answer to YACC and Lex, the YARD parser version 1.0, is now online at SourceForge.net.
Advertisement
Due to my distaste for parser generation tools like YACC and Lex and being such a completely unreasonable guy, I decided to write my own recursive descent parser. I first did it in Delphi, then I did it in Heron. Now I just finished version 1.0 of the YARD parser for C++ and I've posted it to SourceForge.net.
The YARD parser is a data-type agnostic CFG parser tool written using template metaprogramming techniques in C++. The YARD parser was designed to be as compact and flexible as possible.
The YARD parser has a significantly different design than its closest cousin, the boost::spirit library, because the grammar productions are defined directly as meta-functions, and there is no funky operator overloading. Semantic actions are defined as template specializations. See my earlier post on Static versus Dynamic Event Handlers in C++.
The YARD parser source code comes with a XML parser as way of a demonstration, of the ease of use etc. There is also a very simple built-in tokenizer for those who might want to use YARD as a powerful lexical analyzer.
They are very different, the primary difference however is: - Spirit gramamr productions are expressed as expressions - YARD grammar productions are expressed as types
Spirit is less verbose, and supports dynamic rules. YARD on the other hand supports only static grammar productions which makes it more compact, flexible, and efficient. Spirit as a result has a lot of limitations with regards to where and how to define rules. It is much easier to write custom rules using YARD.
If you study more closely both libraries, and try to use them, I think the differences will become apparent very quickly. I find the YARD parser far easier to use.
So Yard is more like C++, but the grammar is statically defined rather than dynamically. Spirit also has a weird arbitrary upper limit on the number of case statements and doesn't use real C++ constructs. (what's switch_p / case_p / default_p ?).
> Apparently the previous is a bad comparison. Oh well. I am > not able to figure out a better comparison, Spirit has > left me quite confused.
Maybe you could show a complete Mathematical expression parser with operator precedence in both spirit and YARD so that we could see something that is commonly found in a YACC specification?