Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

RunFormula

A lightweight open-source unit-aware math and physics scripting engine for FreePascal and Lazarus

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

RunFormula

The RunFormula is a module for FreePascal and Lazarus intended to evaluate mathematical expressions and physics formulas provided as text with scripting language support and physical dimension handling.

Supported data types:

  • integers in decimal, hexadecimal and binary formats;
  • floating-point numbers in decimal and scientific notation;
  • complex numbers and operations on them;
  • intervals and operations on them;
  • strings and ASCII characters;

Arithmetic and logical operations: + - * / or and xor not shl (<<) shr (>>) mod (%) div == <> < <= >= > & (string concatenation) ** (integer exponentiation).
Variables and runtime initialization of variables via an external callback function.
A base set of built-in functions and the ability to register and use additional user-defined functions.
Control flow functions: if() repeat() exit() result() continue() break()
Ability to define and subsequently use functions directly within source script (subroutines).
Support for physical dimensions, their runtime checking, automatic calculation of the resulting dimension, and automatic conversion of values between different unit systems.
Support for the define directive.
Compiling the source script into bytecode for multiple execution.
Minimal dependencies (only SysUtils in the base configuration).

Integrating RunFormula into your project

  • Copy all files from the RunFormula directory (runformula.pas and all .inc files) to your project or a separate directory.
  • Add RunFormula to the uses clause of either the interface or implementation section.

For example, like this:

pascal
implementation
uses RunFormula;

or, if using a separate directory:

pascal
implementation
uses RunFormula in 'RunFormula/runformula.pas';

How to use RunFormula

The simplest way is to call RunFlaParse function and then pass its output to the RunFlaExecStr or RunFlaExecVrt functions.
For example:

pascal
ShowMessage( RunFlaExecStr( RunFlaParse('9 * 3') ) );  // displays 27

or, with physical units:

pascal
ShowMessage( RunFlaExecStr( RunFlaParse('g = 9.8`N/kg`, t = 5, g * t`s` ** 2 / 2') ) );  // displays 122.5 m

RunFlaParse compiles the source script into bytecode for execution by RunFlaExecStr or RunFlaExecVrt. The result of RunFlaExecStr is a string, while RunFlaExecVrt returns a Variant.
For more information on using RunFormula, please refer to the help files in the Help directory (available in both English and Russian). Feel free to ask questions in Discussions.

--
Author: Alexander Torubarov
Contact: runfla@yandex.com

Copyright (C) 2026 Alexander Torubarov
Licensed under the MIT License.
See the LICENSE file in the project root or a copy available at opensource.org for full license information.