0

I have an application in which a user can create entities that are stored in a database. Each entity has a string Name property and a boolean Value property. The user can also specify a string that contains logic to be executed against the entities. For example, the logic might be something like:

(Q1 or Q2) and (Q3 or Q4)

So, to evaluate this logic, my app needs to look for entities whose Name properties are Q1, Q2, Q3, and Q4, substitute the Value properties for the names in the above expression, and evaluate the expression.

The app is written in C#. I'm expert in C# and VB, but I have no experience with dynamic languages. I could write a parser that uses Regex to tokenize the logic string, but I'm wondering if there is an easier way to do this, maybe using something from the relatively new .Net dynamic language features.

Bob

Bob.at.Indigo.Health
  • 11,023
  • 13
  • 64
  • 111
  • Could be a duplicate of http://stackoverflow.com/questions/1194584/what-is-a-good-c-sharp-compiler-compiler-parser-generator – duffymo Nov 25 '12 at 20:49
  • It's certainly a similar question. I think that the referenced question is from someone looking for help parsing a custom language. I'm just looking for a ready-to-use dynamic expression evaluator. As I said in my answer to my own question, Flee seems to be everything I could want, complete with excellent sample code that does all the things I want to do. – Bob.at.Indigo.Health Nov 26 '12 at 21:41
  • Even an ad hoc handwritten recursive descent parser would be sufficient in your case. Implementation language does not matter for such a simple grammar. – SK-logic Nov 30 '12 at 10:19

2 Answers2

1

Flee (http://flee.codeplex.com/) looks like a winner. In particular, it seems to offer an easy event mechanism that allows my app to provide values for the variables that Flee parses out of the expression.

Bob.at.Indigo.Health
  • 11,023
  • 13
  • 64
  • 111
0

ANTLR is a wonderful Java parser generator. I'd recommend giving it a look:

http://www.antlr.org/wiki/display/ANTLR3/Antlr+3+CSharp+Target

duffymo
  • 305,152
  • 44
  • 369
  • 561