PHPackages                             nicmart/expression-tree - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nicmart/expression-tree

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nicmart/expression-tree
=======================

A simple php library to build and dump expression trees.

6131PHP

Since Apr 22Pushed 11y ago2 watchersCompare

[ Source](https://github.com/nicmart/ExpressionTree)[ Packagist](https://packagist.org/packages/nicmart/expression-tree)[ RSS](/packages/nicmart-expression-tree/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

ExpressionTree [![Build Status](https://camo.githubusercontent.com/8e0e8df06800e95f661c115b4a3e56809ebb62e80d5f600e99529e4361fb5f49/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6e69636d6172742f45787072657373696f6e547265652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/nicmart/ExpressionTree)
=============================================================================================================================================================================================================================================================================================================================

[](#expressiontree-)

In this library you can find some dumpers that convert simple expression trees to common string notations.

What is an expression tree?
---------------------------

[](#what-is-an-expression-tree)

Take for example a simple algebraic expression like

```
2 * (100 : (1 + 3)) * (98 - 7)

```

In evaluating this expression we have to find out which expressions has to be evaluated first, in which order, and their hierarchical relationship.

In this case the expression tree is

```
       *
      /|\
     / | \
    2  :  -
      /|   |\
     / |   | \
  100  +   98 7
      / \
     1   3

```

In such a tree leaf nodes are numbers and tree nodes are operators.

Building the tree
-----------------

[](#building-the-tree)

This library does not offer (at least now) an expression parser, and it is supposed you already have the expression in the tree format.

Since this library depends on [nicmart/Tree](https://github.com/nicmart/Tree) library, you can build the tree with its Builder:

```
