How would I Evaluate a certain formula?

后端 未结 4 1319
旧时难觅i
旧时难觅i 2021-01-27 09:24

I have a multidimension arrayList and I ask the user for a formula and than I evaluate it. The problem is that I get user input like this:

  ((a1+a2)/12)*a3
         


        
4条回答
  •  故里飘歌
    2021-01-27 09:49

    Personally, I'd try really hard to avoid all the parsing stuff, and look for an EL library that allows you to use your own variable resolver. All you'd need to do then is hook up the variables to your backing model. (In your case, splitting on word/letter boundary, and looking up cell contents.)

    This would also allow you to include arbitrary functions by simply exposing them to the EL engine. Something like OGNL, MVEL, etc. might be a good starting point. Seems much easier.

提交回复
热议问题