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 into
Conversation
fubhy
commented
Apr 19, 2015
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 |
fubhy
commented
Apr 19, 2015
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. |
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.
fubhy
commented
Aug 31, 2015
I just made this a separate PHP library on GitHub: https://github.com/fubhy/math-php |
Fixing implementation of the Shunting-yard algorithm.