Good parser generator (think lex/yacc or antlr) fo

2019-01-22 07:50发布

Is there a good parser generator (think lex/yacc or antlr) for .NET? Any that have a license that would not scare lawyers? Lot’s of LGPL but I am working on embedded components and some organizations are not comfortable with me taking an LGPL dependency.

I've heard that Oslo may provide this functionality but I'm not sure if it's a build time dependency or also a runtime dependency. Can anyone clarify what Oslo will provide?

UPDATE
What I would really like is a parser generator that is a build time only dependency. It looks like ANTLR has a runtime component.

5条回答
够拽才男人
2楼-- · 2019-01-22 07:57

I just discovered that F# ships with an implementation of yacc and lex. It looks like I will be able to leverage this parser generator for my .NET needs.

F# Samples

The Parsing sample shows how to use the fsyacc and fslex tools to build parsers and lexers for use with F#. (Mode: Compiled, Runs on: any CLI, including Mono)

Related blog posts:

查看更多
Anthone
3楼-- · 2019-01-22 07:58

Personally I'm quite a fan of the GOLD Parser Generator. It doesn't generate any code directly, it just gives you the DFA and LALR state tables and lets you write your own parser engine to suit your needs.

This way of structuring things doesn't suit everyone or every situation (you lose some flexibility since your language must be meet LALR restrictions), so I don't claim this as "the right way", but I liked the separation of parsing algorithm from parse rules (and it does mean that any runtime requirements are entirely and easily within your control).

Of course you don't have to write your own engine – there are three engines written in C# listed on the site for example. Off-hand I don't know what licenses those engines use, but writing your own engine is frankly trivial if you find the licences unpalatable. GOLD includes documentation that gives a full description of a working algorithm, which is (as you'd expect if you understand LALR parsing), a simple state machine system. The GOLD program itself is free to use, of course.

GOLD also includes an IDE for writing your language grammar, which can be quite helpful.

查看更多
Ridiculous、
4楼-- · 2019-01-22 07:58

You could also try Malcolm Crowe's LEX/YACC compiler tools. Lots of good examples.

查看更多
Ridiculous、
5楼-- · 2019-01-22 08:07

Hmmm you already mentioned Antlr so I am not sure why you aren't consider it ...

Antlr generates C# (http://www.antlr.org/wiki/display/ANTLR3/Antlr%2B3%2BCSharp%2BTarget) and has an BSD license (http://www.antlr.org/license.html) that seems to have very few restrictions.


Irony (http://irony.codeplex.com/) has quite a number of downloads and a (easy on the eyes) MIT license. Appears to have Full source code so it might be possible to "imbed" this directly into your app.

查看更多
地球回转人心会变
6楼-- · 2019-01-22 08:08

ANTLR has a runtime component, but you can always take the few classes it uses and include them in your project, at which point you no longer need to reference the runtime assembly. It's licensed under the BSD license - 3 clause for the C# 3 target and 4 clause for the C# 2 target.

查看更多
登录 后发表回答