Question

I'm looking for BNF grammar for C# v4 that I can feed to fsyacc or if I can't find that an EBNF based parser generator that can output F#.

EDIT: I'm not looking to write a parser for C# but an experimental parser for a very similar grammar and since there's a huge literal overlap between the two grammars I find it easier to start with the C# grammar and simply change the bits that deviates. However the only grammar for C#v4 I've found is a EBNF

an alternative answer would be a converter from EBNF to BNF

Was it helpful?

Solution

Extending my previous comment - I don't think there's any solid grammar for C# that could be directly usable. There are some examples, but they probably won't cover all new features (like LINQ) or won't be very well tested.

The best option that I can think of is to use the parser from the C# compiler in Mono. This is written in C#, open-source, includes all recent features (and is also fairly solid). For more information, see Mono C# compiler. You should be able to compile that and use that from F# (or modify it to be more F# friendly).

OTHER TIPS

According to Wikipedia, Coco/R is an EBNF based parser generator. And according to their homepage, there is an F# port of Coco/R (last updated 2007-07-23, though, so I'd expect some breaking changes). If you end up checking it out, I'd be interested in your experience.

I did find a BNF grammer for C# v2: http://www.devincook.com/GOLDParser/grammars/index.htm

I found some grammars here; they seem to include up to C# 4.0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top