I’m new to lex and yacc and trying to use one of their ruby derivatives
to
build a parser for level 2 cascading style-sheets (CSS2). I’m having
trouble deciding whether to use rex & racc or ruby-lex & ruby-yacc. Can
someone help me out by explaining to me the ramifications of choosing
between these two? Does anyone have a particular preference for one
over
the other?
p.s. it’s my understanding that ruby-* requires flex and yacc, while
rex
and racc are pure ruby (please correct me if I’m wrong). That being
said,
I’m mostly interested in functionality and ease-of-implementation
differences between the two pairs of packages…
p.p.s. as I said, I’m looking to build a parser for CSS2. might there
be an
entirely different parser generator for ruby that I should be looking to
use
given the nature of the grammar ( Appendix D: The grammar of CSS2) I’m looking to
parse (such as tdp4r http://rubyforge.org/projects/tdp4r/)?
between these two? Does anyone have a particular preference for one over
the other?
Thanks,
Ryan H.
Maybe Antlr and/or ragel could be useful, though I don;t know anything
about them except that:
Ragel is used to create http parser in mongrel, Antlr was mentioned
here sometime ago. Unfortunately I don’t remember the topic - try
searching if it interests you.
the other?
I made my decision a long time ago (at least 3+ years), and I don’t
remember my exact reasoning. However, I do have two racc parsers
available for your perusal if you’re interested, and one of them is
pretty complicated.
I’ve got a simple Nagios parser in my project named naginator[1], and
a pretty complicated one in Puppet[2]. For Puppet, I used StrScan to
make a lexer, which has so far worked pretty well; for Nagios, I just
wrote a moderately crappy token() method that did the lexing for me.
I know this doesn’t help you specifically decide between any of them,
but at least it’s some code you can look at, which is more than I had
when I made my decision (I wrote Naginator about 2 years before I
wrote Puppet’s parser, and when I went to write Puppet’s parser,
Naginator’s was the only example I could find).
I’d be glad to answer any follow-on questions about them.
I did look at Antlr and Rockit or whatever they’re called, but again,
I don’t remember why I chose against them. I’m sure it was at least
partially because I was already pretty familiar with Lex/Yacc-style
grammars.