How do you restric maximum length of elements in language of context free grammar

340 Views Asked by At

How does one restrict the maximum length of elements in a context free grammar.... How would you structure rules to say only allow for elements of language to be of length seven and less.

1

There are 1 best solutions below

5
On BEST ANSWER

With this you can even express it as a REGEX/FSA. All you need to do is essentially the same thing as you would in those machines, which is to make n amount of nodes which in your case 7. Basically it looks like this.

R -> <1><2>...<7>

<1> -> elements. | e
<2> -> elements. | e
..
<7> -> elements. | e