Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about functions using commas and ** operator #18

Open
New0 opened this issue May 6, 2019 · 3 comments
Open

Questions about functions using commas and ** operator #18

New0 opened this issue May 6, 2019 · 3 comments

Comments

@New0
Copy link

New0 commented May 6, 2019

Hello and thank you for publishing the package.

I've been trying pow() and log() with two parameters but the , returned the Unknown token exception.

The ** operator returned a Syntax error exception.

Code example

$parser = new StdMathParser();
$AST = $parser->parse( 'pow(33,10)' );
$evaluator = new Evaluator();
//$total returns the exceptions explained above
$total = $AST->accept($evaluator);
$parser = new StdMathParser();
$AST = $parser->parse( '3**10' );
$evaluator = new Evaluator();
//$total returns the exceptions explained above
$total = $AST->accept($evaluator);

Did I forget a step for those scenarios ?
All the other math functions and operator work as expected in my case.
Thanks again

@New0
Copy link
Author

New0 commented May 7, 2019

Hello, I see that pow() and ** are not supported and that log() only accepts one argument.

Is that correct ?

@mossadal
Copy link
Owner

mossadal commented May 17, 2019

The standard lexer/parser that ships with the project only uses ^ for exponentiation, and log for the logarithm to base e. If you want to change that, I would suggest that you implement your own lever. Use StdMathLexer as inspiration.

Actually, let me think a little more about this. I just realised that there is no obvious way to add functions taking several comma-separated arguments.

@New0
Copy link
Author

New0 commented May 19, 2019

Hello @mossadal , thank you for your answer.

Yes I was wrong considering that php functions would also be valid/accepted formulas, but I realize it doesn't have to be the case.

I also tried to add comas as a valid token but realized I couldn't develop the logic to for coma separated arguments at the moment.

Thank you again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants