New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate
gives infinite recursion for recursive grammars
#3072
Comments
@sylee957, with an infinite grammar, you can use the depth parameter to limit the recursion depth:
['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] |
I think that it also has the problem if it doesn't reach |
@sylee957 actually, given a finite value for 'depth' lower than the recursion limit, the generate function does reach all the allowable productions. Since it concatenates lists and not strings, it outputs forms like ['a', 'a'] instead of 'aa'. And since it applies the grammar depth-first, the first output is the deepest tree, while the breadth-first strategy would start with ['a']. |
For example:
['a', 'a', 'a', 'a'] |
So the real problem seems to be that, at line 29, generate.py sets a default depth that is much higher than the recursion limit:
However, using sys.getrecursionlimit() instead, which is 1000, is also still too high. Then, the solution could be, on one hand, to lower the default depth and, on the other hand, to output a more informative warning when the recursion limit is reached, |
The following code for generating simple recursive grammar does not work
gives
RuntimeError: The grammar has rule(s) that yield infinite recursion!
I think that the problem should not be an issue if the algorithm uses different searching technique
and iterators should be capable of generating infinite sequences.
Without the capability to generate recursive grammars, it loses many practical capability because it can only handle finite grammars.
The text was updated successfully, but these errors were encountered: