$\begingroup$This is almost literally the Motzkin language (Dyck plus non-parenthesis symbols in arbitrary places), one of the most standard CFLs. So I don't know how to help you; you have probably seen something very similar to the solution in class.$\endgroup$
– Raphael♦Apr 6 '16 at 15:04

2 Answers
2

your current implementation doesn't enforce the first condition "A pair of square bracket tokens [] surrounding zero or more values separated by commas" as an empty string or a NUMBER on its own would be accepted by the grammar.

You could use the following CFG to maintain the integrity of the constraints

array ::= [ ] | [ element ]

element ::= value | value , element

value ::= array | NUMBER

To derive [NUMBER, [NUMBER, NUMBER], NUMBER]

Start with array -> [element]

[ element ]

[ value, element ]

[value, array ]

[value, value, element ]

[value, array, value]

[value, [element], value]

[value, [value, element], value]

[value, [value, value], value]

[NUMBER, [NUMBER, NUMBER], NUMBER]

The grammar rules provided for JSON here might also be a useful reference: http://json.org/