ls-a/arithmetic-ast

Implements the Shunting Yard Algorithm and creates an Abstract Syntax Tree with arithmetic operations

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/ls-a/arithmetic-ast

dev-main 2025-11-11 18:00 UTC

This package is auto-updated.

Last update: 2025-11-11 18:00:54 UTC


README

This documentation is also available in these languages:

This library provides a implementation of Abstract Syntax Tree for arithmetic operations.
For more information, see these links:

Code sample:

<?php

$tokens = [
    TokenParser::parse('1 + 2 * 3'),
    TokenParser::parse('1 + (2 * 3 % 5 - (2 + 3 + 4) + (5 / 2)) + (3 * 4)'),
    TokenParser::parse('(mock(1, 2) + 2.6) / 2'),
    TokenParser::parse('mock-with-dashes(mock-with-dashes(mock-with-dashes(2)))')
];

Features

This library includes :

  • Support for following operators : +, -, *, /, %
  • Allowance to create new operators, with custom symbols, whether single character or string
  • Unary operator managament
  • Functions support
  • Function string parameters
  • Variadic function parameters
  • Support for following units: mm, cm, pt, pc, in, % and related converters, plus support to create your own

For every operation, you can use evaluate method to get its result.

Why?

First, because why not? We could not find an arithmetic abstract syntax tree on composer and felt it was missing.
Next, for a little background, this package is used in XSL-Core package, to handle various XML function calls in attributes.

Installation

This library is available on Composer. Install it with:

composer require ls-a/arithmetic-ast

Changelog

Please refer to the CHANGELOG file to see the latest changes.

Support

We put our heart into delivering high-quality products that are accessible to everyone. If you like our work, don’t hesitate to reach out to us for your next project!

Contributing

Contributions are governed by the CONTRIBUTING file.

Security

If you’ve found a bug or vulnerability, please contact us by email at contact@ls-a.fr instead of opening an issue, in order to protect the security of other users.

Credits

  • Renaud Berthier

License

The MIT License (MIT). Please see License File for more information.