Download the PHP package macfja/lexer-expression without Composer

On this page you can find all versions of the php package macfja/lexer-expression. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lexer-expression

Lexer Expression

  1. Description
  2. What is Shunting Yard algorithm
  3. The Shunting Yard implementation
  4. The RPN expression Solver
  5. The AST Tree builder
  6. Install
  7. Usage
  8. Similar projects
  9. Documentations

Description

The main goal of this library is to transform an expression into a computer understandable expression, by using

  1. Doctrine Lexer
  2. The Shunting Yard algorithm

As the input of the Shunting Yard is a Doctrine Lexer, the library is not limited to mathematics expression.

The library provide an "evaluator" of the Shunting Yard algorithm output, or transform it into a AST Tree

What is Shunting Yard algorithm

The best explanation can by found on Wikipedia, or on this article of @igorw.

But to make simple, the main idea is to transform a list of chars into multiple of small group.

Simple example: (1 + 2) * 3 is really simple for us (human) to process, but a computer can do it, it need to split it into small chunk. And evaluate it piece by piece. For a computer, the expression need to be evaluate like this:

This a binary tree, and yes it's also a kind of AST. So to solve the expression a computer first evaluate the group (we will name the result as (a)):

And then it evaluate the group:

The Shunting Yard algorithm transform your expression into an intermediate expression: a RPN expression. The RPN expression of (1 + 2) * 3 is 1 2 + 3 *.

This expression can be read as:

The Shunting Yard implementation

Like most of Shunting Yard implementation, it can parse "simple" expression (with simple operator) and make parenthesis reduction. It can parse unary, and binary functions (like sin(x), max(x,y)) but also any functions (ex: fct(a,b,c,x,y,z)).

But the main "feature" it's the use of Doctrine Lexer.

The RPN expression Solver

The RPN solver allow you to solve a RPN expression (a list of Doctrine Lexer token). It support Operator/Function with any arity.

The AST Tree builder

The AST Tree builder can transform the RPN expression (a list of Doctrine Lexer token) into an AST Tree.
The tree root is a node, the last(final) node (in the What is Shunting Yard algorithm, it's the * operator). This root node is composed of values (leafs of a tree) and nodes (branches).

Limitation

The Solver can not solver function with variable arity (or optional parameters)

Install

To install with composer:

Usage

Very simple Doctrine DQL

Very simple Mathematics expression

3 examples are available in the test directory. The expression is (1 + 2) / ((3 + 4 * 5) - 6).

The tree of the expression is:

Similar projects

Documentations


All versions of lexer-expression with dependencies

PHP Build Version
Package Version
Requires doctrine/lexer Version ~1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package macfja/lexer-expression contains the following files

Loading the files please wait ....