2 #ifndef _EVALUATION_VISITOR_CPP_ 3 #define _EVALUATION_VISITOR_CPP_ 47 madara::expression::EvaluationVisitor::visit (
50 stack_.push (node.
item ());
55 madara::expression::EvaluationVisitor::visit (
58 stack_.push (node.
item ());
63 madara::expression::EvaluationVisitor::visit (
66 stack_.push (node.
item ());
71 madara::expression::EvaluationVisitor::visit (
74 stack_.push (node.
item ());
79 madara::expression::EvaluationVisitor::visit (
82 stack_.push (node.
item ());
87 madara::expression::EvaluationVisitor::visit (
90 stack_.push (node.
item ());
95 madara::expression::EvaluationVisitor::visit (
98 stack_.push (node.
item ());
103 madara::expression::EvaluationVisitor::visit (
110 madara::expression::EvaluationVisitor::visit (
113 if (stack_.size () >= 1)
114 stack_.push (-stack_.pop ());
117 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
118 "\nKARL EVAL ERROR: Negate" \
119 " requires a right expression"));
121 throw KarlException (
"madara::expression::CompositeNegateNode: " 122 "KARL COMPILE ERROR: " 123 "Node has no right expression\n");
129 madara::expression::EvaluationVisitor::visit (
132 if (stack_.size () >= 1)
137 VariableNode * right = dynamic_cast <VariableNode *> (node.
right ());
142 new_value = right->dec ();
144 stack_.push (new_value);
146 catch (::std::bad_cast &)
148 stack_.push (--old_value);
153 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
154 "\nKARL EVAL ERROR: Predecrement" \
155 " requires a right expression"));
162 madara::expression::EvaluationVisitor::visit (
165 if (stack_.size () >= 1)
170 VariableNode * right = dynamic_cast <VariableNode *> (node.
right ());
175 new_value = right->inc ();
177 stack_.push (new_value);
179 catch (::std::bad_cast &)
181 stack_.push (++old_value);
186 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
187 "\nKARL EVAL ERROR: Preincrement" \
188 " requires a right expression"));
195 madara::expression::EvaluationVisitor::visit (
198 if (stack_.size () >= 1)
199 stack_.push (!stack_.pop ());
202 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
203 "\nKARL EVAL ERROR: Not" \
204 " requires a right expression"));
211 madara::expression::EvaluationVisitor::visit (
214 if (stack_.size () >= 2)
215 stack_.push (stack_.pop () + stack_.pop ());
218 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
219 "\nKARL EVAL ERROR: Add" \
220 " requires both a left and right expression"));
227 madara::expression::EvaluationVisitor::visit (
230 if (stack_.size () >= 2)
240 VariableNode * left = dynamic_cast <VariableNode *> (node.
left ());
244 catch (::std::bad_cast &)
246 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
247 "\nKARL EVAL ERROR: Assignment" \
248 " must have a variable as the left expression\n"));
257 madara::expression::EvaluationVisitor::visit (
260 if (stack_.size () >= 2)
265 stack_.push (left && right);
269 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
270 "\nKARL EVAL ERROR: And" \
271 " requires both a left and right expression\n"));
278 madara::expression::EvaluationVisitor::visit (
281 if (stack_.size () >= 2)
286 stack_.push (left || right);
290 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
291 "\nKARL EVAL ERROR: Or" \
292 " requires both a left and right expression\n"));
299 madara::expression::EvaluationVisitor::visit (
302 if (stack_.size () >= 2)
309 stack_.push (left_v > right_v ? left_v : right_v);
313 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
314 "\nKARL EVAL ERROR: And" \
315 " requires both a left and right expression\n"));
322 madara::expression::EvaluationVisitor::visit (
325 if (stack_.size () >= 2)
332 stack_.push (left_v > right_v ? right_v : left_v);
336 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
337 "\nKARL EVAL ERROR: And" \
338 " requires both a left and right expression\n"));
345 madara::expression::EvaluationVisitor::visit (
352 madara::expression::EvaluationVisitor::visit (
359 madara::expression::EvaluationVisitor::visit (
362 if (stack_.size () >= 2)
367 stack_.push (left == right);
371 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
372 "\nKARL EVAL ERROR: Equality" \
373 " requires both a left and right expression\n"));
380 madara::expression::EvaluationVisitor::visit (
383 if (stack_.size () >= 2)
388 stack_.push (left != right);
392 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
393 "\nKARL EVAL ERROR: Inequality" \
394 " requires both a left and right expression\n"));
401 madara::expression::EvaluationVisitor::visit (
404 if (stack_.size () >= 2)
409 stack_.push (left >= right);
413 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
414 "\nKARL EVAL ERROR: Greater-than-equal" \
415 " requires both a left and right expression\n"));
422 madara::expression::EvaluationVisitor::visit (
425 if (stack_.size () >= 2)
430 stack_.push (left > right);
434 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
435 "\nKARL EVAL ERROR: Greater-than" \
436 " requires both a left and right expression\n"));
443 madara::expression::EvaluationVisitor::visit (
446 if (stack_.size () >= 2)
451 stack_.push (left <= right);
455 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
456 "\nKARL EVAL ERROR: Less-than-equal" \
457 " requires both a left and right expression\n"));
464 madara::expression::EvaluationVisitor::visit (
467 if (stack_.size () >= 2)
472 stack_.push (left < right);
476 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
477 "\nKARL EVAL ERROR: Less-than" \
478 " requires both a left and right expression\n"));
485 madara::expression::EvaluationVisitor::visit (
488 if (stack_.size () >= 2)
491 stack_.push (stack_.pop () - rhs);
495 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
496 "\nKARL EVAL ERROR: Subtract" \
497 " requires both a left and right expression\n"));
504 madara::expression::EvaluationVisitor::visit (
507 if (stack_.size () >= 2 && stack_.top ())
510 stack_.push (stack_.pop () / rhs );
514 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
515 "\nKARL EVAL ERROR: Division" \
516 " requires both a left and right expression" \
517 " (and right must not be 0)\n"));
524 madara::expression::EvaluationVisitor::visit (
527 if (stack_.size () >= 2)
528 stack_.push (stack_.pop () * stack_.pop ());
531 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
532 "\nKARL EVAL ERROR: Multiply" \
533 " requires both a left and right expression\n"));
540 madara::expression::EvaluationVisitor::visit (
543 if (stack_.size () >= 2 && stack_.top ())
546 stack_.push (stack_.pop () / rhs );
550 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
551 "\nKARL EVAL ERROR: Modulus" \
552 " requires both a left and right expression" \
553 " (and right must not be 0)\n"));
560 madara::expression::EvaluationVisitor::visit (
563 if (stack_.size () >= 2)
564 stack_.push (stack_.pop () ? stack_.pop () : 0);
567 MADARA_ERROR (MADARA_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
568 "\nKARL EVAL ERROR: Implies" \
569 " requires both a left and right expression"));
576 madara::expression::EvaluationVisitor::total (
void)
578 if (!stack_.is_empty ())
579 return stack_.top ();
586 madara::expression::EvaluationVisitor::reset (
void)
591 #endif // _USE_VISITORS_ This class encapsulates an entry in a KnowledgeBase.
Composite node that divides a variable by some right hand side.
Defines a terminal node of that references the current value stored in a variable.
A composite node that increments a right expression.
Defines a terminal node of that references the current value stored in a variable.
A composite node that encompasses addition of two expressions.
A composite node that compares left and right children for inequality.
Composite node that subtracts a variable by some right hand side.
A composite node that encompasses subtraction of a right expression from a left expression.
A composite node that iterates until a condition is met.
A composite node that divides a left expression by a right expression and returns the remainder of th...
A composite node that compares left and right expressions for greater than or equal to...
A composite node that evaluates both left and right expressions regardless of their evaluations...
A composite node that compares left and right children for less than or equal to. ...
A composite node that multiplies a left expression by a right expression.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
A composite node that performs an implication (inference rule)
A composite node that decrements a right expression.
A composite node that evaluates both left and right expressions regardless of their evaluations...
A composite node that calls a function.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
A composite node that performs a logical and.
Composite node that multiplies a variable by some right hand side.
A composite node that compares left and right expressions for equality.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
A composite node that logically nots a right expression.
A composite node that allows for variable assignment.
A composite node that compares left and right children for greater than.
A composite node that integrally negates a right expression.
Integer to_integer(void) const
converts the value to an integer.
virtual ComponentNode * left(void) const
Returns the left expression.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the printable value of the node.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
A composite node that performs a logical or.
A composite node that divides a left expression by a right one.
Defines a terminal node of that references the current value stored in a variable.
Defines a terminal node that contains a list.
virtual ComponentNode * right(void) const
Returns the right expression.
A composite node that compares left and right children for less than.