Project Description
LazyParser.NET is a light-weight late-bound expression parser compatible with C# 2.0 expression syntax. It allows you to incorporate user-supplied mathematical expressions or any C# expression in your application which can be dynamically evaluated at runtime, using late binding.

Any .NET class and/or method can be used in expressions, provided you allow access to them in an application-provided "context".

This library is perfect for CMS systems, blog engines, ORM tools, etc.

Features
  • Evaluate any C# 2.0 expression at runtime
  • Fully C# 2.0 spec compliant (operator precedence, nullable lifting, type promotion, ...)
  • Late bound (objects can be passed at runtime, types are evaluated when the expression is evaluated)
  • Function calls: support for member methods, static methods and delegates,
  • Support for static fields, properties and classes
  • Possibility to intercept field or property access at runtime

Examples of use
ParserContext context = new ParserContext();
 
context.AddType("Math", typeof(Math));
context.Set("SomeString", "Hi there!");
context.Set("SomeNumber", 20);
context.AddFunction("fmt",  typeof(String), "Format");
 
CSharpParser parser = new CSharpParser();
 
string stringValue = parser.Evaluate<string>("fmt(\"I said: {0}\", SomeString)", context);  // returns "I said: Hi there!"
int intValue = parser.Evaluate<int>("Math.Max(10, SomeNumber)" , context); // returns 20
double doubleValue = parser.Evaluate<double>("SomeNumber * 2.0", context); // returns 40.0

Last edited Mar 28 at 8:29 PM by activa, version 7
Comments
marlongrech wrote  Mar 4 at 8:20 AM 
I am sorry for my ignorance on this project but may I ask why you created you own engine instead of using the DLR and build on top of it?

But besides that great jon :D

activa wrote  Mar 4 at 10:10 AM 
Well, "light-weight" and "no dependencies" being two of the requirements.

The DLR doesn't satisfy these requirements, not by a long shot :-)

jmptrader wrote  Mar 20 at 3:50 PM 
please, can talk about performance? in comparation with another approachs like Flee : http://www.codeplex.com/flee

jmptrader wrote  Mar 20 at 4:39 PM 
in example:

context.Add("SomeString", "Hi there!");
context.Add("SomeNumber", 20);

must be:

context.Set<string>("SomeString", "Hi there!");
context.Set<int>("SomeNumber", 20);

activa wrote  Mar 28 at 8:34 PM 
This expression parser is not built with performance in mind. The Flee project is a statically typed expression parser, while LazyParser.NET is late-bound. Method calls are resolved at runtime, making it suitable for dynamically executing user-supplied expressions.

Although performance is not a priority, expressions are pre-parsed to an expression tree, which can be cached for better performance.

jmptrader wrote  Mar 31 at 5:05 PM 
ok. I understand the dynamic philosophy of your component. Is possible add at the Context recieve an Object act like an symbol table ? with object avoid lot calls Get/Set ...

Updating...