News for hackers. Stuff that matters.
Re:Compiling PHP's Eval() to .NET by rajeev-k on Sunday February 16, 2020 @12:31PM (#22342638)
I needed the ability to safely execute formulas in my .NET app. My solution was to write a parser and interpreter. Here it is: https://github.com/Rajeev-K/formula-parser
Re:Compiling PHP's Eval() to .NET by smt88 on Sunday February 16, 2020 @12:39PM (#22342685)
You can do this already with DataTables, which is basically an in-memory Excel spreadsheet. Bonus is that it also supports Excel functions, and it’s completely safe/sandboxed code.
Re:Compiling PHP's Eval() to .NET by ftcHn on Sunday February 16, 2020 @10:23PM (#22345347)
Re:Compiling PHP's Eval() to .NET by herman_toothrot on Sunday February 16, 2020 @01:39PM (#22343047)
I've used FLEE for this. Compiles down to IL so it's fast, you can define your own functions, etc.

https://github.com/mparlak/Flee/wiki/Getting-Started

Re:Compiling PHP's Eval() to .NET by senthil_rajasek on Sunday February 16, 2020 @05:24PM (#22344120)
Do you have examples of the types of "formulas" that you wanted to execute?

Also, how would one execute said formula?

Re:Compiling PHP's Eval() to .NET by rajeev-k on Monday February 17, 2020 @11:16AM (#22348686)
Any valid Visual Basic.NET expression is supported. Here are some examples:

  (latestquote - previousquote) / previousquote
  iif(isonlineorder, "Online", "Retail")
  FirstName & " " & LastName
  iif(IsNothing(Amount), "Amount missing",  Format(Amount, "c2"))
  "Q" & ((OrderDate.Month - 1) \ 3 + 1)
  MonthName(DatePart(DateInterval.Month, Today), false)
  DateAdd(DateInterval.Day, 1, Today)
See this file for example of usage: https://github.com/Rajeev-K/formula-parser/blob/master/src/R...