Example #1
0
 /**
  * Translate all PokeNumbers found inside of an expression to decimal numbers.
  * Note: Only expression that use spaces to seperate strings can be parsed
  * This means: "snorlax+jigglypuff" will NOT be recognised whereas "snorlax + jigglypuff" will be parseable.
  *
  * @param string $expression
  *
  * @return string
  */
 public function translate($expression, $inputFormat = self::INPUT_POKENUMBER)
 {
     $inputSystem = $this->numberSystem;
     $outputSystem = new NumberSystem();
     if ($inputFormat === self::INPUT_DECIMAL) {
         $inputSystem = new NumberSystem();
         $outputSystem = $this->numberSystem;
     }
     $expression = new Expression($expression, $inputSystem);
     return $this->converter->convert($expression, $outputSystem)->value();
 }
<?php

use gries\NumberSystem\BinarySystem;
use gries\NumberSystem\Expression;
use gries\NumberSystem\ExpressionConverter;
use gries\NumberSystem\HexadecimalSystem;
use gries\NumberSystem\NumberSystem;
require_once __DIR__ . '/../vendor/autoload.php';
class YoloSystem extends NumberSystem
{
    public function __construct()
    {
        parent::__construct(['1337', 'yolo', 'swag'], '¿');
    }
}
$systems = [new BinarySystem(), new HexadecimalSystem(), new YoloSystem()];
$decimal = new NumberSystem();
$converter = new ExpressionConverter();
$decimalExpression = new Expression('(1337 * 7) + sin(5)-2', $decimal);
foreach ($systems as $system) {
    echo $converter->convert($decimalExpression, $system) . "\n";
}