24

I'm looking for a parser generator that given an EBNF for a LL(k) language will give me a C# parser and generate classes the types defined in the EBNF.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
HasaniH
  • 8,232
  • 6
  • 41
  • 59

7 Answers7

25

ANTLR (nothing else to say)

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • 20
    well you need to say something to get to 15 chars. ;) +1 – kenny Feb 10 '11 at 19:17
  • 2
    I think ANTLR has real problems giving proper error messages. Good luck figuring out eg. where to put the @inlude specification! Documentation is bewildering and never shows the preferred way to do stuff. Tree gramars are a waste of time.. the ANTLR site even has a huge blog entry on this. – Carlo V. Dango Aug 12 '12 at 23:44
  • 2
    Hmm, looks like http://www.antlr.org/wiki/display/ANTLR3/Antlr+3+CSharp+Target was last updated 3 years ago and all the code blocks are missing -- wait, no, that's just what happens when JavaScript is disabled. Anyway, C# has always been a second-class ANTLR target. When I first used it, the C# Runtime source code wasn't available: the author (not the same as the author of ANTLR) released the binary with no specified license IIRC, and dropped off the face of the earth. I used Reflector to reconstruct the source code. – Qwertie Oct 31 '12 at 17:49
8

Gold is OK as far a parser generators go.

Moha the almighty camel
  • 4,327
  • 4
  • 30
  • 53
plinth
  • 48,267
  • 11
  • 78
  • 120
  • 3
    OP asked for LL(k). Gold is LALR. – Ira Baxter Oct 02 '10 at 20:32
  • correct me if I am wrong: Are no LL grammars subset of LALR grammars? – Thanasis Ioannidis Mar 28 '13 at 10:21
  • 1
    @Saysmaster: No. Wikipedia says: "The LALR(k) parsers are incomparable with LL(k) parsers – for any j and k both greater than 0, there are LALR(j) grammars that are not LL(k) grammars and conversely. In fact, it is undecidable whether a given LL(1) grammar is LALR(k) for any k >= 0." – Qwertie Feb 19 '14 at 02:23
  • Would be nice, though to have a gold engine which generates the full parser code into 1 file and spares us to have dependencies. (e.g. for c#) – BitTickler Apr 22 '15 at 23:56
4

You might want to look at MinosseCC, a port of JavaCC to C#. Another possibility is Spart.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191
  • 1
    MinosseCC was renamed to CSharpCC. The current version is on Google Code space and it's the port of JavaCC 3.2, while a development version (port of JavaCC 5.0) is under development on GitHub (http://github.com/deveel/csharpcc) – Antonello Apr 11 '14 at 08:49
  • Spart is terrible; you can't get the AST from an expression. Instead, you have to subscribe to the Act event, which only returns the text matched as a string. This makes it pretty much useless. It is supposed to be a port of Spirit (for C++), but in practice, since it doesn't support this feature from Spirit, it is useless. (also the documentation is incorrect for even the trivial examples) – TamaMcGlinn Oct 30 '18 at 10:28
4

There is a new parser generator on the block called LLLPG, that supports LL(k) grammars and zero-width assertions. The runtime library is optional (a base class suffices). The documentation is fairly detailed now, and I have used LLLPG to parse most of a dialect of C# called Enhanced C# (which, in fact, is the main input language of LLLPG). The input syntax is not EBNF, though (it's sort of a mashup of C# + ANTLR-style code).

Full disclosure: I wrote it. Questions welcome.

Edit: the top Google result for "C# parser generator" is written by a guy named "Tomassetti" who claims my parser generator "is not really usable standalone" - that's like saying a PC is "not really usable as a standalone gaming rig" because it can also do web browsing and spreadsheets. True, after installing the Visual Studio extension you must separately go to NuGet and get the runtime library (Loyc.Syntax), but I don't think that's what he means and I don't think he ever actually tried to use it. LLLPG's design is a feature, not a bug. All I can say is, please give it a try and let me know what you think.

Qwertie
  • 16,354
  • 20
  • 105
  • 148
4

Find Irony in http://irony.codeplex.com/

PROS: It is simple CONS: -Lack of document -Rather Slow

Ali
  • 349
  • 2
  • 4
2

Grammatica supports LL(k). http://grammatica.percederberg.net/

1

Coco/R (from the SSW - "Johannes Kepler" University Linz)

Traummaennlein
  • 474
  • 5
  • 12