title: Formula parsing / evaluation routine or library with generic DLookup functionality
body: <p>I am writing a .Net application where I must support user-defined formulas that can perform basic mathematics, as well as accessing data from any arbitrary table in the database.</p>
  
  <p>I have the math part working, using JScript Eval().</p>
  
  <p>What I haven't decided on is what a nice way is to do the generic table lookups.
  For example, I may have a formula <strong>something like</strong>:<br>
  Column: BonusAmount
  Formula: {CurrentSalary} * 1.5 * {[SystemSettings][Value][SettingName=CorpBonus AND Year={Year}]}</p>
  
  <p>So, in this example I would replace {xxx} and {Year} with the value of Column xxx from the current table, and I would replace the second part with the value of (select Value from SystemSettings WHERE SettingName='CorpBonus' AND Year=2008)</p>
  
  <p>So, basically, I am looking for something very much like the MS Access DLookup function:<br>
  DLookup ( expression, domain, [criteria] )<br>
  DLookup("[UnitPrice]", "Order Details", "OrderID = 10248")</p>
  
  <p>But, I also need to overall parsing routine that can tell whether to just look up in the current row, or to look into another table.  Would also be nice to support aggregate functions (ie: DAvg, DMax, etc), as well as all the weird edge cases handled.</p>
  
  <p>So I wonder if anyone knows of any sort of an existing library, or has a nice routine that can handle this formula parsing <em>and</em> database lookup / aggregate function resolution requirements.</p>