Question

lets say i have the following EBNF:

ProductNo   ::= Digitgroup "-" Lettergroup;
Digitgroup  ::= Digit Digit? Digit? Digit?;
Digit       ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
Lettergroup ::= Letter Letter? Letter? Letter? Letter?;
Letter      ::= "A" | "B" | "C" | "D" | "E" | "F" | "G"
            | "H" | "I" | "J" | "K" | "L" | "M" | "N"
            | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
            | "V" | "W" | "X" | "Y" | "Z";

now i want to set the maximum of Tokens for ProductNo = 5

Example:

Input : 1-A      (EBNF valid and Token < 5)
Input : 023-A    (EBNF valid and Token < 5)
Input : 0231-ABI (currently EBNF valid but Token = 8 > 5 so this should not be valid)
Input : 022-ABCDE(currently EBNF valid but Token = 9 > 5 so this should not be valid)

as you can see in this example input, the combination of Digits and Letters can vary as long as its EBNF conform (min 1 Digit max 4 Digit), (min 1 Letter max 5 Letter) but the sum of the Tokens has to be <= 5 including the "-".

Question : Is there a way other than writing every valid combination of Letter and Digit down?

My current solution:

ProductNo   ::= Token Token Token Token? Token?;
Token       ::= Digit | Letter | "-";
Digit       ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
Letter      ::= "A" | "B" | "C" | "D" | "E" | "F" | "G"
            | "H" | "I" | "J" | "K" | "L" | "M" | "N"
            | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
            | "V" | "W" | "X" | "Y" | "Z";

Problem : The composition of ProductNo (Digitgroup, "-", Lettergroup) is not reproduced. So i need to combine the two EBNF into one, but i really cant figure a way out how to do this.

Was it helpful?

Solution

I'm assuming you are using the W3C notation: http://www.w3.org/TR/REC-xml/#sec-notation , not the standard ISO notation: http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form .

If I'm wrong, then please specify which EBNF you're using!

In the W3C notation you can use this:

Digit       ::= [0-9]
Letter      ::= [A-Z]
GoodFormat  ::= Digit+ "-" Letter+
Token       ::= Digit | Letter | "-"
TooLong     ::= Token Token Token Token Token Token+
ProductNo   ::= GoodFormat - TooLong

OTHER TIPS

I think that there is a smarter solution than writing every valid combination down:

ProductNo   ::= Case1 | Case2 | Case3
Case1       ::= Digit Digit? Digit? "-" Letter;
Case2       ::= Digit "-" Letter Letter? Letter?;
Case3       ::= Digit Digit? "-" Letter Letter?;
Digit       ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
Letter      ::= "A" | "B" | "C" | "D" | "E" | "F" | "G"
            | "H" | "I" | "J" | "K" | "L" | "M" | "N"
            | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
            | "V" | "W" | "X" | "Y" | "Z";

But I don't know if there is any smarter why to do this. I hope this solution helps a bit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top