-
Notifications
You must be signed in to change notification settings - Fork 37
Decimals without a leading integer cause errors #57
Comments
Hello :-), The syntax for real numbers must have an integer part, so something before |
Hi. |
Any @hoaproject/hoackers to try this? Maybe @Grummfy or @vonglasow? |
👍 IMO. Looks pragmatic to support |
I don't think it will be complicated to implement also so 👍 |
@vonglasow So, how would you tackle this problem? There is many ways to do so, can you expose yours :-)? |
For now, I'm passing user entered expressions to the following function to "clean" them first. So far, so good, but I'm guessing you would have better ways of achieving this 😃 I just know at some point, someone is going to get something by this simple little regexp but until then, all is good. Thanks for a great lib. So far, yours is the only one I have tried that actually works and has built in support for floor().
|
Like it seems all calculator (physically or virtual) allow to begin by dot for decimal it should be a good idea to follow the same common usage. |
@vonglasow There is several strategies possible. I would like to hear yours before starting a PR :-). |
Example:
$expression = '.35 + .65';
$ast = $compiler->parse($expression);
echo $visitor->visit($ast);
Result:
Uncaught Hoa\Compiler\Exception\UnrecognizedToken, code: 0
Message: Unrecognized token "." at line 1 and column 1: .35 + .65 ↑
File: /web/htdocs/lmifirearms/vendor/hoa/compiler/Llk/Lexer.php
Line: 1
BUT
$expression = '0.35 + 0.65';
$ast = $compiler->parse($expression);
echo $visitor->visit($ast);
Works fine.
This is problematic if evaluating formulas entered by end users, which I am ;-).
Thanks
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: