mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-18 00:19:32 -08:00
Rewrite the Operator in Kotlin.
This commit is contained in:
parent
5aab7891f2
commit
ba39ee1fad
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
14
src/main/kotlin/org/nwapw/abacus/function/Operator.kt
Normal file
14
src/main/kotlin/org/nwapw/abacus/function/Operator.kt
Normal file
|
@ -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)
|
Loading…
Reference in New Issue
Block a user