denissimon / formula-parser

Parsing and evaluating mathematical formulas given as strings.
MIT License
76 stars 24 forks source link

Problem when variable is next to number #3

Closed yakamuki closed 5 years ago

yakamuki commented 5 years ago

Hey @denissimon great work. I have a small issue when trying to evaluate an expression. If i give the expression 3 6x (between 6 and 'x' there is no operator or space), and set Variable 'x' to 1, then i get the result 3. Which means that somehow, it ignores the number 6, and evaluates the expression 3 x. (i used 'x' as 2 and i get as result 6). But when i give the expression 3 * x6, i get a syntax error, as expected. Shouldn't i get a syntax error as well in the first case? Why it ignores the number given before the variable, when there is neither operator or space between them?

Cheers

denissimon commented 5 years ago

Hi, @yakamuki Yes, in both cases it should output a “Syntax error”. Fixed. Added to the FormulaParserTest.php. Thanks!