Grammar in external file (XML or BNF)

Dec 17, 2009 at 3:24 PM

Hi

Just encountered Irony and having played around with several other parser-types, I think I'll be settling here. I was wondering though, it is would be possible to feed the grammar rules from an XML file or equivalent - or even have an "Irony Grammar" Grammar or something with would read a standard BNF-type text file.  Has it been done already?

Thanks very much again though.

Simon

 

 

Coordinator
Dec 17, 2009 at 4:26 PM

Hi,

 and welcome on board!

About your question, defining grammar in XML - what's the point? Just to make it harder? :)

"Standard BNF-type text file" - what's that? Ironically, BNF is a thing without BNF. Bumm, double irony, intended. There's no "standard" there, at least not I'm aware of. In general, "all in c#" is one of the key strengths of Irony, compared to other parser technologies. BNF itself (grammar rules) is only part of language definition, you have to provide much more in most cases - action snippets, custom event handlers, precedence rules, error handlers - it is much easier to do directly in c# than in external artificial language. Irony's method of representing BNF is good enough, I think - compact, precise and matching the original BNFs as they are listed in language specs

Roman

 

 

Dec 17, 2009 at 7:08 PM

OK. Fair enough. In my enthusiasm in coming across Irony (I've been looking for a while now), perhaps I spoke before thinking.

One other thing ... your SQL grammar example, in C# I can see the overloaded pipe operator. In VB.Net I can't. I've searched the object browser and it doesn't appear to be visible. Am I doing something daft (highly likely) or is it a shortcoming of VB.Net?

Thx

Simon

 

Dec 17, 2009 at 7:19 PM

OK ... so I'm doing something dumb!  There's the OR!

 

Dec 18, 2009 at 11:33 AM
SWoods2009 wrote:

Hi

Just encountered Irony and having played around with several other parser-types, I think I'll be settling here. I was wondering though, it is would be possible to feed the grammar rules from an XML file or equivalent - or even have an "Irony Grammar" Grammar or something with would read a standard BNF-type text file.  Has it been done already?

Thanks very much again though.

Simon

 

 

Hi there, SWoods.

I think I may have what you want.

Rivantsov, I've been messing around with Irony and came up with a few things I would be glad to share/contribute, if you thought them useful for the project:

1- A "converter", that takes in a BnF text file (heavily based upon the ones consumed by the Gold Parser Project) and outputs a .cs grammar file

2- A dynamic grammar class, that takes a slightly modified version of the Gold BnF and initializes a new grammar in runtime. The alterations in the BnF notation were made in order to replace the standar terminator declaration in favor of the way Irony declares them, allowing you to delcare, say, quoted identifiers, as simlple as NTerminal    = QuotedValue("<", ">"). I'm also using the parameter syntax to finish up the configuration of the grammar, declaring stuf like Punctuation, Operator precedence, Transient and Not Reported Symbols, Keywords, etc.

My personal reasons to make this were, first, to have a challenge in hand, in order to explore Irony, and second, to crate a concise form to create dynamic grammars, so that I could, in runtime, define a set of rules for reading complex textual data. Also, having a grammar's grammar is going to be useful in a tool for documenting my parsers/languages, something I've been postponing for quite some time now.

I'm still amazed at how much it has been acomplished with Irony with such a clean and concise code, and I'm really considering dropping some of my old parsers and re-writing them in Irony, and the least I can do is share what little I can to make this project even better!

 

 

 

Dec 18, 2009 at 5:05 PM

Hi Sygnus

I must admit your 2) was exactly what I had in mind. I hadn't considered 1) but can see that for existing grammars it'd be useful.

I completely agree with the sentiments of your last paragraph (well the first bit - since I have nothing to contribute!).

Thx

Simon