beltoforion / muparserx

A C++ Library for Parsing Expressions with Strings, Complex Numbers, Vectors, Matrices and more.
http://beltoforion.de/en/muparserx
BSD 2-Clause "Simplified" License
137 stars 60 forks source link

UnknownException when defining variables with dot (.) #97

Closed atilag closed 4 years ago

atilag commented 5 years ago

I'm getting an exception if I define a variable with a dot into it:

ParserX parser;
Value pi(M_PI);
parser.DefineVar("np.pi", Variable(&pi)); // <--- Throws

Is this expected? As a last resort I could filter them and remove the dots

Thanks for sharing this library! It's being very helpful! :)

beltoforion commented 5 years ago

Variable, constant or function names with a "." are not allowed. As far as i can see you should receive a ParserException that explains this. This is normal behavior, just catch and evaluate the exception..

You can try to add the "." to line 62 of mpParser.cpp or call the function DefineNameChars directly. This will make it an allowed character although i cannot guarantee it won't collide with other operators.

jarom-nelson commented 4 years ago

We've been able to get this to work by building up a string of acceptable name characters, including '.', and assigning it via ParserXBase::DefineNameChars

beltoforion commented 4 years ago

closed; not a bug; can be adjusted with existing API