Can't come up with a BNF grammar for the sequence of characters (possibly empty), separated by comma, but not starting or ending with a comma,
So this is OK:
<--- Empty sequence is ok!
A
A,B
A,B,C
This is NOT ok:
A,
,A
A,,B
AB
The empty case throws me off. What I got so far is:
<char-seq> ::= <empty> | <char> , <char-seq> | <char>
but this produces strings like A,
:-(
BNF syntax can only represent a rule in one line, whereas in EBNF a terminating character, the semicolon, marks the end of a rule. Furthermore, EBNF includes mechanisms for enhancements, defining the number of repetitions, excluding alternatives, comments, etc.
Rules For making BNF : A terminal could be a quoted literal (like “+”, “switch” or ” “<<=”) or the name of a category of literals (like integer). The name of a category of literals is typically defined by other means, like a daily expression or maybe prose.
The right hand side of a production may be composed of any sequence of bracketed names and printable characters. Curly brackets ({...}) are used to delimit choices separated by vertical bars and square brackets ([...]) are used to indicate optional phrases.
The empty char sequence is what gives you the trouble. You need a rule that matches a non-empty sequence to be separate from the rule that matches both an empty and a non-empty one, like this:
<char-seq> ::= <empty> | <non-empty-char-seq>
<non-empty-char-seq> ::= <char> | <char> , <non-empty-char-seq>
<char-seq> ::= <empty> | <chars>
<chars> ::= <char> | <char> , <chars>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With