承接 phramework/expression-parser 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phramework/expression-parser

Composer 安装命令:

composer create-project phramework/expression-parser

包简介

LISP-like expression parser

README 文档

README

Α "LISP like" expression parser for evaluating expressions Build Status Coverage Status

Requirements

Install

Require package using composer

composer require phramework/expression-parser

Usage examples

Define a simple language

<?php
/*
 * Define a language
 * with a Boolean function "or"
 */
$language = (new Language())
    /*
     * Define 'or' function
     */
    ->set(
        'or',
        function(bool $l, bool $r) : bool {
            return $l || $r;
        }
    );

/*
 * Create an expression parser based on the language
 */
$parser = new ExpressionParser(
    $language
);

/*
 * Evaluate an expression, expect result to be true
 */
$result = $parser->evaluate([
    'or', // first argument is always the function name 
    true, // will be passed as or function's first argument
    false // will be passed as or function's second argument
]);

A more complex example

<?php
/*
 * Define a language
 * with "+" (addition) and "-" (subtraction) functions for float numbers
 */
$language = (new Language())
    /*
     * Define "+" (addition) function
     */
    ->set(
        '+',
        function(float $l, float $r) : float {
            return $l + $r;
        }
    )
    /*
     * Define "-" (subtraction) function
     */
    ->set(
        '-',
        function(float $l, float $r) : float {
            return $l - $r;
        }
    );

/*
 * Create an expression parser based on the language
 */
$parser = new ExpressionParser(
    $language
);

/*
 * Evaluate expression
 * expect result to be 5 + (4.5 - 1) = 8.5
 */
$result = $parser->evaluate([
    '+',
    5,
    [
        '-',
        4.5,
        1
    ],
]);

Development

To install composer dependencies:

composer update

To run the tests:

composer test

License

Copyright 2016-2018 Xenofon Spafaridis

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

统计信息

  • 总下载量: 19.44k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2016-12-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固