PHP Classes

File: main.php

Recommend this page to a friend!
  Classes of Alex Dan   Expressions   main.php   Download  
File: main.php
Role: Example script
Content type: text/plain
Description: Expression Example script
Class: Expressions
Parse, convert and evaluate math expressions
Author: By
Last change:
Date: 12 years ago
Size: 561 bytes
 

Contents

Class file image Download
<?php
error_reporting
(E_ALL);
include
'Config/load.php';

$evaluator = Expression_Evaluator::getInstance();

$str = '(10 + 20) + (1 + 3 * 2 / (1+1))';
$strPostfix = $evaluator->getConvertor()->strInfixToStrPostfix($str);
echo (
"\n".$str."\n");
echo (
"\n".$strPostfix."\n");
echo(
$evaluator->evaluateStrPostfix($strPostfix));
echo(
' === ');
eval(
'$x = '.$str.';');
echo (
$x."");
$expressionTree = $evaluator->getConvertor()->strInfixToExpressionTree($str);
echo(
' === ');
echo (
$evaluator->evaluateExpressionTree($expressionTree));
echo (
"\n");