Mini scripting language on top of php

I am looking for a mini-scripting language that works on php, I need to interpret simple formulas (something that a scripting language for a spreadsheet will do). The main thing I need is variables, affects and conditions of mathematical operations and the statement if.

ex:

if (price1> 360) result = (price1 * Q) + price1 * Q / 17 else ...

+5
source share
3 answers

I suggest you take a look at some of the concepts used in the template system, such as Smarty, and implement your own. For example, a mathematical template allows you to perform the following operations:

{* $height=4, $width=5 *}
{math equation="x + y" x=$height y=$width}

, . - , eval().

, RPN (Reverse Polish Notation) : +, - , *, /, IF, THEN, SWAP, DUP, =, <>, >, <. >= <=.

+2

, PHP eval. , Pandora, , , ( , , , - , ).

(, ) javascript . PHP-, , , ( , , ): j4p5 phpjs. , PECL SpiderMonkey .

+1

You can use the built-in interpreter, for example. Javascript like http://phpjs.berlios.de/ or wraps command line calls to spider monkey.

+1
source

All Articles