Search code examples
c#-4.0f#grammarbnfebnf

C# grammar in BNF or EBNF Parser generator for F#


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


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).