| [reply] |
| [reply] |
Use Perl 5.10. With its named captures in regexes, and the ability to use them as 'rules', translating EBNF into regexes is quite easy. In fact, I don't think it'll be hard to write a program that takes an EBNF grammar and returns a regular expression matching the same strings.
And you may want to have a look at Parse::RecDescent. Any EBNF grammar is a recursive descent grammar (but not every recursive descent grammar can be expressed in EBNF). | [reply] |
There's also the evocatively named Parse::EBNF. Although JavaFan's observation that every EBNF grammar is a recursive-descent grammar makes Parse::RecDescent a natural fit, note also that it's famously slow, which may not be what you want. (On the other hand, I have no idea how fast Parse::EBNF is.) | [reply] |
Hi,
I may have done this thread a disfavour when, motivated by some of the help pages, I left out a number of details to focus more on the question:
- I'm not asking for what I already have in the language: I'm on Ubuntu, which I pay for by being more or less locked in specific versions of software. For Perl this is 5.8; I don't know why.
- I searched the monastry before asking and had already found Parsing EBNF with Perl 5 to eventually parse XML with Perl 6, but from the description it's actually about "Extracting EBNF with Perl 5 to eventually parse XML with Perl 6". And it also does not really concern EBNF.
- I'm not interested in defining EBNF or parsing the definition, beyond being able to convert my personal normal form to EBNF, which I currently do with plain substitution, though eventually I'll have to face the one essential difference: A repeat can't be optional in my pnf.
(Actually, I am interested in such matters; it's just outside the current scope.)
JadeNB, thanks for pointing me to Parse:EBNF. I find I've been focussing too much on finding Perl compatible versions of the tools I knew from the last time I did this (lex and yacc, over 20 years ago, which I know to now have flex and bison as counterparts), and hence have missed some other possible ways to parse languages. Unfortunately, counter to the name, that module isn't concerned with EBNF either.
EBNF, for those who do not know this, is a standard: ISO 14799. And the reason it is a standard is exactly this one: To avoid such problems of having a parser that can parse something, but it's not really defined the same way. For the details: A version of ISO 14799 can usually be found at Markus Kuhn's EBNF page. The normal form used for XML is not EBNF, even if the standard says so. I'm not even sure it's a Backus normal form at all. This faux pas seems to muddle the issue no end, including the weird situation of having an EBNF-parser that doesn't actually understand EBNF.
JavaFan, thanks for pointing me to Parse::RecDescent. Originally, I thought it would require C input, but apparently the description should be read differently.
It seemd both Parse::\w+ modules will get me somewhere, but not from where I am now. I probably will have to parse my pnf more formally to be able to get to either starting point. I guess that was inevitable anyway, but it's a bit weird to write a whole parser to preproccess the parser input. Anyway, I'll have to see which Parser module would work best for me.
Thanks,
| [reply] |