Given the three symbols: "(" ")" and ";"
how can I create production rules of a context free grammar for S expressions, which meet the following criteria:
If the expression is read from left to right, then the amount of open brackets on any position of the expression (except for the last one) is greater than the amount of closed brackets. At the end of the expression the amount of open brackets should be equal to the closed brackets.
Also upper case letters need to be used for any introduced Non-terminal letters.
Strings contained in the grammar:
()
(;)
(((;)))
((;);((;)))
(();(()))
Strings NOT contained in the grammar.
;
(;;)
(()())
());(()
();()
;()
ε
I have tried using the following grammar, but I get some faulty values from it, any input/correction is appreciated.
S --> (BAB)
A --> ; | ε | (A)
B --> B | A | A);(A
An Answer:
S->(T)|(;)|()
T->(T)|T;T|()|(;)