If you have a grammar for your BNF rules, you could use Parse::RecDescent to parse the BNF rules for you. Decide on a 'nice structure' that you would like to compile the BNF rules into, and write Parse::RecDescent rules to create that structure as Parse::RecDescent parses your BNF rules.
| [reply] |
In fact, the language that my "spew" language uses is very close to a BNF-style language anyway. You could probably use that parser as a good start.
| [reply] |
| [reply] |
P::RD doesnt *quite* use BNF, in fact its kind of a slightly mutated *Extended*BNF (EBNF). BNF itself is a lot simpler.
C.
| [reply] |
I spent quite a while also looking for a BNF parser, and turned up a couple not on CPAN (eg this one) .. But I don't remember if I got around to actually trying it out.
I also found it strange that theres none on CPAN, I guess people don't do this too often.. (I was looking to parse the SQL92 spec, which is freely available in BNF form..)
In the end though, I acquired the SQL1999 spec in pdf form, and hand parsed the interesting bits..
C. | [reply] |
Well, in that case, perhaps it's worth writing one. Er, maybe... I wonder if anyone other than the two of us would use it. :-)
| [reply] |
I would! I thought of writing a (E)BNF to P::RD parser in P::RD, but never quite got round to it. It would certainly be useful, as you can dig out BNFs for lots of languages that don't necessarily have P::RD-based parsers on CPAN. It would also make P::RD parsers hand-converted from changeable BNFs much easier to maintain. I would think it'd be quite simple to do this if you can write a meta-grammar for BNF in P::RD. Maybe it's so simple that it's been done several times already, but never made its way onto CPAN...
| [reply] |