Search code examples
bnfebnf

EBNF rule into BNF


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.


Solution

  • 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> | _