It's been a few years since my computer-language class and so I've forgotten the finer points of BNF's and EBNF's and I don't have a textbook next to me. Specifically, I've forgotten how to convert an EBNF into BNF.
From what little I remember, I know that one of the main points is to convert { term }
into <term> | <many-terms>
. But I don't remember the other rules. I've tried to look this up online but I can only find links to either homework questions, or a small comment about converting terms with curly braces. I can't find an exhaustive list of rules that define the translation.
Please see the following link, it contains instructions for each production that needs to be converted:
http://lampwww.epfl.ch/teaching/archive/compilation-ssc/2000/part4/parsing/node3.html
For building parsers (especially bottom-up) a BNF grammar is often better, than EBNF. But it's easy to convert an EBNF Grammar to BNF:
Convert every repetition
{ E }
to a fresh non-terminalX
and addX = ε | X E.
Convert every option
[ E ]
to a fresh non-terminalX
and addX = ε | E.
(We can convert
X = A [ E ] B.
toX = A E B | A B.
)Convert every group
( E )
to a fresh non-terminalX
and addX = E.
We can even do away with alternatives by having several productions with the same non-terminal.
X = E | E'.
becomesX = E. X = E'.
来源:https://stackoverflow.com/questions/2466484/converting-ebnf-to-bnf