All Projects → pieterderycke → Jace

pieterderycke / Jace

Licence: mit
Jace.NET is a calculation engine for the .NET platform.

Projects that are alternatives of or similar to Jace

fast-formula-parser
Parse and evaluate MS Excel formula in javascript.
Stars: ✭ 341 (+15.2%)
Mutual labels:  formula, interpreter
Melang
A script language of preemptive scheduling coroutine in single thread
Stars: ✭ 273 (-7.77%)
Mutual labels:  interpreter
wendy
Wendy is an compiler / interpreter for WendyScript
Stars: ✭ 14 (-95.27%)
Mutual labels:  interpreter
danube
The Danube Programming Language
Stars: ✭ 33 (-88.85%)
Mutual labels:  interpreter
ocaml-offchain
Fork of WebAssembly reference interpreter with support for generating proofs needed for blockchain verification
Stars: ✭ 42 (-85.81%)
Mutual labels:  interpreter
pascal-interpreter
A simple interpreter for a large subset of Pascal language written for educational purposes
Stars: ✭ 21 (-92.91%)
Mutual labels:  interpreter
recurse
re<urse is a declarative language for generating musical patterns
Stars: ✭ 32 (-89.19%)
Mutual labels:  interpreter
Rascal
The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
Stars: ✭ 284 (-4.05%)
Mutual labels:  interpreter
Swiftpascalinterpreter
Simple Swift interpreter for the Pascal language inspired by the Let’s Build A Simple Interpreter article series.
Stars: ✭ 270 (-8.78%)
Mutual labels:  interpreter
vbf
A brainfuck interpreter/compiler written in V.
Stars: ✭ 17 (-94.26%)
Mutual labels:  interpreter
H-Calc
So, you want to write a DSL interpreter...
Stars: ✭ 21 (-92.91%)
Mutual labels:  interpreter
SandboxJS
Safe eval runtime
Stars: ✭ 18 (-93.92%)
Mutual labels:  interpreter
Dascript
daScript - high-performance statically strong typed scripting language
Stars: ✭ 259 (-12.5%)
Mutual labels:  interpreter
3bc-lang
Low level language, tiny virtual machine that works on computers and microcontrollers. (Friendly Punched cards)
Stars: ✭ 155 (-47.64%)
Mutual labels:  interpreter
Brainfuck
Brainfuck interpreter written in C
Stars: ✭ 275 (-7.09%)
Mutual labels:  interpreter
awesome-internals
A curated list of awesome resources and learning materials in the field of X internals
Stars: ✭ 78 (-73.65%)
Mutual labels:  interpreter
RISVM
A low overhead, embeddable bytecode virtual machine in C++
Stars: ✭ 21 (-92.91%)
Mutual labels:  interpreter
balloon-lang
The Balloon programming language and interpreter.
Stars: ✭ 17 (-94.26%)
Mutual labels:  interpreter
Lbforth
Self-hosting metacompiled Forth, bootstrapping from a few lines of C; targets Linux, Windows, ARM, RISC-V, 68000, PDP-11, asm.js.
Stars: ✭ 293 (-1.01%)
Mutual labels:  interpreter
Eval5
A JavaScript interpreter written in TypeScript - Support ES5
Stars: ✭ 281 (-5.07%)
Mutual labels:  interpreter

Jace.NET

Jace.NET is a high performance calculation engine for the .NET platform. It stands for "Just Another Calculation Engine".

Build Status

  • Build status (master)
  • Build status (dev)

What does it do?

Jace.NET can interprete and execute strings containing mathematical formulas. These formulas can rely on variables. If variables are used, values can be provided for these variables at execution time of the mathematical formula.

Jace can execute formulas in two modes: in interpreted mode and in a dynamic compilation mode. If dynamic compilation mode is used, Jace will create a dynamic method at runtime and will generate the necessary MSIL opcodes for native execution of the formula. If a formula is re-executed with other variables, Jace will take the dynamically generated method from its cache. It is recommended to use Jace in dynamic compilation mode.

Wiki

For detailed information how to use Jace.NET, please consult the wiki

Architecture

Jace.NET follows a design similar to most of the modern compilers. Interpretation and execution is done in a number of phases:

Tokenizing

During the tokenizing phase, the string is converted into the different kind of tokens: variables, operators and constants.

Abstract Syntax Tree Creation

During the abstract syntax tree creation phase, the tokenized input is converted into a hierarchical tree representing the mathematically formula. This tree unambiguously stores the mathematical calculations that must be executed.

Optimization

During the optimization phase, the abstract syntax tree is optimized for executing.

Interpreted Execution/Dynamic Compilation

In this phase the abstract syntax tree is executed in either interpreted mode or in dynamic compilation mode.

Examples

Jace.NET can be used in a couple of ways:

To directly execute a given mathematical formula using the provided variables:

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2.5);
variables.Add("var2", 3.4);

CalculationEngine engine = new CalculationEngine();
double result = engine.Calculate("var1*var2", variables);

To build a .NET Func accepting a dictionary as input containing the values for each variable:

CalculationEngine engine = new CalculationEngine();
Func<Dictionary<string, double>, double> formula = engine.Build("var1+2/(3*otherVariable)");

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2);
variables.Add("otherVariable", 4.2);
	
double result = formula(variables);

To build a typed .NET Func:

CalculationEngine engine = new CalculationEngine();
Func<int, double, double> formula = (Func<int, double, double>)engine.Formula("var1+2/(3*otherVariable)")
	.Parameter("var1", DataType.Integer)
    .Parameter("otherVariable", DataType.FloatingPoint)
    .Result(DataType.FloatingPoint)
    .Build();
	
double result = formula(2, 4.2);

Functions can be used inside the mathemical formulas. Jace.NET currently offers four functions accepting one argument (sin, cos, loge and log10) and one function accepting two arguments (logn).

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2.5);
variables.Add("var2", 3.4);

CalculationEngine engine = new CalculationEngine();
double result = engine.Calculate("logn(var1,var2)+4", variables);

Performance

Below you can find the results of Jace.NET benchmark that show its high performance calculation engine. Tests were done on an Intel i7 2640M laptop. 1000 random formulas were generated, each containing 3 variables and a number of constants (a mix of integers and floating point numbers). Each random generated formula was executed 10 000 times. So in total 10 000 000 calculations are done during the benchmark. You can find the benchmark application in "Jace.Benchmark" if you want to run it on your system.

  • Interpreted Mode : 00:00:06.7860119
  • Dynamic Compilation Mode: 00:00:02.5584045

Compatibility

If you are using Jace.NET inside a Unity project using IL2CPP you must use Jace.NET in interpreted mode due to limitations of IL2CPP with dynamic code generation.

More Information

For more information, you can read the following articles:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].