mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-17 16:09:32 -08:00
Add comments to the newly created Kotlin implementations.
This commit is contained in:
parent
62e8971db2
commit
5aab7891f2
|
@ -1,5 +1,16 @@
|
|||
package org.nwapw.abacus.tree
|
||||
|
||||
/**
|
||||
* A tree node that holds a binary operation.
|
||||
*
|
||||
* This node represents any binary operation, such as binary infix or binary postfix. The only
|
||||
* currently implemented into Abacus is binary infix, but that has more to do with the parser than
|
||||
* this class, which doesn't care about the order that its operation and nodes were found in text.
|
||||
*
|
||||
* @param operation the operation this node performs on its children.
|
||||
* @param left the left node.
|
||||
* @param right the right node.
|
||||
*/
|
||||
data class BinaryNode(val operation: String, val left: TreeNode? = null, val right: TreeNode?) : TreeNode() {
|
||||
|
||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
package org.nwapw.abacus.tree
|
||||
|
||||
/**
|
||||
* A tree node that holds a function call.
|
||||
*
|
||||
* The function call node can hold any number of children, and passes the to the appropriate reducer,
|
||||
* but that is its sole purpose.
|
||||
*
|
||||
* @param function the function string.
|
||||
*/
|
||||
data class FunctionNode(val function: String) : TreeNode() {
|
||||
|
||||
/**
|
||||
* List of function parameters added to this node.
|
||||
*/
|
||||
val children: MutableList<TreeNode> = mutableListOf()
|
||||
|
||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||
|
@ -20,10 +31,20 @@ data class FunctionNode(val function: String) : TreeNode() {
|
|||
return super.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a child to this node's list of children.
|
||||
*
|
||||
* @node the node to append.
|
||||
*/
|
||||
fun appendChild(node: TreeNode){
|
||||
children.add(node)
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends a child to this node's list of children.
|
||||
*
|
||||
* @node the node to prepend.
|
||||
*/
|
||||
fun prependChild(node: TreeNode){
|
||||
children.add(0, node)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,14 @@ package org.nwapw.abacus.tree
|
|||
|
||||
import org.nwapw.abacus.number.NumberInterface
|
||||
|
||||
/**
|
||||
* A tree node that holds a single number value.
|
||||
*
|
||||
* This is a tree node that holds a single NumberInterface, which represents any number,
|
||||
* and is not defined during compile time.
|
||||
*
|
||||
* @number the number value of this node.
|
||||
*/
|
||||
data class NumberNode(val number: NumberInterface) : TreeNode() {
|
||||
|
||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.nwapw.abacus.tree
|
||||
|
||||
/**
|
||||
* A tree node.
|
||||
*/
|
||||
abstract class TreeNode {
|
||||
|
||||
abstract fun <T: Any> reduce(reducer: Reducer<T>) : T?
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
package org.nwapw.abacus.tree
|
||||
|
||||
/**
|
||||
* A tree node that holds a unary operation.
|
||||
*
|
||||
* This node holds a single operator applied to a single parameter, and does not care
|
||||
* whether the operation was found before or after the parameter in the text.
|
||||
*
|
||||
* @param operation the operation applied to the given node.
|
||||
* @param applyTo the node to which the operation will be applied.
|
||||
*/
|
||||
data class UnaryNode(val operation: String, val applyTo: TreeNode? = null) : TreeNode() {
|
||||
|
||||
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||
|
|
Loading…
Reference in New Issue
Block a user