Add a Lexer/Parser for mathematical expressions. (Input Processor + Separate Action & Condition)#183
Add a Lexer/Parser for mathematical expressions. (Input Processor + Separate Action & Condition)#183fubhy wants to merge 12 commits intofago:8.x-3.xfrom fubhy:8.x-3.x
Conversation
|
This is not yet finished. It is lacking test coverage and the usage of plain arrays for the output and for the stack in the Shunting-yard algorithm is going to be subject to change (I want to use \SqlQueue and \SqlStack there... Same for the initial tokenizing). Note: This implementation seems to be extremely effective due to the compiled regex. I tried running a few (even complex) mathematical expressions and they correctly evaluated within a matter of microseconds. Yai |
|
Oh and it obviously lacks Drupal / Rules integration (still misses variable support, currently only handles constants). I also want to register the lexer and the parser as separate services. Not sure yet how I want to handle the registration of the default methods. Probably through a list of method calls in the services.yml. |
src/Math/Calculator.php
Outdated
Fixing implementation of the Shunting-yard algorithm. Fixing spelling error.
There was a problem hiding this comment.
Can't you figure out the amount of arguments using reflection?
There was a problem hiding this comment.
I would like to avoid reflection due to performance concerns. Do you think it is viable to do this on runtime? Or are you saying that, once I move this to some other place, I would do this during the building of the container?
There was a problem hiding this comment.
Fair point. Yeah I kinda assumed that you cache that object
There was a problem hiding this comment.
Well, I will... Eventually (once I am registering as a service). So I will look at that again once that's done. That huge constructor with all the registering is going to go away in that process of course (that's just for now so I can work with it and test it).
There was a problem hiding this comment.
Makes sense. The variable should be number_of_arguments or so though, as it's not the actual function arguments.
There was a problem hiding this comment.
Once we retrieve that with reflection that argument would be gone anyways :P.
|
I just made this a separate PHP library on GitHub: https://github.com/fubhy/math-php |
Fixing implementation of the Shunting-yard algorithm.