Home
Insert
Update snippet 'Parsing string expressions, the lazy way'
Title
Description
Sometimes you'd be surprised at what functionality you can find inside the .Net framework. Apparently the DataTable object can compute string expressions. Nice for testing your own parser implementation, and/or for lazy coders like me. Note that the DataTable is created only once and reused with each function call.
Source code
let eval = let dt = new System.Data.DataTable() fun expr -> System.Convert.ToDouble(dt.Compute(expr,"")) // usage (FSI) // > eval "(1+5)*7/((3+(2-1))/(7-3))";; // val it : float = 42.0
Tags
expression
parsing
expression
parsing
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update