rpn progress
This commit is contained in:
parent
a9fca33dea
commit
e563021963
|
@ -1,5 +1,7 @@
|
||||||
package com.fathzer.soft.javaluator;
|
package com.fathzer.soft.javaluator;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -46,6 +48,13 @@ import java.util.Locale;
|
||||||
* @see <a href="../../../license.html">License information</a>
|
* @see <a href="../../../license.html">License information</a>
|
||||||
*/
|
*/
|
||||||
public class DoubleEvaluator extends AbstractEvaluator<Double> {
|
public class DoubleEvaluator extends AbstractEvaluator<Double> {
|
||||||
|
@NotNull
|
||||||
|
public static DoubleEvaluator process(String expression) {
|
||||||
|
DoubleEvaluator evaluator = new DoubleEvaluator();
|
||||||
|
evaluator.evaluate(expression.toLowerCase());
|
||||||
|
return evaluator;
|
||||||
|
}
|
||||||
|
|
||||||
/** The order or operations (operator precedence) is not clearly defined, especially between the unary minus operator and exponentiation
|
/** The order or operations (operator precedence) is not clearly defined, especially between the unary minus operator and exponentiation
|
||||||
* operator (see <a href="http://en.wikipedia.org/wiki/Order_of_operations#Exceptions_to_the_standard">http://en.wikipedia.org/wiki/Order_of_operations</a>).
|
* operator (see <a href="http://en.wikipedia.org/wiki/Order_of_operations#Exceptions_to_the_standard">http://en.wikipedia.org/wiki/Order_of_operations</a>).
|
||||||
* These constants define the operator precedence styles.
|
* These constants define the operator precedence styles.
|
||||||
|
|
|
@ -65,12 +65,10 @@ public class CompileTool {
|
||||||
|
|
||||||
String expression = line.substring(indexOfEquals + 1).trim();
|
String expression = line.substring(indexOfEquals + 1).trim();
|
||||||
|
|
||||||
DoubleEvaluator evaluator = new DoubleEvaluator();
|
String rpn = DoubleEvaluator.process(expression).getRusEfi();
|
||||||
evaluator.evaluate(expression.toLowerCase());
|
|
||||||
|
|
||||||
String rpn = evaluator.getRusEfi();
|
|
||||||
|
|
||||||
bw.write("\n// Human-readable: " + expression + "\r\n");
|
bw.write("\n// Human-readable: " + expression + "\r\n");
|
||||||
bw.write("#define " + name + " \"" + rpn + "\"\r\n");
|
bw.write("#define " + name + " \"" + rpn + "\"\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package com.rusefi.ui.fsio;
|
package com.rusefi.ui.fsio;
|
||||||
|
|
||||||
import com.autsia.bracer.BracerParser;
|
import com.fathzer.soft.javaluator.DoubleEvaluator;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.text.ParseException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (c) Andrey Belomutskiy
|
* (c) Andrey Belomutskiy
|
||||||
|
@ -25,7 +24,7 @@ public class FlexibleControls {
|
||||||
human2rpm.addActionListener(new ActionListener() {
|
human2rpm.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
process();
|
process(FlexibleControls.this.normalForm.getText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -37,17 +36,11 @@ public class FlexibleControls {
|
||||||
|
|
||||||
normalForm.setText("(time_since_boot < 4) | (rpm > 0)");
|
normalForm.setText("(time_since_boot < 4) | (rpm > 0)");
|
||||||
|
|
||||||
process();
|
process(normalForm.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void process() {
|
private void process(String text) {
|
||||||
BracerParser bp = new BracerParser();
|
rpnForm.setText(DoubleEvaluator.process(text).getRusEfi());
|
||||||
try {
|
|
||||||
bp.parse(normalForm.getText());
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
rpnForm.setText(bp.getRusEfi());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getPanel() {
|
public JPanel getPanel() {
|
||||||
|
|
Loading…
Reference in New Issue