| 172 | } |
| 173 | |
| 174 | bool MathParser::function0(Expression& expr) |
| 175 | { |
| 176 | struct Func0 |
| 177 | { |
| 178 | std::string name; |
| 179 | double value; |
| 180 | }; |
| 181 | |
| 182 | static const std::vector<Func0> funcs { |
| 183 | { "nan", std::numeric_limits<double>::quiet_NaN() }, |
| 184 | { "lowest", std::numeric_limits<double>::lowest() }, |
| 185 | { "highest", (std::numeric_limits<double>::max)() } |
| 186 | }; |
| 187 | |
| 188 | std::string name = curToken().sval(); |
| 189 | auto it = std::find_if(funcs.begin(), funcs.end(), |
| 190 | [&name](const Func0& f){ return f.name == name; }); |
| 191 | |
| 192 | if (it == funcs.end()) |
| 193 | { |
| 194 | if (peekToken() == TokenType::Lparen) |
| 195 | setError("Invalid function name '" + name + "'"); |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | if (!match(TokenType::Lparen)) |
| 200 | { |
| 201 | setError("Expecting '(' to open function invocation of '" + name + "'."); |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | if (!match(TokenType::Rparen)) |
| 206 | { |
| 207 | setError("Expecting ')' to close function invocation of '" + name + "'."); |
| 208 | return false; |
| 209 | } |
| 210 | |
| 211 | expr.pushNode(NodePtr(new ConstValueNode(it->value))); |
| 212 | |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | bool MathParser::function1(Expression& expr) |
| 217 | { |