I'm working on a program that takes in user input which often includes things like math.sqrt()
, imaginary numbers, multiplication, division, and similar (basically, standard math plus imaginary numbers).
Currently, I'm using eval()
(don't worry, this is not the sort of program that is used on public computers and I have a major warning on the github repository) but I want to switch this to some sort of custom parser that can handle calls to the cmath and math modules, along with *, /, +, and - without risking computer security.
I've heard of ast
, but it also seems like a significant amount of work, and sandboxing eval()
is very difficult to impossible. What are my options for approaches here?