-
Notifications
You must be signed in to change notification settings - Fork 3
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
Precedence, backtracking and so. #4
Comments
Hi! Thanks a lot for using pegasus. I'm still trying to understand the specifics of your grammar, but from what I understand, you'd like to give precedence to certain rules in your grammar to prevent conflicts - specifically, in this case, Backtracking, on the other hand, is trickier. Pegasus uses the LALR(1) parsing algorithm, which does not backtrack. Certain tools (bison, for sure) use GLR rather than LALR(1), which may allow backtracking (or at least something resembling backtracking). I would rather not switch pegasus' parsing algorithm, as this is a lot of work. Thanks again for your interest, and please let me know if I understood you correctly! |
First, thanks for your quick reply. Second, yes, you did understand. There must be a way of doing what I want with LALR(1), but I'm no expert. I have to investigate further. Do you have an example of grammar you use for a real project, maybe a real-world language grammar? (further details on my problem, feel free to skip)I just want to get items of a block in the same branch of the tree.
Should be seen as a simple branch containing all elements in order. Same thing for a block of free text such as:
These blocks are well-matched since the free text block must start with an @. This currently works with my grammar, but I did included a mandatory carriage return for each item of these blocks (see List items and free text lines are no different grammars, so it will conflict if there are no part of a block anymore. |
I'm sure there's a way to get it working with LALR, but whether it's convenient without modification to the algorithm, I'm not sure. If precedence is a simple enough modification to make (it appears as such at first glance), I'd be happy to implement it so that defining grammars is more convenient. I'm not sure if this is "real-world" enough, but here is my grammar for a functional language compiler that I wrote for a class project. Check out the programs folder to see examples of what it parses. Regarding your problem: you add the |
Hello!
First, congratulations about your program, I use it right now and I like the design.
I do hope the software will be maintained!
Second, I do have a problem.
Here is a document I would like to parse:
Just a bit of context: it is a recipe for packaging an application.
A minimalistic version of this could be:
For now, my lexer and grammar look like this:
This grammar works but I have to do a carriage return after a
listitem
orfreetext
.This carriage return is mandatory but if I want to remove it in the rule I will have shift-reduce problems (this is probably conflicting with
lines
).Same thing for the
freetext
rule.I would like to replace them by something like:
I think that it could be simpler if I could prioritize a branch instead of another.
In this example, prioritize
listitem
instead oflines
so my grammar tree would look like this:So. Is there a way not to require a carriage return at the end of a
freetext
andlistitem
, and still have a good grammar tree?As I understand, grammar tools often add precedence, backtracking or other mechanisms to simplify the grammar. I think it could be useful in my case.
Is this on the roadmap? :)
Thanks a lot for reading me up to this point, and thanks for the help.
The text was updated successfully, but these errors were encountered: