-
Notifications
You must be signed in to change notification settings - Fork 249
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
[SUGGESTION] Grammar railroad diagram #910
Comments
Also to help there is here robertoraggi/cplusplus#281 the latest |
Thanks for the suggestion. I know there are different grammar styles, EBNF being a popular one. I try to generally follow the way the current C++ grammar is specified, though, and I want to stick with that unless there's a compelling must-do reason to change. Is there a compelling benefit to this change that we don't get with |
The compelling reason for me is the ability to generate a railroad diagram and it's less ambiguous when one alternative is long and need to be split between more than one line (the way the current C++ manage such situations is by adding space indentation). It seems that you've not tried visualize the railroad diagrams from your own grammar that I adapted here on the first message (#910 (comment)) and also the latest C++ standard also adapted by me here robertoraggi/cplusplus#281 (comment) or here cplusplus/draft#6742 (comment) . If you try then you'll probably will have a different opinion. To try then only copy and paste then at https://www.bottlecaps.de/rr/ui in the 'Edit Grammar' tab |
Actually its not hard to write script, may be 100-200 lines long, converting current grammar to EBNF, using regex. |
I've just added the |
Ah, now I see what you mean. Sorry, I misunderstood that the example in the initial comment was the railroad diagram. You're right, I've never used the graphical kind, just occasionally seen it.
I've tried to keep the productions under 110 characters, and just did a cleanup pass to make them all less than 90: 9585ecc So maybe I just haven't felt the pain because the productions are short and not complex. I definitely see your point with horrible productions like cast-expression in this example: https://mingodad.github.io/cpp-grammars/c++23.ebnf.xhtml#cast-expression There's nothing like that in my grammar fortunately. But, I admit I do like the ability to directly link to Let me take a quick poll of readers of this thread... If you want to enable railroad diagrams and find them useful, please upvote this reply! |
Looks like the bottlecaps.de site has gone offline. I've worked with the diagram like that for the JSON grammar, but had no idea what they were called. I would say that I have found it useful on occasion, and would probably find them more useful if I used them more regularly. I could imagine having them for the new syntax being very useful as we start using it more. Also, since all my parsing work was done with lex and yacc (and yes, I have/had the O'Reilly bird book), the EBNF form is much more familiar to me. |
The software used by https://www.bottlecaps.de/rr/ui is here https://github.com/GuntherRademacher/rr and can be used offline (web/command line). |
Following up on this in the context of #1031: Above, I see 5 upvotes for this suggestion. So without rewriting the grammar, are there any blockers right now to mechanically generate EBNF grammar from the I'll ask the same question on the sister issues. Thanks! |
#387 has some comments on that. |
Here is one script that extract the grammar using
Output:
|
Great! How close is that to what you need for bottlecaps? I'll have to get rid of that whitespace note... |
You don't need to remove the notes but only prefix then with "//" will be enough. It's actually generating the railroad diagram, but for navigation purposes probably the script should turn then upside down to start with the top level |
I've just changed the script to invert the rules order (turn then upside down):
Output:
|
I've tried to also run the script against the Why use
Parser+lexer EBNF with manual fixes:
|
👍 OK, will be in the next commit. (BTW, I intend to take a look at eliminating the need for that note soon, but for now at least the |
If the syntax to describe the grammar is changed to an
EBNF
understood by https://www.bottlecaps.de/rr/ui we can have a nice navigable railroad diagram to help document/develop/debug the grammar/parser, see bellow:The text was updated successfully, but these errors were encountered: