908 views
3 votes
Write a grammar for a language whose sentences start with an even and non-zero number of x’s, end with an odd number of z’s, and have a number of y’s in between equal to the total number of x’s and z’s in the sentence. For example, xxyyyyyzzz is a valid sentence.

User Acmoune
by
5.5k points

1 Answer

4 votes

Answer:

GRAMMAR

S -> AB

A -> xxAyy | xxyy

B -> yyBzz | yz

EXPLANATION

A is for even number of x's followed by that number of y's

B is for odd number of y's followed by that number of z's

User Astreltsov
by
5.7k points