Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good parser generator (think lex/yacc or antlr) for .NET? Build time only? [closed]

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.

like image 294
Eric Schoonover Avatar asked Aug 10 '09 21:08

Eric Schoonover


3 Answers

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:

  • A simple parser in F#
like image 176
Eric Schoonover Avatar answered Nov 15 '22 17:11

Eric Schoonover


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.

like image 41
BlueShepherd Avatar answered Nov 15 '22 16:11

BlueShepherd


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.

like image 4
John Bartholomew Avatar answered Nov 15 '22 15:11

John Bartholomew