Calamari / shunting-yard.js

The shunting yard algorithm transforms a mathematical expression from infix notation into a reversed polish notation (postfix).
23 stars 3 forks source link

Did not get the expected value #24

Open rookiefront opened 1 year ago

rookiefront commented 1 year ago
const shuntingYard = new ShuntingYard();
var rpn = shuntingYard.parse([6, '+', 'sqrt', '(', 6, '+', 3, ')']);
// [6, '+', 6, 3, '+', 'sqrt']
var result = shuntingYard.resolveRpn(rpn);
// Error 
/*
vue.runtime.esm.js:1442 TypeError: Cannot read properties of undefined (reading 'apply')
    at ShuntingYard.resolveRpn (ShuntingYard.js?t=1689476073976:116:30)
*/

op.params is null

image

Calamari commented 1 year ago

Hey @rookiefront , sorry for the delayed response. Question: did you define what "'sqrt' is ? I don't see that any shuntingYard.addOperator call in your code snippet above. Without that, the resolver will not know what to do with sqrt. How to use it is described in the README, but if you have questions, please feel free to follow up :)

Calamari commented 1 year ago

But I think a nicer error message might be a dev quality improvement :)