Does C# have (direct) flex/yacc port? Or what lexer/parser people use for C#? [closed]

无人久伴 提交于 2019-12-03 02:48:38

问题


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?

回答1:


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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/2974630/does-c-sharp-have-direct-flex-yacc-port-or-what-lexer-parser-people-use-for-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!