-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Infinite recursion - i.e. how to use ref()? #51
Comments
Yea, this is a quite common problem when writing parsers called Left Recursion. You basically have the rule:
So what happens when you try parsing Well:
To solve this, you could change the rules to be something like this:
This can be written in On a side note, I'm pretty sure other parser combinator libraries have functions for this specific pattern and mecha probably should have that too. |
Well when you point it out, it seems obvious! I've got something that's pretty much working out of
Indeed. I am pretty new to combinator/PEG style parsing but I notice that e.g. I also got a version of this grammar working, stolen from wikipedia
I haven't figured out how to convert this one into an AST (... yet!, I'll get there!) instead of just discarding, but it works quite well. |
I'm trying to write a very simple arithmetic expression parser. I'm not even trying to have any specific operator precedence yet, just going left to right. I'm ending up in an infinite loop, and I suspect it's because I'm misunderstanding ref.
Here's the data structure we're trying to parse into.
and a conversion function ...
here's the parser definition(s)
A simple usage end in an infinite recursion
and so on, for many tens of thousands of frames...
I'm simply unsure what to do next to troubleshoot. any advice appreciated.
The text was updated successfully, but these errors were encountered: