From 949334d6c37d384800c639ba9941e94f5157f5ac Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Wed, 20 May 2020 06:04:31 +0300 Subject: WIP: New generation (#62) * Massive refactoring More clean structure Parsing without regular expressions * Cleanup unused imports * Fix version string for Travis * 7.1 downgrade * Fix readme --- src/NXP/Classes/CustomFunction.php | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/NXP/Classes/CustomFunction.php (limited to 'src/NXP/Classes/CustomFunction.php') diff --git a/src/NXP/Classes/CustomFunction.php b/src/NXP/Classes/CustomFunction.php new file mode 100644 index 0000000..944f7d9 --- /dev/null +++ b/src/NXP/Classes/CustomFunction.php @@ -0,0 +1,63 @@ +name = $name; + $this->function = $function; + if ($places === null) { + $reflection = new ReflectionFunction($function); + $this->places = $reflection->getNumberOfParameters(); + } else { + $this->places = $places; + } + } + + public function execute(&$stack) + { + if (count($stack) < $this->places) { + throw new IncorrectExpressionException(); + } + $args = []; + for ($i = 0; $i < $this->places; $i++) { + array_unshift($args, array_pop($stack)->value); + } + + $result = call_user_func_array($this->function, $args); + + return new Token(Token::Literal, $result); + } + + +} \ No newline at end of file -- cgit v1.2.3