Converting EBNF to BNF
Asked Answered
N

2

14

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.

Nambypamby answered 17/3, 2010 at 22:54 Comment(0)
M
26

See this page.🕗 It contains instructions for each production that needs to be converted:

From EBNF to BNF


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-terminal X and add

    X = ε | X E.
    
  • Convert every option [ E ] to a fresh non-terminal X and add

    X = ε | E.
    

    (We can convert X = A [ E ] B. to X = A E B | A B.)

  • Convert every group ( E ) to a fresh non-terminal X and add

    X = E.
    
  • We can even do away with alternatives by having several productions with the same non-terminal.

    X = E | E'. becomes X = E. X = E'.

Monte answered 17/3, 2010 at 23:27 Comment(4)
Perfect! That's exactly what I need. Someone I never found that link!Nambypamby
I'm getting a 404 on that link now... any idea if there is an updated version somewhere?Germano
Alas, not off the top of my head. Hopefully the page will come back.Monte
The page has moved to lampwww.epfl.ch/teaching/archive/compilation-ssc/2000/part4/…Subway
M
1

Be warned: EBNF as it's listed in the ISO standard also includes exceptions to syntactic rules, which do not have a BNF equivalent. The conversion given by 500 - Internal Server Error only works for the portion of EBNF which overlaps with RBNF/ABNF.

Millisecond answered 20/8, 2019 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.