mirror of
https://github.com/DanilaFe/abacus
synced 2026-01-25 08:05:19 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18b252afb1 | ||
|
|
b2a20226d3 | ||
|
|
d67d498625 | ||
|
|
2e9c88c39e | ||
|
|
b9c88b9d24 |
@@ -1,8 +1,3 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'application'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.1.3'
|
||||
}
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'application'
|
||||
|
||||
@@ -12,7 +7,6 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compile 'com.moandjiezana.toml:toml4j:0.7.1'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8"
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.nwapw.abacus;
|
||||
|
||||
import org.nwapw.abacus.config.Configuration;
|
||||
import org.nwapw.abacus.fx.AbacusApplication;
|
||||
import org.nwapw.abacus.fx.AbacusController;
|
||||
import org.nwapw.abacus.number.NaiveNumber;
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
import org.nwapw.abacus.parsing.LexerTokenizer;
|
||||
import org.nwapw.abacus.parsing.ShuntingYardParser;
|
||||
@@ -12,6 +14,8 @@ import org.nwapw.abacus.plugin.StandardPlugin;
|
||||
import org.nwapw.abacus.tree.NumberReducer;
|
||||
import org.nwapw.abacus.tree.TreeNode;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* The main calculator class. This is responsible
|
||||
* for piecing together all of the components, allowing
|
||||
@@ -43,13 +47,13 @@ public class Abacus {
|
||||
* from a string.
|
||||
*/
|
||||
private TreeBuilder treeBuilder;
|
||||
|
||||
private AbacusController controller;
|
||||
/**
|
||||
* Creates a new instance of the Abacus calculator.
|
||||
*
|
||||
* @param configuration the configuration object for this Abacus instance.
|
||||
*/
|
||||
public Abacus(Configuration configuration) {
|
||||
public Abacus(Configuration configuration,AbacusController controller) {
|
||||
pluginManager = new PluginManager(this);
|
||||
numberReducer = new NumberReducer(this);
|
||||
this.configuration = new Configuration(configuration);
|
||||
@@ -59,8 +63,12 @@ public class Abacus {
|
||||
|
||||
pluginManager.addListener(shuntingYardParser);
|
||||
pluginManager.addListener(lexerTokenizer);
|
||||
}
|
||||
this.controller =controller;
|
||||
|
||||
}
|
||||
public NumberInterface getVar(String variable){
|
||||
return controller.getVar(variable);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
AbacusApplication.launch(AbacusApplication.class, args);
|
||||
}
|
||||
|
||||
76
src/main/java/org/nwapw/abacus/function/Operator.java
Normal file
76
src/main/java/org/nwapw/abacus/function/Operator.java
Normal file
@@ -0,0 +1,76 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
package org.nwapw.abacus.fx;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.transformation.FilteredList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.CheckBoxListCell;
|
||||
@@ -15,15 +12,15 @@ import javafx.util.StringConverter;
|
||||
import org.nwapw.abacus.Abacus;
|
||||
import org.nwapw.abacus.config.Configuration;
|
||||
import org.nwapw.abacus.number.ComputationInterruptedException;
|
||||
import org.nwapw.abacus.number.NaiveNumber;
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
import org.nwapw.abacus.plugin.ClassFinder;
|
||||
import org.nwapw.abacus.plugin.PluginListener;
|
||||
import org.nwapw.abacus.plugin.PluginManager;
|
||||
import org.nwapw.abacus.plugin.StandardPlugin;
|
||||
import org.nwapw.abacus.plugin.*;
|
||||
import org.nwapw.abacus.tree.TreeNode;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -67,14 +64,22 @@ public class AbacusController implements PluginListener {
|
||||
*/
|
||||
private static final String ERR_EXCEPTION = "Exception Thrown";
|
||||
@FXML
|
||||
private TextArea macroOutputField;
|
||||
@FXML
|
||||
private Tab macroTab;
|
||||
@FXML
|
||||
private TextArea macroField;
|
||||
@FXML
|
||||
private Button inputButtonMacro;
|
||||
@FXML
|
||||
private Button stopButtonMacro;
|
||||
@FXML
|
||||
private TabPane coreTabPane;
|
||||
@FXML
|
||||
private Tab calculateTab;
|
||||
@FXML
|
||||
private Tab settingsTab;
|
||||
@FXML
|
||||
private Tab functionListTab;
|
||||
@FXML
|
||||
private TableView<HistoryModel> historyTable;
|
||||
@FXML
|
||||
private TableColumn<HistoryModel, String> inputColumn;
|
||||
@@ -96,11 +101,7 @@ public class AbacusController implements PluginListener {
|
||||
private ListView<ToggleablePlugin> enabledPluginView;
|
||||
@FXML
|
||||
private TextField computationLimitField;
|
||||
@FXML
|
||||
private ListView<String> functionListView;
|
||||
@FXML
|
||||
private TextField functionListSearchField;
|
||||
|
||||
private String macroOutputText;
|
||||
/**
|
||||
* The list of history entries, created by the users.
|
||||
*/
|
||||
@@ -117,20 +118,12 @@ public class AbacusController implements PluginListener {
|
||||
* and, when reloaded, get added to the plugin manager's black list.
|
||||
*/
|
||||
private ObservableList<ToggleablePlugin> enabledPlugins;
|
||||
/**
|
||||
* The list of functions that are registered in the calculator.
|
||||
*/
|
||||
private ObservableList<String> functionList;
|
||||
/**
|
||||
* The filtered list displayed to the user.
|
||||
*/
|
||||
private FilteredList<String> functionFilter;
|
||||
|
||||
/**
|
||||
* The abacus instance used for changing the plugin configuration.
|
||||
*/
|
||||
private Abacus abacus;
|
||||
|
||||
private boolean stop;
|
||||
/**
|
||||
* Boolean which represents whether changes were made to the configuration.
|
||||
*/
|
||||
@@ -143,6 +136,17 @@ public class AbacusController implements PluginListener {
|
||||
* The alert shown when a press to "apply" is needed.
|
||||
*/
|
||||
private Alert reloadAlert;
|
||||
private ArrayList<Plugin> plugins;
|
||||
public NumberInterface getVar(String variable){
|
||||
for(Plugin plugin:plugins){
|
||||
if(plugin instanceof VariablePlugin){
|
||||
if(((VariablePlugin)plugin).getValue(variable)!=null)
|
||||
return ((VariablePlugin)plugin).getValue(variable);
|
||||
return NaiveNumber.ZERO;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* The runnable that takes care of killing computations that take too long.
|
||||
*/
|
||||
@@ -228,11 +232,6 @@ public class AbacusController implements PluginListener {
|
||||
}
|
||||
});
|
||||
|
||||
functionList = FXCollections.observableArrayList();
|
||||
functionFilter = new FilteredList<>(functionList, (s) -> true);
|
||||
functionListView.setItems(functionFilter);
|
||||
functionListSearchField.textProperty().addListener((observable, oldValue, newValue) ->
|
||||
functionFilter.setPredicate((newValue.length() == 0) ? ((s) -> true) : ((s) -> s.contains(newValue))));
|
||||
historyData = FXCollections.observableArrayList();
|
||||
historyTable.setItems(historyData);
|
||||
numberImplementationOptions = FXCollections.observableArrayList();
|
||||
@@ -252,10 +251,15 @@ public class AbacusController implements PluginListener {
|
||||
if (oldValue.equals(settingsTab)) alertIfApplyNeeded(true);
|
||||
});
|
||||
|
||||
abacus = new Abacus(new Configuration(CONFIG_FILE));
|
||||
abacus = new Abacus(new Configuration(CONFIG_FILE),this);
|
||||
PluginManager abacusPluginManager = abacus.getPluginManager();
|
||||
abacusPluginManager.addListener(this);
|
||||
abacusPluginManager.addInstantiated(new StandardPlugin(abacus.getPluginManager()));
|
||||
plugins = new ArrayList<>();
|
||||
plugins.add(new StandardPlugin(abacus.getPluginManager()));
|
||||
plugins.add(new VariablePlugin(abacus.getPluginManager()));
|
||||
for(Plugin plugin: plugins){
|
||||
abacusPluginManager.addInstantiated(plugin);
|
||||
}
|
||||
try {
|
||||
ClassFinder.loadJars("plugins").forEach(abacusPluginManager::addClass);
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
@@ -283,6 +287,7 @@ public class AbacusController implements PluginListener {
|
||||
|
||||
@FXML
|
||||
public void performCalculation() {
|
||||
stop=false;
|
||||
inputButton.setDisable(true);
|
||||
stopButton.setDisable(false);
|
||||
calculationThread = new Thread(CALCULATION_RUNNABLE);
|
||||
@@ -290,17 +295,51 @@ public class AbacusController implements PluginListener {
|
||||
computationLimitThread = new Thread(TIMER_RUNNABLE);
|
||||
computationLimitThread.start();
|
||||
}
|
||||
Runnable macroCalculate = new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
stop=false;
|
||||
inputButtonMacro.setDisable(true);
|
||||
stopButtonMacro.setDisable(false);
|
||||
Scanner macroScanner = new Scanner(macroField.getText());
|
||||
String next = "!";
|
||||
macroOutputText="";
|
||||
while(!stop&¯oScanner.hasNextLine()) {
|
||||
next = macroScanner.nextLine().trim();
|
||||
if(next.equals(""))
|
||||
break;
|
||||
inputField.setText(next);
|
||||
calculationThread = new Thread(CALCULATION_RUNNABLE);
|
||||
calculationThread.start();
|
||||
computationLimitThread = new Thread(TIMER_RUNNABLE);
|
||||
computationLimitThread.start();
|
||||
while(calculationThread.isAlive()){}
|
||||
//long b = System.currentTimeMillis();
|
||||
//while(System.currentTimeMillis()-b<10000){}
|
||||
macroOutputText +=outputText.getText()+"\n";
|
||||
//next = macroScanner.nextLine().trim();
|
||||
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
macroOutputField.setText(macroOutputText);
|
||||
inputButtonMacro.setDisable(false);
|
||||
stopButtonMacro.setDisable(true);
|
||||
});
|
||||
}
|
||||
};
|
||||
@FXML
|
||||
public void macroCalculation(){
|
||||
Thread macroThread = new Thread(macroCalculate);
|
||||
macroThread.start();
|
||||
}
|
||||
@FXML
|
||||
public void performStop(){
|
||||
if(calculationThread != null) {
|
||||
calculationThread.interrupt();
|
||||
calculationThread = null;
|
||||
stop = true;
|
||||
}
|
||||
if(computationLimitThread != null){
|
||||
computationLimitThread.interrupt();
|
||||
computationLimitThread = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -347,13 +386,10 @@ public class AbacusController implements PluginListener {
|
||||
plugin.enabledProperty().addListener(e -> changesMade = true);
|
||||
enabledPlugins.add(plugin);
|
||||
}
|
||||
functionList.addAll(manager.getAllFunctions());
|
||||
functionList.sort(String::compareTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnload(PluginManager manager) {
|
||||
functionList.clear();
|
||||
enabledPlugins.clear();
|
||||
numberImplementationOptions.clear();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public class Lexer<T> {
|
||||
* @return the best match.
|
||||
*/
|
||||
public Match<T> lexOne(String from, int startAt, Comparator<T> compare) {
|
||||
//boolean variable = true;
|
||||
ArrayList<Match<T>> matches = new ArrayList<>();
|
||||
HashSet<PatternNode<T>> currentSet = new HashSet<>();
|
||||
HashSet<PatternNode<T>> futureSet = new HashSet<>();
|
||||
@@ -70,6 +71,7 @@ public class Lexer<T> {
|
||||
node.addOutputsInto(futureSet);
|
||||
} else if (node instanceof EndNode) {
|
||||
matches.add(new Match<>(from.substring(startAt, index), ((EndNode<T>) node).getPatternId()));
|
||||
//variable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +86,9 @@ public class Lexer<T> {
|
||||
if (compare != null) {
|
||||
matches.sort(Comparator.comparingInt(a -> a.getContent().length()));
|
||||
}
|
||||
//if(variable&&) {
|
||||
// matches.add(new Match<>(from.substring(startAt, index), ((EndNode<T>) node).getPatternId()));
|
||||
//}
|
||||
return matches.isEmpty() ? null : matches.get(matches.size() - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.nwapw.abacus.lexing.pattern;
|
||||
|
||||
import org.nwapw.abacus.tree.TokenType;
|
||||
|
||||
/**
|
||||
* A match that has been generated by the lexer.
|
||||
*
|
||||
|
||||
@@ -35,7 +35,6 @@ public class NaiveNumber extends NumberInterface {
|
||||
public NaiveNumber(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPrecision() {
|
||||
return 18;
|
||||
@@ -43,22 +42,22 @@ public class NaiveNumber extends NumberInterface {
|
||||
|
||||
@Override
|
||||
public NumberInterface multiplyInternal(NumberInterface multiplier) {
|
||||
return new NaiveNumber(value * ((NaiveNumber) multiplier).value);
|
||||
return new NaiveNumber(value * ((NaiveNumber) multiplier.number()).value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberInterface divideInternal(NumberInterface divisor) {
|
||||
return new NaiveNumber(value / ((NaiveNumber) divisor).value);
|
||||
return new NaiveNumber(value / ((NaiveNumber) divisor.number()).value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberInterface addInternal(NumberInterface summand) {
|
||||
return new NaiveNumber(value + ((NaiveNumber) summand).value);
|
||||
return new NaiveNumber(value + ((NaiveNumber) summand.number()).value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberInterface subtractInternal(NumberInterface subtrahend) {
|
||||
return new NaiveNumber(value - ((NaiveNumber) subtrahend).value);
|
||||
return new NaiveNumber(value - ((NaiveNumber) subtrahend.number()).value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,7 +84,7 @@ public class NaiveNumber extends NumberInterface {
|
||||
|
||||
@Override
|
||||
public int compareTo(NumberInterface number) {
|
||||
NaiveNumber num = (NaiveNumber) number;
|
||||
NaiveNumber num = (NaiveNumber) number.number();
|
||||
return Double.compare(value, num.value);
|
||||
}
|
||||
|
||||
@@ -119,6 +118,8 @@ public class NaiveNumber extends NumberInterface {
|
||||
if (toClass == this.getClass()) return this;
|
||||
else if (toClass == PreciseNumber.class) {
|
||||
return new PreciseNumber(Double.toString(value));
|
||||
}else if(toClass == Variable.class){
|
||||
return this;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,12 @@ public abstract class NumberInterface {
|
||||
if(Thread.currentThread().isInterrupted())
|
||||
throw new ComputationInterruptedException();
|
||||
}
|
||||
public NumberInterface number(){
|
||||
return this;
|
||||
}
|
||||
public Class<? extends NumberInterface> getClassVal(){
|
||||
return this.getClass();
|
||||
}
|
||||
/**
|
||||
* The maximum precision to which this number operates.
|
||||
*
|
||||
@@ -182,7 +188,7 @@ public abstract class NumberInterface {
|
||||
* Also, checks if the thread has been interrupted, and if so, throws
|
||||
* an exception.
|
||||
*
|
||||
* @return the least integer bigger or equal to the number.
|
||||
* @return the least integer bigger or equal to the number, if int can hold the value.
|
||||
*/
|
||||
public final NumberInterface ceiling(){
|
||||
checkInterrupted();
|
||||
@@ -192,7 +198,7 @@ public abstract class NumberInterface {
|
||||
/**
|
||||
* Return the greatest integer less than or equal to the number.
|
||||
*
|
||||
* @return the greatest integer smaller or equal the number.
|
||||
* @return the greatest integer smaller or equal the number, if int can hold the value.
|
||||
*/
|
||||
protected abstract NumberInterface floorInternal();
|
||||
|
||||
@@ -201,7 +207,7 @@ public abstract class NumberInterface {
|
||||
* Also, checks if the thread has been interrupted, and if so, throws
|
||||
* an exception.
|
||||
*
|
||||
* @return the greatest int smaller than or equal to the number.
|
||||
* @return the greatest int smaller or equal to the number, if int can hold the value.
|
||||
*/
|
||||
public final NumberInterface floor(){
|
||||
checkInterrupted();
|
||||
@@ -216,7 +222,7 @@ public abstract class NumberInterface {
|
||||
protected abstract NumberInterface fractionalPartInternal();
|
||||
|
||||
/**
|
||||
* Returns the fractional part of the number, specifically x - floor(x).
|
||||
* Returns the fractional part of the number.
|
||||
* Also, checks if the thread has been interrupted,
|
||||
* and if so, throws an exception.
|
||||
* @return the fractional part of the number.
|
||||
|
||||
@@ -53,22 +53,22 @@ public class PreciseNumber extends NumberInterface {
|
||||
|
||||
@Override
|
||||
public NumberInterface multiplyInternal(NumberInterface multiplier) {
|
||||
return new PreciseNumber(this.value.multiply(((PreciseNumber) multiplier).value));
|
||||
return new PreciseNumber(this.value.multiply(((PreciseNumber) multiplier.number()).value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberInterface divideInternal(NumberInterface divisor) {
|
||||
return new PreciseNumber(value.divide(((PreciseNumber) divisor).value, this.getMaxPrecision(), RoundingMode.HALF_UP));
|
||||
return new PreciseNumber(value.divide(((PreciseNumber) divisor.number()).value, this.getMaxPrecision(), RoundingMode.HALF_UP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberInterface addInternal(NumberInterface summand) {
|
||||
return new PreciseNumber(value.add(((PreciseNumber) summand).value));
|
||||
return new PreciseNumber(value.add(((PreciseNumber) summand.number()).value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberInterface subtractInternal(NumberInterface subtrahend) {
|
||||
return new PreciseNumber(value.subtract(((PreciseNumber) subtrahend).value));
|
||||
return new PreciseNumber(value.subtract(((PreciseNumber) subtrahend.number()).value));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +90,7 @@ public class PreciseNumber extends NumberInterface {
|
||||
|
||||
@Override
|
||||
public int compareTo(NumberInterface number) {
|
||||
return value.compareTo(((PreciseNumber) number).value);
|
||||
return value.compareTo(((PreciseNumber) number.number()).value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,18 +113,19 @@ public class PreciseNumber extends NumberInterface {
|
||||
String str = value.toPlainString();
|
||||
int decimalIndex = str.indexOf('.');
|
||||
if (decimalIndex != -1) {
|
||||
NumberInterface floor = new PreciseNumber(str.substring(0, decimalIndex));
|
||||
if(signum() == -1){
|
||||
floor = floor.subtract(ONE);
|
||||
}
|
||||
return floor;
|
||||
return new PreciseNumber(str.substring(0, decimalIndex));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberInterface fractionalPartInternal() {
|
||||
return this.subtractInternal(floorInternal());
|
||||
String str = value.toPlainString();
|
||||
int decimalIndex = str.indexOf('.');
|
||||
if (decimalIndex != -1) {
|
||||
return new PreciseNumber(str.substring(decimalIndex + 1));
|
||||
}
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
102
src/main/java/org/nwapw/abacus/number/Variable.java
Normal file
102
src/main/java/org/nwapw/abacus/number/Variable.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package org.nwapw.abacus.number;
|
||||
|
||||
public class Variable extends NumberInterface{
|
||||
public NumberInterface value;
|
||||
public String variable;
|
||||
|
||||
public Variable(NumberInterface value,String variable){
|
||||
this.value = value;
|
||||
this.variable = variable;
|
||||
}
|
||||
public String getVariable(){
|
||||
return variable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumberInterface number(){
|
||||
return value.number();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends NumberInterface> getClassVal(){
|
||||
return value.getClassVal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPrecision() {
|
||||
return value.getMaxPrecision();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface multiplyInternal(NumberInterface multiplier) {
|
||||
value = value.promoteToInternal(multiplier.number().getClass());
|
||||
return value.multiplyInternal(multiplier.number());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface divideInternal(NumberInterface divisor) {
|
||||
value = value.promoteToInternal(divisor.number().getClass());
|
||||
return value.divideInternal(divisor.number());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface addInternal(NumberInterface summand) {
|
||||
value = value.promoteToInternal(summand.number().getClass());
|
||||
return value.addInternal(summand.number());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface subtractInternal(NumberInterface subtrahend) {
|
||||
value = value.promoteToInternal(subtrahend.number().getClass());
|
||||
return value.subtractInternal(subtrahend.number());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface negateInternal() {
|
||||
return value.negateInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface intPowInternal(int exponent) {
|
||||
return value.intPowInternal(exponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(NumberInterface number) {
|
||||
value = value.promoteToInternal(number.number().getClass());
|
||||
return value.compareTo(number.number());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int signum() {
|
||||
return value.signum();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface ceilingInternal() {
|
||||
return value.ceilingInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface floorInternal() {
|
||||
return value.floorInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface fractionalPartInternal() {
|
||||
return value.fractionalPartInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intValue() {
|
||||
return value.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface promoteToInternal(Class<? extends NumberInterface> toClass) {
|
||||
return value.promoteToInternal(toClass);
|
||||
}
|
||||
public String toString(){
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public class LexerTokenizer implements Tokenizer<Match<TokenType>>, PluginListen
|
||||
register("[0-9]*(\\.[0-9]+)?", TokenType.NUM);
|
||||
register("\\(", TokenType.OPEN_PARENTH);
|
||||
register("\\)", TokenType.CLOSE_PARENTH);
|
||||
register("[a-zA-Z]+",TokenType.VARIABLE);
|
||||
}};
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
|
||||
matchType = match.getType();
|
||||
if (matchType == TokenType.NUM) {
|
||||
output.add(match);
|
||||
} else if (matchType == TokenType.FUNCTION) {
|
||||
}else if(matchType == TokenType.VARIABLE) {
|
||||
output.add(match);
|
||||
}else if (matchType == TokenType.FUNCTION) {
|
||||
output.add(new Match<>("", TokenType.INTERNAL_FUNCTION_END));
|
||||
tokenStack.push(match);
|
||||
} else if (matchType == TokenType.OP) {
|
||||
@@ -144,6 +146,8 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
|
||||
}
|
||||
} else if (matchType == TokenType.NUM) {
|
||||
return new NumberNode(abacus.numberFromString(match.getContent()));
|
||||
} else if (matchType == TokenType.VARIABLE){
|
||||
return new VariableNode(match.getContent());
|
||||
} else if (matchType == TokenType.FUNCTION) {
|
||||
String functionName = match.getContent();
|
||||
FunctionNode node = new FunctionNode(functionName);
|
||||
|
||||
@@ -209,9 +209,6 @@ public class PluginManager {
|
||||
if (disabledPlugins.contains(plugin.getClass().getName())) continue;
|
||||
plugin.disable();
|
||||
}
|
||||
registeredFunctions.clear();
|
||||
registeredOperators.clear();
|
||||
registeredNumberImplementations.clear();
|
||||
cachedInterfaceImplementations.clear();
|
||||
cachedPi.clear();
|
||||
listeners.forEach(e -> e.onUnload(this));
|
||||
|
||||
@@ -94,7 +94,7 @@ public class StandardPlugin extends Plugin {
|
||||
public static final Operator OP_DIVIDE = new Operator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1, new Function() {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length == 2 && params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) != 0;
|
||||
return params.length == 2 && params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClassVal())) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,26 +110,26 @@ public class StandardPlugin extends Plugin {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length == 1
|
||||
&& params[0].fractionalPart().compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0
|
||||
&& params[0].fractionalPart().compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClassVal())) == 0
|
||||
&& params[0].signum() >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
if (params[0].signum() == 0) {
|
||||
return fromInt(params[0].getClass(), 1);
|
||||
return fromInt(params[0].getClassVal(), 1);
|
||||
}
|
||||
NumberInterface factorial = params[0];
|
||||
NumberInterface multiplier = params[0];
|
||||
//It is necessary to later prevent calls of factorial on anything but non-negative integers.
|
||||
while ((multiplier = multiplier.subtract(NaiveNumber.ONE.promoteTo(multiplier.getClass()))).signum() == 1) {
|
||||
while ((multiplier = multiplier.subtract(NaiveNumber.ONE.promoteTo(multiplier.getClassVal()))).signum() == 1) {
|
||||
factorial = factorial.multiply(multiplier);
|
||||
}
|
||||
return factorial;
|
||||
/*if(!storedList.containsKey(params[0].getClass())){
|
||||
storedList.put(params[0].getClass(), new ArrayList<NumberInterface>());
|
||||
storedList.get(params[0].getClass()).add(NaiveNumber.ONE.promoteTo(params[0].getClass()));
|
||||
storedList.get(params[0].getClass()).add(NaiveNumber.ONE.promoteTo(params[0].getClass()));
|
||||
/*if(!storedList.containsKey(params[0].getClassVal())){
|
||||
storedList.put(params[0].getClassVal(), new ArrayList<NumberInterface>());
|
||||
storedList.get(params[0].getClassVal()).add(NaiveNumber.ONE.promoteTo(params[0].getClassVal()));
|
||||
storedList.get(params[0].getClassVal()).add(NaiveNumber.ONE.promoteTo(params[0].getClassVal()));
|
||||
}*/
|
||||
}
|
||||
});
|
||||
@@ -144,7 +144,7 @@ public class StandardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
return params[0].multiply((new NaiveNumber(params[0].signum())).promoteTo(params[0].getClass()));
|
||||
return params[0].multiply((new NaiveNumber(params[0].signum())).promoteTo(params[0].getClassVal()));
|
||||
}
|
||||
};
|
||||
/**
|
||||
@@ -153,31 +153,31 @@ public class StandardPlugin extends Plugin {
|
||||
public static final Function FUNCTION_LN = new Function() {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length == 1 && params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) > 0;
|
||||
return params.length == 1 && params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClassVal())) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
NumberInterface param = params[0];
|
||||
int powersOf2 = 0;
|
||||
while (FUNCTION_ABS.apply(param.subtract(NaiveNumber.ONE.promoteTo(param.getClass()))).compareTo(new NaiveNumber(0.1).promoteTo(param.getClass())) >= 0) {
|
||||
if (param.subtract(NaiveNumber.ONE.promoteTo(param.getClass())).signum() == 1) {
|
||||
param = param.divide(fromInt(param.getClass(), 2));
|
||||
while (FUNCTION_ABS.apply(param.subtract(NaiveNumber.ONE.promoteTo(param.getClassVal()))).compareTo(new NaiveNumber(0.1).promoteTo(param.getClassVal())) >= 0) {
|
||||
if (param.subtract(NaiveNumber.ONE.promoteTo(param.getClassVal())).signum() == 1) {
|
||||
param = param.divide(fromInt(param.getClassVal(), 2));
|
||||
powersOf2++;
|
||||
if (param.subtract(NaiveNumber.ONE.promoteTo(param.getClass())).signum() != 1) {
|
||||
if (param.subtract(NaiveNumber.ONE.promoteTo(param.getClassVal())).signum() != 1) {
|
||||
break;
|
||||
//No infinite loop for you.
|
||||
}
|
||||
} else {
|
||||
param = param.multiply(fromInt(param.getClass(), 2));
|
||||
param = param.multiply(fromInt(param.getClassVal(), 2));
|
||||
powersOf2--;
|
||||
if (param.subtract(NaiveNumber.ONE.promoteTo(param.getClass())).signum() != -1) {
|
||||
if (param.subtract(NaiveNumber.ONE.promoteTo(param.getClassVal())).signum() != -1) {
|
||||
break;
|
||||
//No infinite loop for you.
|
||||
}
|
||||
}
|
||||
}
|
||||
return getLog2(param).multiply((new NaiveNumber(powersOf2)).promoteTo(param.getClass())).add(getLogPartialSum(param));
|
||||
return getLog2(param).multiply((new NaiveNumber(powersOf2)).promoteTo(param.getClassVal())).add(getLogPartialSum(param));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,13 +189,13 @@ public class StandardPlugin extends Plugin {
|
||||
private NumberInterface getLogPartialSum(NumberInterface x) {
|
||||
|
||||
NumberInterface maxError = getMaxError(x);
|
||||
x = x.subtract(NaiveNumber.ONE.promoteTo(x.getClass())); //Terms used are for log(x+1).
|
||||
x = x.subtract(NaiveNumber.ONE.promoteTo(x.getClassVal())); //Terms used are for log(x+1).
|
||||
NumberInterface currentNumerator = x, currentTerm = x, sum = x;
|
||||
int n = 1;
|
||||
while (FUNCTION_ABS.apply(currentTerm).compareTo(maxError) > 0) {
|
||||
n++;
|
||||
currentNumerator = currentNumerator.multiply(x).negate();
|
||||
currentTerm = currentNumerator.divide(new NaiveNumber(n).promoteTo(x.getClass()));
|
||||
currentTerm = currentNumerator.divide(new NaiveNumber(n).promoteTo(x.getClassVal()));
|
||||
sum = sum.add(currentTerm);
|
||||
}
|
||||
return sum;
|
||||
@@ -208,18 +208,18 @@ public class StandardPlugin extends Plugin {
|
||||
*/
|
||||
private NumberInterface getLog2(NumberInterface number) {
|
||||
NumberInterface maxError = getMaxError(number);
|
||||
//NumberInterface errorBound = fromInt(number.getClass(), 1);
|
||||
//NumberInterface errorBound = fromInt(number.getClassVal(), 1);
|
||||
//We'll use the series \sigma_{n >= 1) ((1/3^n + 1/4^n) * 1/n)
|
||||
//In the following, a=1/3^n, b=1/4^n, c = 1/n.
|
||||
//a is also an error bound.
|
||||
NumberInterface a = fromInt(number.getClass(), 1), b = a, c = a;
|
||||
NumberInterface sum = NaiveNumber.ZERO.promoteTo(number.getClass());
|
||||
NumberInterface a = fromInt(number.getClassVal(), 1), b = a, c = a;
|
||||
NumberInterface sum = NaiveNumber.ZERO.promoteTo(number.getClassVal());
|
||||
int n = 0;
|
||||
while (a.compareTo(maxError) >= 1) {
|
||||
n++;
|
||||
a = a.divide(fromInt(number.getClass(), 3));
|
||||
b = b.divide(fromInt(number.getClass(), 4));
|
||||
c = NaiveNumber.ONE.promoteTo(number.getClass()).divide((new NaiveNumber(n)).promoteTo(number.getClass()));
|
||||
a = a.divide(fromInt(number.getClassVal(), 3));
|
||||
b = b.divide(fromInt(number.getClassVal(), 4));
|
||||
c = NaiveNumber.ONE.promoteTo(number.getClassVal()).divide((new NaiveNumber(n)).promoteTo(number.getClassVal()));
|
||||
sum = sum.add(a.add(b).multiply(c));
|
||||
}
|
||||
return sum;
|
||||
@@ -236,7 +236,7 @@ public class StandardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
return OP_CARET.getFunction().apply(params[0], ((new NaiveNumber(0.5)).promoteTo(params[0].getClass())));
|
||||
return OP_CARET.getFunction().apply(params[0], ((new NaiveNumber(0.5)).promoteTo(params[0].getClassVal())));
|
||||
}
|
||||
};
|
||||
/**
|
||||
@@ -304,25 +304,25 @@ public class StandardPlugin extends Plugin {
|
||||
NumberInterface maxError = getMaxError(params[0]);
|
||||
int n = 0;
|
||||
if (params[0].signum() <= 0) {
|
||||
NumberInterface currentTerm = NaiveNumber.ONE.promoteTo(params[0].getClass()), sum = currentTerm;
|
||||
NumberInterface currentTerm = NaiveNumber.ONE.promoteTo(params[0].getClassVal()), sum = currentTerm;
|
||||
while (FUNCTION_ABS.apply(currentTerm).compareTo(maxError) > 0) {
|
||||
n++;
|
||||
currentTerm = currentTerm.multiply(params[0]).divide((new NaiveNumber(n)).promoteTo(params[0].getClass()));
|
||||
currentTerm = currentTerm.multiply(params[0]).divide((new NaiveNumber(n)).promoteTo(params[0].getClassVal()));
|
||||
sum = sum.add(currentTerm);
|
||||
}
|
||||
return sum;
|
||||
} else {
|
||||
//We need n such that x^(n+1) * 3^ceil(x) <= maxError * (n+1)!.
|
||||
//right and left refer to lhs and rhs in the above inequality.
|
||||
NumberInterface sum = NaiveNumber.ONE.promoteTo(params[0].getClass());
|
||||
NumberInterface sum = NaiveNumber.ONE.promoteTo(params[0].getClassVal());
|
||||
NumberInterface nextNumerator = params[0];
|
||||
NumberInterface left = params[0].multiply(fromInt(params[0].getClass(), 3).intPow(params[0].ceiling().intValue())), right = maxError;
|
||||
NumberInterface left = params[0].multiply(fromInt(params[0].getClassVal(), 3).intPow(params[0].ceiling().intValue())), right = maxError;
|
||||
do {
|
||||
sum = sum.add(nextNumerator.divide(factorial(params[0].getClass(), n + 1)));
|
||||
sum = sum.add(nextNumerator.divide(factorial(params[0].getClassVal(), n + 1)));
|
||||
n++;
|
||||
nextNumerator = nextNumerator.multiply(params[0]);
|
||||
left = left.multiply(params[0]);
|
||||
NumberInterface nextN = (new NaiveNumber(n + 1)).promoteTo(params[0].getClass());
|
||||
NumberInterface nextN = (new NaiveNumber(n + 1)).promoteTo(params[0].getClassVal());
|
||||
right = right.multiply(nextN);
|
||||
//System.out.println(left + ", " + right);
|
||||
}
|
||||
@@ -339,24 +339,16 @@ public class StandardPlugin extends Plugin {
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length == 2
|
||||
&& !(params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0
|
||||
&& params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) == 0)
|
||||
&& !(params[0].signum() == -1 && params[1].fractionalPart().compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) != 0);
|
||||
&& !(params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClassVal())) == 0
|
||||
&& params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClassVal())) == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
if (params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0)
|
||||
return NaiveNumber.ZERO.promoteTo(params[0].getClass());
|
||||
else if (params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0)
|
||||
return NaiveNumber.ONE.promoteTo(params[1].getClass());
|
||||
//Detect integer bases:
|
||||
if(params[0].fractionalPart().compareTo(fromInt(params[0].getClass(), 0)) == 0
|
||||
&& FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), Integer.MAX_VALUE)) < 0
|
||||
&& FUNCTION_ABS.apply(params[1]).compareTo(fromInt(params[1].getClass(), 1)) >= 0){
|
||||
NumberInterface[] newParams = {params[0], params[1].fractionalPart()};
|
||||
return params[0].intPow(params[1].floor().intValue()).multiply(applyInternal(newParams));
|
||||
}
|
||||
if (params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClassVal())) == 0)
|
||||
return NaiveNumber.ZERO.promoteTo(params[0].getClassVal());
|
||||
else if (params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClassVal())) == 0)
|
||||
return NaiveNumber.ONE.promoteTo(params[1].getClassVal());
|
||||
return FUNCTION_EXP.apply(FUNCTION_LN.apply(FUNCTION_ABS.apply(params[0])).multiply(params[1]));
|
||||
}
|
||||
});
|
||||
@@ -371,13 +363,13 @@ public class StandardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
NumberInterface pi = piFor(params[0].getClass());
|
||||
NumberInterface twoPi = pi.multiply(fromInt(pi.getClass(), 2));
|
||||
NumberInterface pi = piFor(params[0].getClassVal());
|
||||
NumberInterface twoPi = pi.multiply(fromInt(pi.getClassVal(), 2));
|
||||
NumberInterface theta = getSmallAngle(params[0], pi);
|
||||
//System.out.println(theta);
|
||||
if (theta.compareTo(pi.multiply(new NaiveNumber(1.5).promoteTo(twoPi.getClass()))) >= 0) {
|
||||
if (theta.compareTo(pi.multiply(new NaiveNumber(1.5).promoteTo(twoPi.getClassVal()))) >= 0) {
|
||||
theta = theta.subtract(twoPi);
|
||||
} else if (theta.compareTo(pi.divide(fromInt(pi.getClass(), 2))) > 0) {
|
||||
} else if (theta.compareTo(pi.divide(fromInt(pi.getClassVal(), 2))) > 0) {
|
||||
theta = pi.subtract(theta);
|
||||
}
|
||||
//System.out.println(theta);
|
||||
@@ -395,7 +387,7 @@ public class StandardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
return functionSin.apply(piFor(params[0].getClass()).divide(fromInt(params[0].getClass(), 2))
|
||||
return functionSin.apply(piFor(params[0].getClassVal()).divide(fromInt(params[0].getClassVal(), 2))
|
||||
.subtract(params[0]));
|
||||
}
|
||||
};
|
||||
@@ -424,7 +416,7 @@ public class StandardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
return NaiveNumber.ONE.promoteTo(params[0].getClass()).divide(functionCos.apply(params[0]));
|
||||
return NaiveNumber.ONE.promoteTo(params[0].getClassVal()).divide(functionCos.apply(params[0]));
|
||||
}
|
||||
};
|
||||
/**
|
||||
@@ -438,7 +430,7 @@ public class StandardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
return NaiveNumber.ONE.promoteTo(params[0].getClass()).divide(functionSin.apply(params[0]));
|
||||
return NaiveNumber.ONE.promoteTo(params[0].getClassVal()).divide(functionSin.apply(params[0]));
|
||||
}
|
||||
};
|
||||
/**
|
||||
@@ -469,7 +461,7 @@ public class StandardPlugin extends Plugin {
|
||||
* @return the value of the partial sum that has the same class as x.
|
||||
*/
|
||||
private static NumberInterface sumSeries(NumberInterface x, BiFunction<Integer, NumberInterface, NumberInterface> nthTermFunction, int n) {
|
||||
NumberInterface sum = NaiveNumber.ZERO.promoteTo(x.getClass());
|
||||
NumberInterface sum = NaiveNumber.ZERO.promoteTo(x.getClassVal());
|
||||
for (int i = 0; i <= n; i++) {
|
||||
sum = sum.add(nthTermFunction.apply(i, x));
|
||||
}
|
||||
@@ -483,7 +475,7 @@ public class StandardPlugin extends Plugin {
|
||||
* @return the maximum error.
|
||||
*/
|
||||
private static NumberInterface getMaxError(NumberInterface number) {
|
||||
return fromInt(number.getClass(), 10).intPow(-number.getMaxPrecision());
|
||||
return fromInt(number.getClassVal(), 10).intPow(-number.getMaxPrecision());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,7 +514,7 @@ public class StandardPlugin extends Plugin {
|
||||
do {
|
||||
n += 2;
|
||||
power = power.multiply(multiplier);
|
||||
currentTerm = power.divide(factorial(x.getClass(), n));
|
||||
currentTerm = power.divide(factorial(x.getClassVal(), n));
|
||||
sum = sum.add(currentTerm);
|
||||
} while (FUNCTION_ABS.apply(currentTerm).compareTo(maxError) > 0);
|
||||
return sum;
|
||||
@@ -535,7 +527,7 @@ public class StandardPlugin extends Plugin {
|
||||
* @return theta in [0, 2pi) that differs from phi by a multiple of 2pi.
|
||||
*/
|
||||
private static NumberInterface getSmallAngle(NumberInterface phi, NumberInterface pi) {
|
||||
NumberInterface twoPi = pi.multiply(new NaiveNumber("2").promoteTo(phi.getClass()));
|
||||
NumberInterface twoPi = pi.multiply(new NaiveNumber("2").promoteTo(phi.getClassVal()));
|
||||
NumberInterface theta = FUNCTION_ABS.apply(phi).subtract(twoPi
|
||||
.multiply(FUNCTION_ABS.apply(phi).divide(twoPi).floor())); //Now theta is in [0, 2pi).
|
||||
if (phi.signum() < 0) {
|
||||
|
||||
52
src/main/java/org/nwapw/abacus/plugin/VariablePlugin.java
Normal file
52
src/main/java/org/nwapw/abacus/plugin/VariablePlugin.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package org.nwapw.abacus.plugin;
|
||||
|
||||
import org.nwapw.abacus.function.Function;
|
||||
import org.nwapw.abacus.function.Operator;
|
||||
import org.nwapw.abacus.function.OperatorAssociativity;
|
||||
import org.nwapw.abacus.function.OperatorType;
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
import org.nwapw.abacus.number.Variable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class VariablePlugin extends Plugin {
|
||||
private HashMap<String,NumberInterface> variableMap;
|
||||
public final Operator OP_EQUALS = new Operator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, -1, new Function() {
|
||||
//private HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>> storedList = new HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>>();
|
||||
@Override
|
||||
protected boolean matchesParams(NumberInterface[] params) {
|
||||
return params.length == 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||
//System.out.println((char)Double.parseDouble(params[1].toString()));
|
||||
//System.out.println(params[0].toString());
|
||||
if (params[0] instanceof Variable){
|
||||
variableMap.put(((Variable) params[0]).getVariable(), params[1]);
|
||||
}
|
||||
return params[1];
|
||||
}
|
||||
});
|
||||
public NumberInterface getValue(String variable){
|
||||
return variableMap.get(variable);
|
||||
}
|
||||
public VariablePlugin(PluginManager manager) {
|
||||
super(manager);
|
||||
//variables = new ArrayList<>();
|
||||
variableMap=new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
//variables = new ArrayList<>();
|
||||
variableMap=new HashMap<>();
|
||||
registerOperator("=",OP_EQUALS);
|
||||
}
|
||||
@Override
|
||||
public void onDisable(){
|
||||
|
||||
}
|
||||
};
|
||||
108
src/main/java/org/nwapw/abacus/tree/BinaryNode.java
Normal file
108
src/main/java/org/nwapw/abacus/tree/BinaryNode.java
Normal file
@@ -0,0 +1,108 @@
|
||||
package org.nwapw.abacus.tree;
|
||||
|
||||
/**
|
||||
* A tree node that represents an operation being applied to two operands.
|
||||
*/
|
||||
public class BinaryNode extends TreeNode {
|
||||
|
||||
/**
|
||||
* The operation being applied.
|
||||
*/
|
||||
private String operation;
|
||||
/**
|
||||
* The left node of the operation.
|
||||
*/
|
||||
private TreeNode left;
|
||||
/**
|
||||
* The right node of the operation.
|
||||
*/
|
||||
private TreeNode right;
|
||||
|
||||
private BinaryNode() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new operation node with the given operation
|
||||
* and no child nodes.
|
||||
*
|
||||
* @param operation the operation.
|
||||
*/
|
||||
public BinaryNode(String operation) {
|
||||
this(operation, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new operation node with the given operation
|
||||
* and child nodes.
|
||||
*
|
||||
* @param operation the operation.
|
||||
* @param left the left node of the expression.
|
||||
* @param right the right node of the expression.
|
||||
*/
|
||||
public BinaryNode(String operation, TreeNode left, TreeNode right) {
|
||||
this.operation = operation;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the operation in this node.
|
||||
*
|
||||
* @return the operation in this node.
|
||||
*/
|
||||
public String getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the left sub-expression of this node.
|
||||
*
|
||||
* @return the left node.
|
||||
*/
|
||||
public TreeNode getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left sub-expression of this node.
|
||||
*
|
||||
* @param left the sub-expression to apply.
|
||||
*/
|
||||
public void setLeft(TreeNode left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the right sub-expression of this node.
|
||||
*
|
||||
* @return the right node.
|
||||
*/
|
||||
public TreeNode getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right sub-expression of this node.
|
||||
*
|
||||
* @param right the sub-expression to apply.
|
||||
*/
|
||||
public void setRight(TreeNode right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T reduce(Reducer<T> reducer) {
|
||||
T leftReduce = left.reduce(reducer);
|
||||
T rightReduce = right.reduce(reducer);
|
||||
if (leftReduce == null || rightReduce == null) return null;
|
||||
return reducer.reduceNode(this, leftReduce, rightReduce);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String leftString = left != null ? left.toString() : "null";
|
||||
String rightString = right != null ? right.toString() : "null";
|
||||
|
||||
return "(" + leftString + operation + rightString + ")";
|
||||
}
|
||||
}
|
||||
85
src/main/java/org/nwapw/abacus/tree/FunctionNode.java
Normal file
85
src/main/java/org/nwapw/abacus/tree/FunctionNode.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package org.nwapw.abacus.tree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A node that represents a function call.
|
||||
*/
|
||||
public class FunctionNode extends TreeNode {
|
||||
|
||||
/**
|
||||
* The name of the function being called
|
||||
*/
|
||||
private String function;
|
||||
/**
|
||||
* The list of arguments to the function.
|
||||
*/
|
||||
private List<TreeNode> children;
|
||||
|
||||
/**
|
||||
* Creates a function node with no function.
|
||||
*/
|
||||
private FunctionNode() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new function node with the given function name.
|
||||
*
|
||||
* @param function the function name.
|
||||
*/
|
||||
public FunctionNode(String function) {
|
||||
this.function = function;
|
||||
children = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the function name for this node.
|
||||
*
|
||||
* @return the function name.
|
||||
*/
|
||||
public String getFunction() {
|
||||
return function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a child to the end of this node's child list.
|
||||
*
|
||||
* @param node the child to add.
|
||||
*/
|
||||
public void appendChild(TreeNode node) {
|
||||
children.add(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new child to the beginning of this node's child list.
|
||||
*
|
||||
* @param node the node to add.
|
||||
*/
|
||||
public void prependChild(TreeNode node) {
|
||||
children.add(0, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T reduce(Reducer<T> reducer) {
|
||||
Object[] reducedChildren = new Object[children.size()];
|
||||
for (int i = 0; i < reducedChildren.length; i++) {
|
||||
reducedChildren[i] = children.get(i).reduce(reducer);
|
||||
if (reducedChildren[i] == null) return null;
|
||||
}
|
||||
return reducer.reduceNode(this, reducedChildren);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(function);
|
||||
buffer.append("(");
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
buffer.append(children.get(i));
|
||||
buffer.append(i == children.size() - 1 ? "" : ", ");
|
||||
}
|
||||
buffer.append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
49
src/main/java/org/nwapw/abacus/tree/NumberNode.java
Normal file
49
src/main/java/org/nwapw/abacus/tree/NumberNode.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package org.nwapw.abacus.tree;
|
||||
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
|
||||
/**
|
||||
* A node implementation that represents a single number.
|
||||
*/
|
||||
public class NumberNode extends TreeNode {
|
||||
|
||||
/**
|
||||
* The number that is represented by this number node.
|
||||
*/
|
||||
private NumberInterface number;
|
||||
|
||||
/**
|
||||
* Creates a number node with no number.
|
||||
*/
|
||||
public NumberNode() {
|
||||
number = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new number node with the given double value.
|
||||
*
|
||||
* @param newNumber the number for which to create a number node.
|
||||
*/
|
||||
public NumberNode(NumberInterface newNumber) {
|
||||
this.number = newNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number value of this node.
|
||||
*
|
||||
* @return the number value of this node.
|
||||
*/
|
||||
public NumberInterface getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T reduce(Reducer<T> reducer) {
|
||||
return reducer.reduceNode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return number != null ? number.toString() : "null";
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.nwapw.abacus.tree;
|
||||
import org.nwapw.abacus.Abacus;
|
||||
import org.nwapw.abacus.function.Function;
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
import org.nwapw.abacus.number.Variable;
|
||||
|
||||
/**
|
||||
* A reducer implementation that turns a tree into a single number.
|
||||
@@ -47,6 +48,8 @@ public class NumberReducer implements Reducer<NumberInterface> {
|
||||
Function function = abacus.getPluginManager().functionFor(((FunctionNode) node).getFunction());
|
||||
if (function == null) return null;
|
||||
return function.apply(convertedChildren);
|
||||
} else if (node instanceof VariableNode){
|
||||
return (NumberInterface)new Variable(abacus.getVar(((VariableNode)node).getVariable()),((VariableNode)node).getVariable());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.nwapw.abacus.tree;
|
||||
public enum TokenType {
|
||||
|
||||
INTERNAL_FUNCTION_END(-1),
|
||||
ANY(0), WHITESPACE(1), COMMA(2), OP(3), NUM(4), FUNCTION(5), OPEN_PARENTH(6), CLOSE_PARENTH(7);
|
||||
ANY(0), WHITESPACE(1), COMMA(2), OP(3), NUM(4), VARIABLE(5), FUNCTION(6), OPEN_PARENTH(7), CLOSE_PARENTH(8);
|
||||
|
||||
/**
|
||||
* The priority by which this token gets sorted.
|
||||
|
||||
17
src/main/java/org/nwapw/abacus/tree/TreeNode.java
Normal file
17
src/main/java/org/nwapw/abacus/tree/TreeNode.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package org.nwapw.abacus.tree;
|
||||
|
||||
/**
|
||||
* An abstract class that represents an expression tree node.
|
||||
*/
|
||||
public abstract class TreeNode {
|
||||
|
||||
/**
|
||||
* The function that reduces a tree to a single vale.
|
||||
*
|
||||
* @param reducer the reducer used to reduce the tree.
|
||||
* @param <T> the type the reducer produces.
|
||||
* @return the result of the reduction, or null on error.
|
||||
*/
|
||||
public abstract <T> T reduce(Reducer<T> reducer);
|
||||
|
||||
}
|
||||
63
src/main/java/org/nwapw/abacus/tree/UnaryNode.java
Normal file
63
src/main/java/org/nwapw/abacus/tree/UnaryNode.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package org.nwapw.abacus.tree;
|
||||
|
||||
public class UnaryNode extends TreeNode {
|
||||
|
||||
/**
|
||||
* The operation this node will apply.
|
||||
*/
|
||||
private String operation;
|
||||
/**
|
||||
* The tree node to apply the operation to.
|
||||
*/
|
||||
private TreeNode applyTo;
|
||||
|
||||
/**
|
||||
* Creates a new node with the given operation and no child.
|
||||
*
|
||||
* @param operation the operation for this node.
|
||||
*/
|
||||
public UnaryNode(String operation) {
|
||||
this(operation, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new node with the given operation and child.
|
||||
*
|
||||
* @param operation the operation for this node.
|
||||
* @param applyTo the node to apply the function to.
|
||||
*/
|
||||
public UnaryNode(String operation, TreeNode applyTo) {
|
||||
this.operation = operation;
|
||||
this.applyTo = applyTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T reduce(Reducer<T> reducer) {
|
||||
Object reducedChild = applyTo.reduce(reducer);
|
||||
if (reducedChild == null) return null;
|
||||
return reducer.reduceNode(this, reducedChild);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the operation of this node.
|
||||
*
|
||||
* @return the operation this node performs.
|
||||
*/
|
||||
public String getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node to which this node's operation applies.
|
||||
*
|
||||
* @return the tree node to which the operation will be applied.
|
||||
*/
|
||||
public TreeNode getApplyTo() {
|
||||
return applyTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + (applyTo == null ? "null" : applyTo.toString()) + ")" + operation;
|
||||
}
|
||||
}
|
||||
24
src/main/java/org/nwapw/abacus/tree/VariableNode.java
Normal file
24
src/main/java/org/nwapw/abacus/tree/VariableNode.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.nwapw.abacus.tree;
|
||||
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
|
||||
public class VariableNode extends TreeNode{
|
||||
private String variable;
|
||||
public VariableNode() {
|
||||
variable = null;
|
||||
}
|
||||
public VariableNode(String name){
|
||||
this.variable = name;
|
||||
}
|
||||
public String getVariable() {
|
||||
return variable;
|
||||
}
|
||||
@Override
|
||||
public <T> T reduce(Reducer<T> reducer) {
|
||||
return reducer.reduceNode(this);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
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)
|
||||
@@ -1,26 +0,0 @@
|
||||
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? {
|
||||
val leftReduce = left?.reduce(reducer) ?: return null
|
||||
val rightReduce = right?.reduce(reducer) ?: return null
|
||||
return reducer.reduceNode(this, leftReduce, rightReduce)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "(" + (left?.toString() ?: "null") + operation + (right?.toString() ?: "null") + ")"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
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? {
|
||||
val children = Array<Any?>(children.size, { children[it].reduce(reducer) ?: return null; })
|
||||
return reducer.reduceNode(this, *children)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
val buffer = StringBuffer()
|
||||
buffer.append(function)
|
||||
buffer.append('(')
|
||||
for (i in 0 until children.size) {
|
||||
buffer.append(children[i].toString())
|
||||
buffer.append(if (i == children.size - 1) ")" else ",")
|
||||
}
|
||||
return buffer.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)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
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? {
|
||||
return reducer.reduceNode(this)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return number.toString()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package org.nwapw.abacus.tree
|
||||
|
||||
/**
|
||||
* A tree node.
|
||||
*/
|
||||
abstract class TreeNode {
|
||||
|
||||
abstract fun <T: Any> reduce(reducer: Reducer<T>) : T?
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
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? {
|
||||
val reducedChild = applyTo?.reduce(reducer) ?: return null
|
||||
return reducer.reduceNode(this, reducedChild)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "(" + (applyTo?.toString() ?: "null") + ")" + operation
|
||||
}
|
||||
|
||||
}
|
||||
@@ -60,14 +60,61 @@
|
||||
</FlowPane>
|
||||
</GridPane>
|
||||
</Tab>
|
||||
<Tab fx:id="functionListTab" text="Functions" closable="false">
|
||||
<VBox spacing="10">
|
||||
<Tab fx:id="macroTab" text="Macros" closable="false">
|
||||
<BorderPane>
|
||||
<padding>
|
||||
<Insets left="10" right="10" top="10" bottom="10"/>
|
||||
<Insets top="10" bottom="10" left="10" right="10"/>
|
||||
</padding>
|
||||
<TextField fx:id="functionListSearchField" maxWidth="Infinity"/>
|
||||
<ListView maxWidth="Infinity" fx:id="functionListView"/>
|
||||
</VBox>
|
||||
<center>
|
||||
<BorderPane>
|
||||
<center>
|
||||
<ScrollPane hbarPolicy="NEVER" vbarPolicy="NEVER" prefWidth="50" fitToWidth="true">
|
||||
<SplitPane prefHeight="Infinity" >
|
||||
<BorderPane prefHeight="Infinity">
|
||||
<center>
|
||||
<TextArea fx:id="macroField" wrapText="false" prefHeight="Infinity"/>
|
||||
</center>
|
||||
</BorderPane>
|
||||
<BorderPane prefHeight="Infinity">
|
||||
<center>
|
||||
<TextArea fx:id="macroOutputField" wrapText="false" text="aaa
aaaaa" editable="false" prefHeight="Infinity"/>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</SplitPane>
|
||||
</ScrollPane>
|
||||
|
||||
</center>
|
||||
</BorderPane>
|
||||
</center>
|
||||
<bottom>
|
||||
<VBox>
|
||||
|
||||
<Button fx:id="inputButtonMacro" text="Calculate"
|
||||
onAction="#macroCalculation" maxWidth="Infinity"/>
|
||||
<Button fx:id="stopButtonMacro" text="Stop" onAction="#performStop" maxWidth="Infinity"/>
|
||||
</VBox>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
<!--
|
||||
<GridPane>
|
||||
<padding>
|
||||
<Insets top="10" bottom="10" left="10" right="10"/>
|
||||
</padding>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints percentWidth="100.0"/>
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints percentHeight="85.0"/>
|
||||
<RowConstraints/>
|
||||
<RowConstraints/>
|
||||
</rowConstraints>
|
||||
<TextArea fx:id="macroField" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
|
||||
<Button fx:id="inputButtonMacro" text="Calculate" maxWidth="Infinity"
|
||||
onAction="#macroCalculation" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
|
||||
<Button fx:id="stopButtonMacro" text="Stop" onAction="#performStop" maxWidth="Infinity"
|
||||
disable="true" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
|
||||
</GridPane>
|
||||
-->
|
||||
</Tab>
|
||||
</TabPane>
|
||||
</center>
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.nwapw.abacus.tree.TreeNode;
|
||||
|
||||
public class CalculationTests {
|
||||
|
||||
private static Abacus abacus = new Abacus(new Configuration(0, "precise", new String[]{}));
|
||||
private static Abacus abacus = new Abacus(new Configuration(0, "precise", new String[]{}),null);
|
||||
|
||||
@BeforeClass
|
||||
public static void prepareTests(){
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
|
||||
public class TokenizerTests {
|
||||
|
||||
private static Abacus abacus = new Abacus(new Configuration(0, "precise", new String[]{}));
|
||||
private static Abacus abacus = new Abacus(new Configuration(0, "precise", new String[]{}),null);
|
||||
private static LexerTokenizer lexerTokenizer = new LexerTokenizer();
|
||||
private static Function subtractFunction = new Function() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user