auto-sync
This commit is contained in:
parent
37e9bca47f
commit
c9b1b32e71
|
@ -60,7 +60,7 @@ public class BracerParser {
|
|||
* correct
|
||||
* @since 3.0
|
||||
*/
|
||||
public void parse(String expression) throws ParseException {
|
||||
public BracerParser parse(String expression) throws ParseException {
|
||||
/* cleaning stacks */
|
||||
stackOperations.clear();
|
||||
stackRPN.clear();
|
||||
|
@ -140,6 +140,7 @@ public class BracerParser {
|
|||
|
||||
/* reverse stack */
|
||||
Collections.reverse(stackRPN);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,8 +171,16 @@ public class BracerParser {
|
|||
stackAnswer.push(token);
|
||||
} else if (isOperator(token)) {
|
||||
Double a = Double.valueOf(stackAnswer.pop());
|
||||
Double b = Double.valueOf(stackAnswer.pop());
|
||||
boolean aBoolean = a.doubleValue() == 1.0;
|
||||
|
||||
if (token.equals("!")) {
|
||||
stackAnswer.push(String.valueOf(aBoolean ? "1" : "0"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stackAnswer.isEmpty())
|
||||
throw new IllegalStateException("While " + token + " and " + a);
|
||||
Double b = Double.valueOf(stackAnswer.pop());
|
||||
boolean bBoolean = b.doubleValue() == 1.0;
|
||||
switch (token) {
|
||||
case "+":
|
||||
|
|
|
@ -109,6 +109,13 @@ public class BracerParserTest {
|
|||
|
||||
@Test
|
||||
public void testBooleanNot2() throws Exception {
|
||||
assertEquals("0", bracerParser.parse("! false").evaluate());
|
||||
assertEquals("0", bracerParser.parse("! 0").evaluate());
|
||||
assertEquals("0", bracerParser.parse("1 & not(false)").evaluate());
|
||||
assertEquals("0", bracerParser.parse("1 & (!(false))").evaluate());
|
||||
// assertEquals("0", bracerParser.parse("1 & !(0)").evaluate());
|
||||
// assertEquals("0", bracerParser.parse("1 & !(false)").evaluate());
|
||||
|
||||
bracerParser.parse("1 & not(false)");
|
||||
assertEquals("0", bracerParser.evaluate());// todo: this does not seem right
|
||||
assertEquals("1 not 0 &", bracerParser.getRusEfi()); // todo: this does not seem right
|
||||
|
|
Loading…
Reference in New Issue