18

I might be wrong, but it looks like that there's no direct flex/bison (lex/yacc) port for C#/.NET so far.

For LALR parser, I found GPPG/GPLEX, and for LL parser, there is the famous ANTLR. But, I want to reuse my flex/bison grammar as much as possible.

  • Is there any direct port of flex/bison for C#?
  • What lexer/parser people normally use for C#? Is there any reason for that choice?
prosseek
  • 182,215
  • 215
  • 566
  • 871
  • possible duplicate of [Lex/Yacc for C#?](http://stackoverflow.com/questions/540593/lex-yacc-for-c) – Hans Passant Jun 04 '10 at 14:40
  • @Hans: While the title may be similar the question isn't. – Andre Artus May 06 '11 at 13:40
  • ANTLR only supports LL(k) grammars - bison supports LALR(1) grammars, which is much more powerful. I don't know of any parser-generator for .Net that even comes close to bison's power, so the question is very legit IMHO. – Algoman Sep 24 '13 at 09:57

3 Answers3

20

I think your best bet is going to be GPLEX/GPPG, it's the closest thing to Yacc/Lex for C# that I know of, and you will need to port your actions into C# regardless.

I have also used Coco/R, ANTLR (of course), and have more recently played with Irony.net, fslex/fsyacc (F#), and fparsec (F#).

Here are some links

Fparsec

Coco/R

Irony.net

Gardens Point Parser Generator

Gardens Point Lex

I don't have a technical reason for using one versus another: I play around with these mostly for fun. I did create some DSLs for work projects a good number of years ago, but I hand rolled the scanners/parsers on those (back then I was working mostly in Pascal, and I found that TP Lex/Yacc did not suit my tastes, and the DSLs were simple enough). I have found that FParsec and Irony suit my tastes the best, as I find the other somewhat "messy" (lacking in elegance).

Emyr
  • 2,351
  • 18
  • 38
Andre Artus
  • 1,850
  • 15
  • 21
2

ANTLR is a very mature (and awesome) parser/lexer generator. It originally produced Java code, but can now target several languages, including C#.

Dónal
  • 185,044
  • 174
  • 569
  • 824
  • The above link is dead at the moment, on the [C# target](https://github.com/antlr/antlr4/blob/master/doc/csharp-target.md) page we may find some information. – minus one Jul 26 '21 at 04:47
  • The [getting started](https://github.com/antlr/antlr4/tree/master/runtime/CSharp/src) page is also very useful. – minus one Jul 26 '21 at 04:54
1

Take a look at "Managed babel" extensions, there is quite a classic-style port of lex and yacc.

http://msdn.microsoft.com/en-us/library/bb165037(VS.80).aspx

SK-logic
  • 9,605
  • 1
  • 23
  • 35