I want to write the grammar for a list containing sequentially increasing integers like this
1 X
1 X 2 X
1 X 2 X 3 X
1 X 2 X 3 X 4 X
// and so on
I want to use a recursive definition to avoid defining separate rules for each case manually.
Without the increasing integers, I could write the following recursive grammar (in McKeeman Form)
NumberedList
Int X
Int X NumberedList
How can I specify the increasing integers?
No context-free grammar can represent this language because it is not context-free. Each expansion depends on the preceding expansion, which is an example of what the "context" in "context-free" is referring to.
It would be straightforward but tedious to write a context-sensitive grammar. That's the result of having to write out decimal arithmetic as a set of string substitution rules.