6 ms·
Compiling PHP's Eval() to .NET
- whoisthemachine 7y agoAs someone who began programming with PHP, and who programs professionally in C# now, PeachPIE has always been a fascinating project to me. Glad to see Roslyn has made PeachPIE even more capable.
- awild 7y agoWe do something very similar at work, but with runtime generated Java code for an in-memory column oriented database. Our data is analyzed before being loaded and we determine the range of numbers necessary to store the data: eg. If we only have bytes incoming, we generate a class that only stores bytes etc. On top of that all our strings are interned in a trie and then represented as ints, also run through above outlined code. This works because we are mostly interested in equality of strings and other computation with strings (mostly prefix based classific) is done ahead of time. For debugging we emit our generated code and both eclipse and intellij picked up our generated code without configuration. It's safed us a lot of headaches.
- rajeev-k 7y agoI 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 https://github.com/Rajeev-K/formula-parser
- smt88 7y agoYou 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.
- ftcHn 7y agoe.g. https://docs.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.data.data...
- herman_toothrot 7y agoI'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 https://github.com/mparlak/Flee/wiki/Getting-Started
- senthil_rajasek 7y agoDo you have examples of the types of "formulas" that you wanted to execute? Also, how would one execute said formula?
- rajeev-k 7y agoAny 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/Repl.cs https://github.com/Rajeev-K/formula-parser/blob/master/src/R...
- humble_engineer 7y agoThese are the kinds of articles that make me never want to come to this site.
- ghusbands 7y ago> we simply want to emit the debug information of eval() only if we are just debugging the program. Otherwise it’s just an unnecessary performance overhead. This will not correctly handle the case when the user attaches a debugger after the eval has started, but before all execution artifacts (including callbacks/closures) are finished.