Skip to content
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

Why don't you include an EBNF Parser that reads a file and outputs a grammar #54

Open
AlexanderBaggett opened this issue Mar 4, 2023 · 2 comments

Comments

@AlexanderBaggett
Copy link

AlexanderBaggett commented Mar 4, 2023

I've been going through this code for a while now.

All of your examples/samples are hardcoded.

I was totally confused by this.

It's like you are literally doing things the hard way.

Why can't you parse a file and generate terminals, non-terminals, and BNF rules from a file automatically?

@sebastienros
Copy link
Contributor

All of your examples/samples are hardcoded.

This is the point of parser combinator libraires.

Because of this you can build dsls dynamically. You also get intellisense to build them and compilation validation.

But what would be interesting would be to create a BNF parser with the library and generate the code based on that input in case you have existing grammars to port.

@rivantsov
Copy link
Contributor

this is the way other parser generators (PGs) work - you describe BNF in a file, using some special BNF language; each generator/solution has its own syntax. So you before you start building custom lang parser, you have to build a parser for BNF. This is what Scott Hanselman points out in his article:
https://www.hanselman.com/blog/the-weekly-source-code-59-an-open-source-treasure-irony-net-language-implementation-kit

Defining grammar directly in c# is the 'sweet spot' of Irony, you get strong typing, intellisence support, etc. And in Irony, BNF looks like natural, thanks to operator overloading.

Secondly, for all these PGs with BNF in file, the file actually has to include a lot of extra custom things, and usually it is code snippets injected into generated code. This gets really difficult to manage. You put "c" snippets into BNF grammar, but compiler or parser cannot check correctness, you have to generate the full parser code (usually its huge and cryptic), and then compile and run the whole thing, there you will see how your snippet works.
In Irony, you are in c# already, and you add extra custom code right there, thru events and other facilities - but it is directly checkable by c# environment.
That's the whole point of this approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants