15,900,586 members
See more:
I have made a basic app that can derivate a mathematical expression. The current input method looks like this:
JavaScript
`G = new Ln(new Add(new X(), new Add(new Constant(2), new Ln(new X()))));`
Is there a way to use the string input method which is looks like this:
`ln(x+(2+ln(x)))`
How could I do that?

I know how basic tokenzier works, I have already made one (github). But I do not know how to convert a tokenzied array into
JavaScript
`G = new Ln(new Add(new X(), new Add(new Constant(2), new Ln(new X()))));`
format??

I am newbie in the fields of programming.

What I have tried:

You can find my question at stackoverflow: https://stackoverflow.com/q/73425663/19807534[^]
Posted
Updated 22-Aug-22 6:16am

## Solution 1

1) If I wanted to answer SO questions, I'd answer questions at SO, not CP. Posting so multiple groups do the same work for you is a good way to get peoples backs up - and annoyed people are less likely to help you than happy ones.

2) If you have written a tokenizer, then you've done the donkey work already: now convert the tokens into a stack-based (RPN) form and evaluate them:
`ln(x+(2+ln(x)))`
Becomes
`x 2 x ln + + ln`
Now unwind the stack and it's easy to evaluate. Converting infix to RPN (shunting-yard algorithm) | andreinc[^]