This might be very simplistic for this forum (apologies, if so). How does one evaluate the tree below. I am not looking for a solution, just assistance in how to evaluate it:

Abstract syntax tree

I assume I start at the top node, (i.e. add the two node answers together)

  • Left node, right split: $ ( 2 \div 1 ) $ — this needs to get multiplied with next left split.
  • Left node left split, left split, $ 160 \cdot 5 $.
  • Left node right split: $ 160^{676} $ ?
  • Right node left split, left split: $ 145 + 27 $ ?
  • Right node left split right split: ?
  • Right node right split: wheel completely fallen off.

Thanks in advance.


closed as off-topic by user21820, MickG, JonMark Perry, Watson, user91500 Jun 14 '16 at 10:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about mathematics, within the scope defined in the help center." – user21820, JonMark Perry, Watson, user91500
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ What are the rules of this kind of game? What is a solution? (Is it a number?) $\endgroup$ – dankness Jun 14 '16 at 9:24
  • $\begingroup$ yup, we end up with a number - only rule is traverse the tree to get a solution $\endgroup$ – Crudler Jun 14 '16 at 9:25

The tree doesn't make any sense (assuming that it is an Abstract Syntax Tree). In ASTs, you recursively evaluate the children of a node, which doesn't make much sense here (you cannot say, "What is $ \times 5 $?").

Let me briefly explain why:

  1. In ASTs, the precedence is described in the tree structure, and not their nodes (that is, there is no parathesis node).

  2. The nodes follows some rules, based on their type, for example $ + $ is a binary operation, and thus has exactly two children. Nonetheless, your example contains multiple nodes breaking these rules.

So, in conclusion, the tree is malformed and cannot be evaluated as is.

  • 1
    $\begingroup$ At least I don't feel stupid now. I thought something smelled funny $\endgroup$ – Crudler Jun 14 '16 at 11:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.