From ba39ee1fad62c9b12360d6a779eeecf85091c897 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 7 Aug 2017 19:16:51 -0700 Subject: [PATCH] Rewrite the Operator in Kotlin. --- .../org/nwapw/abacus/function/Operator.java | 76 ------------------- .../org/nwapw/abacus/function/Operator.kt | 14 ++++ 2 files changed, 14 insertions(+), 76 deletions(-) delete mode 100644 src/main/java/org/nwapw/abacus/function/Operator.java create mode 100644 src/main/kotlin/org/nwapw/abacus/function/Operator.kt diff --git a/src/main/java/org/nwapw/abacus/function/Operator.java b/src/main/java/org/nwapw/abacus/function/Operator.java deleted file mode 100644 index b7352c4..0000000 --- a/src/main/java/org/nwapw/abacus/function/Operator.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.nwapw.abacus.function; - -/** - * A class that represents a single infix operator. - */ -public class Operator { - - /** - * The associativity of the operator. - */ - private OperatorAssociativity associativity; - /** - * The type of this operator. - */ - private OperatorType type; - /** - * The precedence of the operator. - */ - private int precedence; - /** - * The function that is called by this operator. - */ - private Function function; - - /** - * Creates a new operator with the given parameters. - * - * @param associativity the associativity of the operator. - * @param operatorType the type of this operator, like binary infix or unary postfix. - * @param precedence the precedence of the operator. - * @param function the function that the operator calls. - */ - public Operator(OperatorAssociativity associativity, OperatorType operatorType, int precedence, Function function) { - this.associativity = associativity; - this.type = operatorType; - this.precedence = precedence; - this.function = function; - } - - /** - * Gets the operator's associativity. - * - * @return the associativity. - */ - public OperatorAssociativity getAssociativity() { - return associativity; - } - - /** - * Gets the operator's type. - * - * @return the type. - */ - public OperatorType getType() { - return type; - } - - /** - * Gets the operator's precedence. - * - * @return the precedence. - */ - public int getPrecedence() { - return precedence; - } - - /** - * Gets the operator's function. - * - * @return the function. - */ - public Function getFunction() { - return function; - } - -} diff --git a/src/main/kotlin/org/nwapw/abacus/function/Operator.kt b/src/main/kotlin/org/nwapw/abacus/function/Operator.kt new file mode 100644 index 0000000..e0cb60f --- /dev/null +++ b/src/main/kotlin/org/nwapw/abacus/function/Operator.kt @@ -0,0 +1,14 @@ +package org.nwapw.abacus.function + +/** + * A single operator that can be used by Abacus. + * + * This is a data class that holds the information about a single operator, such as a plus or minus. + * + * @param associativity the associativity of this operator, used for order of operations;. + * @param type the type of this operator, used for parsing (infix / prefix / postfix and binary / unary) + * @param precedence the precedence of this operator, used for order of operations. + * @param function the function this operator applies to its arguments. + */ +data class Operator(val associativity: OperatorAssociativity, val type: OperatorType, + val precedence: Int, val function: Function) \ No newline at end of file