All Projects → yallie → Sprache.Calc

yallie / Sprache.Calc

Licence: MIT license
Easy to use extensible calculator for .NET. Demonstrates Sprache toolkit grammar inheritance.

Programming Languages

C#
18002 projects
shell
77523 projects

Projects that are alternatives of or similar to Sprache.Calc

string-math
Evaluates a math expression from a string. Supports variables and custom operators.
Stars: ✭ 14 (-66.67%)
Mutual labels:  calculator, expression-evaluator
menu-calc
A calculator for Rofi/dmenu(2)
Stars: ✭ 45 (+7.14%)
Mutual labels:  calculator, calc
pratt-calculator
A very simple expression evaluator written using a Pratt Parser
Stars: ✭ 22 (-47.62%)
Mutual labels:  calculator, expression-evaluator
N-Matrix-Programmer
A software to write an optimized code that calculates inverse and determinant of N by N matrix.
Stars: ✭ 35 (-16.67%)
Mutual labels:  calculator
Mather
A powerful expression-based calculator, unit converter, and general computation engine for Android
Stars: ✭ 49 (+16.67%)
Mutual labels:  calculator
util
封装了一些Java常用的功能
Stars: ✭ 19 (-54.76%)
Mutual labels:  calculator
rpncalc
RPNCalc: The Command Line Reverse Polish Notation (RPN) Calculator
Stars: ✭ 19 (-54.76%)
Mutual labels:  calculator
fend
Arbitrary-precision unit-aware calculator
Stars: ✭ 64 (+52.38%)
Mutual labels:  calculator
Math-Expression-Evaluator
A C# library for parsing mathemitical expressions with support for parentheses and variables.
Stars: ✭ 97 (+130.95%)
Mutual labels:  expression-evaluator
fcal
Extensive math expression evaluator library for JavaScript and Node.js
Stars: ✭ 86 (+104.76%)
Mutual labels:  calculator
hellocalc
HelloCalc is a programable calculator for Android created with JavaFX.
Stars: ✭ 23 (-45.24%)
Mutual labels:  calculator
eqn
A gem to evaluate mathematical equations.
Stars: ✭ 32 (-23.81%)
Mutual labels:  calculator
bitcointaxer
Crypto-TAX Gain/Loss Calculator
Stars: ✭ 33 (-21.43%)
Mutual labels:  calculator
eva
a calculator REPL, similar to bc(1)
Stars: ✭ 535 (+1173.81%)
Mutual labels:  calculator
glGraph
A 2d Graphing Calculator written in C++ using Modern OpenGL
Stars: ✭ 15 (-64.29%)
Mutual labels:  calculator
Nota
A calculator with a beautiful interface for the Terminal, Including unicode-based charting and rich mathematical notation rendering
Stars: ✭ 45 (+7.14%)
Mutual labels:  calculator
rsc
A handwritten scientific calculator for interpreting equations.
Stars: ✭ 32 (-23.81%)
Mutual labels:  calculator
kafka-cluster-size-calculator
An Apache Kafka cluster size calculator
Stars: ✭ 36 (-14.29%)
Mutual labels:  calculator
in-line-calculator
📟 an interface-less calculator for Windows
Stars: ✭ 44 (+4.76%)
Mutual labels:  calculator
android-calculator
大三上Java课设 - Android 科学计算器
Stars: ✭ 37 (-11.9%)
Mutual labels:  calculator

Sprache.Calc

Appveyor build status Tests

This library provides easy to use extensible expression evaluator based on LinqyCalculator sample. The evaluator supports arithmetic operations, custom functions and parameters. It takes string representation of an expression and converts it to a structured LINQ expression instance which can easily be compiled to an executable delegate. In contrast with interpreted expression evaluators such as NCalc, compiled expressions perform just as fast as native C# methods.

Instaco.de

Usage example

var calc = new Sprache.Calc.XtensibleCalculator();

// using expressions
var expr = calc.ParseExpression("Sin(y/x)", x => 2, y => System.Math.PI);
var func = expr.Compile();
Console.WriteLine("Result = {0}", func());

// custom functions
calc.RegisterFunction("Mul", (a, b, c) => a * b * c);
expr = calc.ParseExpression("2 ^ Mul(PI, a, b)", a => 2, b => 10);
Console.WriteLine("Result = {0}", expr.Compile()());

// end-user's functions
calc.RegisterFunction("Add", "a + b", "a", "b");
expr = calc.ParseExpression("Add(353, 181)");
Console.WriteLine("Result = {0}", expr.Compile()());

Installation

To use expression evaluator in your projects, install Sprache.Calc NuGet package by running the following command in the Package Manager Console:

PM> Install-Package Sprache.Calc

Grammar inheritance technique

Sprache.Calc library serves as a demonstration of grammar inheritance technique with Sprache toolkit. An article describing Sprache.Calc implementation details is currently available in English and Russian:

TL;DR:

  • Declare parsers as virtual properties instead of static fields
  • Decompose the grammar into small and reusable rules
  • Write unit tests for every single atomic parser
  • Use "protected internal" access modifier to enable unit testing
  • Unit tests must be organized in the same hierarchy as parser classes
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].