-
Notifications
You must be signed in to change notification settings - Fork 24
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
support EBNF #50
Comments
I'd like Grammophone to do this. I think the obvious solution is to convert EBNF to BNF just after parsing by adding rules to the grammar. However, when considering this before, I wasn't sure how to present calculations with these additional rules. For example, this grammar:
...could be converted internally to something like this:
This would add Perhaps the added nonterminals could be displayed differently, or the conversion to BNF could be shown explicitly somehow. |
There's one huge issue that prevents a traditional EBNF grammar from being straightforwardly-useful with grammophone. The conversion between CFG and EBNF is not "lossless". There's some amount of ambiguity there as there are alternative interpretation strategies for the constructs that EBNF comes with. For example, repetition operators can be interpreted to either mean a left recursive or a right recursive version. Left recursive: on grammophone
Right recursive: on grammophone
Both describe the same language. Which one should be used? There are more implementations possible, see this comment: #26 (comment) There's no clear winner there so it's not clear which implementation should be used as each has the ability to offer different benefits wrt to the conflict and lookahead profile of a CFG. Here are two separate solutions to the actual issue (which is to support a more concise grammar formalism)
Which would make it possible to define ones own constructs.
where I think the second approach is a much better fit for grammophone. The first one is very convenient, but much harder to implement. Extra: 3. The "cutting-edge-infinite-resources" approach. Grammophone could use e-graphs (https://egraphs-good.github.io) for finding the best version that leads to the fewest conflicts. This has not been done before and it is much harder, but I hope one day we'll have something like that. |
I think this could be achieved by taking a dataflow approach (either via DeRemer & Penello or via Pingali #27) and introducing unique nodes for the extended constructs. (Edit: Pingali discusses how a dataflow approach over a GFG can be used to find lookaheads.)
|
Of course, somehow I forgot about that... I think the ambiguity has a benefit, though. Grammophone could choose an arbitrary interpretation but also allow the user to select one interactively (ie, not using syntax). This would allow for demonstrating the differences between the two. So, given the example grammar:
Grammophone could indicate that
(Let's say But also allow the user to select this:
I'm not sure where this would be presented. Maybe above the "Sanity Checks" section. |
I want to analyze this grammar for complexity, it's in EBNF: https://github.com/VladimirAlexiev/shacl/blob/shaclc-grammars/shacl-compact-syntax/grammar/shaclc-XText.ebnf.
It's also available in Eclipse XText: https://github.com/VladimirAlexiev/shacl/blob/shaclc-grammars/shacl-compact-syntax/grammar/shaclc-XText.xtext.
Is it possible for Grammophone to support one of these formats?
The text was updated successfully, but these errors were encountered: