MCPcopy Create free account
hub / github.com/PDAL/PDAL / addexpr

Method addexpr

filters/private/expr/MathParser.cpp:16–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16bool MathParser::addexpr(Expression& expr)
17{
18 if (!multexpr(expr))
19 return false;
20
21 while (true)
22 {
23 NodeType type;
24
25 if (match(TokenType::Plus))
26 type = NodeType::Add;
27 else if (match(TokenType::Dash))
28 type = NodeType::Subtract;
29 else
30 return true;
31
32 if (!multexpr(expr))
33 {
34 setError("Expected expression following '" + curToken().sval() + "'.");
35 return false;
36 }
37
38 NodePtr right = expr.popNode();
39 NodePtr left = expr.popNode();
40
41 ConstValueNode *leftVal = dynamic_cast<ConstValueNode *>(left.get());
42 ConstValueNode *rightVal = dynamic_cast<ConstValueNode *>(right.get());
43 if (leftVal && rightVal)
44 {
45 double v = (type == NodeType::Add) ?
46 leftVal->value() + rightVal->value() :
47 leftVal->value() - rightVal->value();
48 expr.pushNode(NodePtr(new ConstValueNode(v)));
49 }
50 else
51 {
52 if (left->isBool() || right->isBool())
53 {
54 setError("Can't apply '" + curToken().sval() + "' to "
55 "logical expression.");
56 return false;
57 }
58 expr.pushNode(NodePtr(new BinMathNode(type, std::move(left), std::move(right))));
59 }
60 }
61 return true;
62}
63
64bool MathParser::multexpr(Expression& expr)
65{

Callers

nothing calls this directly

Calls 6

svalMethod · 0.80
popNodeMethod · 0.80
pushNodeMethod · 0.80
getMethod · 0.45
valueMethod · 0.45
isBoolMethod · 0.45

Tested by

no test coverage detected