context-free-grammarcontext-sensitive-grammar

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


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.


Solution

  • 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