0

Hi I am having a lot of trouble with this problem and I came across a lot of sites but found this post How to convert BNF to EBNF to be very helpful but I just don't know where to start with this example.

<decimal_literal> --> (0|1|2|3|4|5|6|8|9){0|1|2|3|4|5|6|7|8|9|_}

In this rule the parenthesis and curly braces are metasymbols. It needs more than 1 rule and may need to introduce 1 or more new non-terminals.

This is the textbook I am using http://umsl.edu/~mfrp9/misc/cpl.pdf page 131 shows an example but I can't apply it to this problem. If someone can please explain the solution to this problem step by step so I can learn it to do similar problems is greatly appreciated.

Community
  • 1
  • 1
Noobie
  • 65
  • 5
  • The question you cross-reference is converting from a BNF to EBNF. Your question title says you're trying to convert from EBNF to BNF. Which are you trying to do? And if the target is BNF, then which dialect of BNF? If the target is EBNF, do you mean standard EBNF (as in ISO 14977:1996), or some other dialect of EBNF? – Jonathan Leffler Oct 01 '14 at 04:45
  • Yes I am looking to convert EBNF to BNF but was told that if it can be converted one way then it can be converted the other way. I couldn't find anything exactly for EBNF to BNF so I used that post as a guide. Yes standard EBNF. – Noobie Oct 01 '14 at 04:53
  • Yes, it can be converted, but the question is "which dialect of BNF"? I suppose the answer to that is "in the book". – Jonathan Leffler Oct 01 '14 at 04:55
  • I would assume it is dialect 2 according to http://bnf-for-java.sourceforge.net/Dialects.html – Noobie Oct 01 '14 at 05:02

1 Answers1

0

This looks plausible as a translation to the BNF from p131 of the book.

<decimal_literal> ⟶ <decimal_digit>
    | <decimal_literal> <decimal_digit_or_underscore>

<decimal_digit> ⟶ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

<decimal_digit_or_underscore> ⟶ <decimal_digit> | _
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • I understand the but how come we split up and the ? Since expressions that may be omitted or repeated can be represented through curly braces { ... }. – Noobie Oct 01 '14 at 05:24
  • Do it your own way if you want; this is the way I'd do it. The BNF on p131 in your book doesn't show any use of `{ … }` for repetition; that is an EBNF notation. Since you're translating from EBNF to BNF, you have to remove EBNF-only constructs like `{ … }` and translate to BNF. – Jonathan Leffler Oct 01 '14 at 05:24
  • Hi, thanks for your help Jonathan, I posted another simple question and I would like to see if my solution is correct, if you have a second, please take a look. http://stackoverflow.com/questions/26134894/bnf-to-standard-ebnf – Noobie Oct 01 '14 at 05:51