Writing a parser from scratch? I would assume a recursive function based on discovery of open brackets and secondary recursion based on operator priority. Someone has probably written this in 12 lines of code

Minus another 12 lines of warning and error messages.
When stumped, I increase granularity of warning, error, or debug messages (developer mode) as appropriate. Eventually it may reveal the underlying typo, syntax error or limitation. An example would be sending a string from a calling function that provides a name or other info to be reported in a warning message.