2017-09-23 23:43:08 -07:00
|
|
|
package org.nwapw.abacus.tree.nodes
|
|
|
|
|
|
|
|
import org.nwapw.abacus.tree.Reducer
|
2017-08-25 17:46:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A binary operator node that reduces its children.
|
|
|
|
*
|
|
|
|
* NumberBinaryNode operates by simply reducing its children and
|
|
|
|
* then using the result of that reduction to reduce itself.
|
|
|
|
*
|
|
|
|
* @param operation the operation this node performs.
|
|
|
|
* @param left the left child of this node.
|
|
|
|
* @param right the right child of this node.
|
|
|
|
*/
|
2017-09-07 12:31:40 -07:00
|
|
|
class NumberBinaryNode(operation: String, left: TreeNode, right: TreeNode)
|
2017-08-25 17:46:25 -07:00
|
|
|
: BinaryNode(operation, left, right) {
|
|
|
|
|
2017-09-07 12:53:12 -07:00
|
|
|
override fun <T : Any> reduce(reducer: Reducer<T>): T {
|
|
|
|
val left = left.reduce(reducer)
|
|
|
|
val right = right.reduce(reducer)
|
2017-08-25 17:46:25 -07:00
|
|
|
return reducer.reduceNode(this, left, right)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|