Can someone enlighten me why a recursive descent parser with backtracking that tries the productions $S \rightarrow aSa$ and $S \rightarrow aa$ (in that order) does not recognize the language formed by the grammar $S \rightarrow aSa\ |\ aa$.
It appears to only parse words from the language $\{a^{2^n}\ |\ n \ge 1 \}$.
I generated such a parser using this ABNF Parser Generator with the production rule S = "a" S "a" / "aa"
and the parser does not recognize the word aaaaaa
, for example.
I would expect it to use the production $S \rightarrow aSa$ until the concatenation of the parse tree's terminal nodes from the left starts with 7 a
's, and then go up the parse tree choosing the production $S \rightarrow aa$ instead until the tree looks like this:
S
/ | \
a S a
/ | \
a S a
/ \
a a
aaaaaa
. $\endgroup$aaaaaa
. $\endgroup$