Replies: 1 comment 2 replies
-
Hello,
Those cases are actually just restated as right-recursive patterns.
It is, I believe, always possible in general to rewrite as right-recursive. That said, I agree that it can sometimes be rather annoying to do. I think in your case, however, the rewrite shouldn't be too hard. Take this sub-grammar:
This can be restated as right-recursive with a technique called precedence climbing, which would express this as something more akin to:
You can see this approach for parsing operators taken in several of the example parsers, and in the tutorial. I don't see anything in the BNF that you provide that is fundamentally more complex than these cases. Incidentally, if you're using version Let me know if I can help further. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm using Chumsky to parse a functional-style programming language (which is called Bluespec SsytemVerilog), which means the expression type can be very complex and there are a lot of left recursive grammars. The full grammar can be find at https://github.com/B-Lang-org/bsc/releases/download/2023.07/BSV_lang_ref_guide.pdf and I have extracted all the grammar defs to a gist: https://gist.github.com/myrfy001/f4621cba938fa8d9577181a0c06ac666
for example, the following is a slice of the grammar:
From the Chumsky's toturial, it provides simple example for handling left recursive by using repeat and fold, but it seems to work only for simple case, when the expression being complex, is there any other way to handle the left recursive? Because the grammar is so complex that it's not possible to rewrite to remove the left recusrive. Also, I'm not an expert on Writing Parsers.
In the 1.0 alpha version, I can see it has an memorized paraer and it says can be used to handle left recursive, but I'm not sure whether it can handle such a complex case, and it doesn't has an example either.
I wish to get some advise on those problems, thanks!
Beta Was this translation helpful? Give feedback.
All reactions