even though it is not easy to build a tool that does the translation from an EBNF to a PEG notation automatically (and correctly) for all possible grammars
for most real-world grammars the transcription is not that hard to do by hand.
I would start by simply creating a rule structure that directly mimics the EBNF you have. The EBNF operators have direct counterparts in the PEG notation and therefore in parboiled.
There are two things you have to look out for:
- Choice operators ('|')
- Left recursion
In BNF the choice operator has no order, i.e. a parser has to use look-ahead to figure out which of the given choices applies at a specific input location (it has to be exactly one). In PEGs the choice operator is ordered, i.e. the parser will try one option after the other until one succeeds.
This differing semantics does not make a difference, if all options are completely independent. However, if some of the options of a choice operator share common prefixes (or even are prefixes of other options) you will have to reorder the choice or add semantic predicates (also see the parboiled docs at http://wiki.github.com/sirthias/parboiled/parsing-performance-tuning).
The second point, left recursion, might not be applicable, if the grammar you are looking to transcribe does not use left recursion (many real-world grammars don't). Currently parboiled cannot handle left recursion. However, even if the grammar has left recursion it is usually not hard to remove.
Check out http://en.wikipedia.org/wiki/Left_recursion for more info.
Hope that helps to get you started.
If you have a parboiled grammar for SQL-92 that you would like to share just drop me a note.
I would be happy to include it with the parboiled examples.
On 17.08.2010, at 21:29, Mike Norman [via parboiled users] wrote:
> Mathias: how hard would it be to convert the BNF for SQL-92 to PEG-style Parboiled Java?
> Actually, I don't need all of the SQL grammar - just the terms for a 'WHERE' clause.
> Any hints on how to get started would be greatly appreciated,
> View message @ http://users.parboiled.org/Parboiled-Sql-tp1194198p1194198.html > To start a new topic under parboiled users, email [hidden email] > To unsubscribe from parboiled users, click here.