I have to define a context free grammar for the following rules:
(i) A pair of square bracket tokens [] surrounding zero or more values separated by commas. (ii) A value can be another array or a number.
A number is represented by the token NUMBER
. So for example, [NUMBER, [NUMBER, NUMBER], NUMBER]
. is valid.
I am stuck as how to approach this.
My intuition is always to look at the question and see that S->LSQ VALUE RSQ, VALUE->VALUE COMMA VALUE | VALUE | ARRAY | e | NUMBER, ARRAY -> LSQ NUMBER RSQ, NUMBER ->NUMBER
. But I know this slips up.
What steps can I take to ensure I am always thinking in the right way?