uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
A comprehensive overview of uCalc's multi-stage processing model, detailing how text is transformed from a raw string into a final, evaluated result.
[revisit]
Understanding how uCalc processes a string from input to output is key to leveraging its full power. It's not a single, monolithic eval() function but a sophisticated, multi-stage pipeline where each step is configurable. This allows you to intercept and modify the process at various points, enabling the creation of custom syntax, domain-specific languages (DSLs), and complex transformation logic.
This topic provides a high-level overview of the entire end-to-end pipeline.
At its core, the uCalc engine follows a five-stage process. The diagram below illustrates the path an expression takes from a raw string to a final result.
[ Expression Parser Pipeline ]
Raw String ────► [ 1. Pre-Processing ] ────► Tokenizer ────► [ 2. Token Transformation ] ────► Token Stream ────► [ 3. Syntactic Analysis (Parsing) ] ────► Executable Plan (AST) ────► [ 4. Evaluation ] ────► Raw Result ────► [ 5. Post-Processing (Formatting) ] ────► Final String[ Transformer Pipeline ]
Raw String ────► Tokenizer ────► Token Stream ────► [ 3. Syntactic Analysis (Matching) ] ────► Match Results ────► [ 4. Replacement ] ────► Final StringNote: The Transformer follows a simplified pipeline that branches off after tokenization.
Let's break down each stage for the expression parser.
ExpressionTransformer)Before the parser even sees the individual tokens, the entire raw string is passed to the ExpressionTransformer. This is a meta-transformer that allows you to define high-level rewrite rules.
100 USD to EUR syntax into a standard function call like ConvertCurrency(100, "USD", "EUR").Tokens)The string (either the original or the pre-processed version) is fed into the tokenizer, also known as a lexer. The lexer uses a set of regular-expression-based rules defined in a Tokens collection to break the string into a stream of meaningful units: numbers, identifiers, operators, string literals, etc.
TokenTransformer)During tokenization, if the lexer finds a token that has been specially marked with TokenType::TokenTransform, it pauses and sends that single token to the TokenTransformer.
0xFF into an expression the engine understands, like BaseConvert("FF", 16).Parse)The final stream of tokens is fed into the syntactic analyzer, or parser. The parser uses the grammar rules (operator precedence, function signatures) to build a hierarchical structure called an Abstract Syntax Tree (AST). This tree represents the expression's logic and order of operations.
Evaluate / Execute)The AST contained within the Expression object is executed. The engine walks the tree, performing the specified calculations, calling functions, and retrieving variable values.
Format)If the evaluation was triggered by a method that returns a string (like EvalStr or EvaluateStr), the raw string result is passed through a final, optional formatting pipeline.
Double results as currency (e.g., 123.45 becomes $123.45).Most evaluation tools are a "black box". You provide a string and get a result.
eval() in Scripting Languages: A single, non-configurable step.uCalc's key advantage is its transparent and configurable pipeline. It gives you hooks at every major stage of processing, transforming it from a simple evaluator into a powerful language construction toolkit. You can control high-level syntax, low-level literals, and final output formatting, all within a single, cohesive engine.