Re: Bitwise operation

75 views
Skip to first unread message
Message has been deleted

Richard Morris

unread,
Apr 18, 2013, 8:43:39 AM4/18/13
to jep-...@googlegroups.com
Hi Simone,

You need to specify the StandardConfigurableParser rather than the StandardParser. This allows a more flexible syntax which includes the extra operators specified with the BitwiseOperatorTable.

The code below should work.

Richard

    Jep jep = new Jep(new StandardConfigurableParser());

    BitwiseOperatorTable bitwiseOperatorTable = new BitwiseOperatorTable("**", "^");

    jep.setComponent(bitwiseOperatorTable);

    //jep.reinitializeComponents();

    String formula = "a|b == b";

    jep.addVariable("a", 0x1);

    jep.addVariable("b", 0x1);

    jep.parse(formula);

    System.out.println(jep.evaluate());


On Thursday, April 18, 2013 10:20:55 AM UTC+1, Simone Di Nobile wrote:
I need to use bit opertation, i try this code:
 
        Jep jep = new Jep();
        BitwiseOperatorTable bitwiseOperatorTable = new BitwiseOperatorTable("**", "^");
        jep.setComponent(bitwiseOperatorTable);
        String formula = "a & b == b";
        jep.addVariable("a", 0x1);
        jep.addVariable("b", 0x1);
        jep.parse(formula);
        System.out.println(jep.evaluate());
 
But i got this error:
 
Exception in thread "main" com.singularsys.jep.ParseException: Lexical error at line 1, column 4.  Encountered: " " (32), after : "&"
 at com.singularsys.jep.parser.StandardParser.parse(Unknown Source)
 at com.singularsys.jep.Jep.parse(Unknown Source)
 at com.singularsys.jep.Jep.parse(Unknown Source)
 at jepformulapanda.JepFormulaPanda.main(JepFormulaPanda.java:29)
Caused by: com.singularsys.jep.parser.ParseException: Lexical error at line 1, column 4.  Encountered: " " (32), after : "&"
 at com.singularsys.jep.parser.JccParser.parseStream(Unknown Source)
 ... 4 more
Java Result: 1
 
Why???
Message has been deleted

Simone Di Nobile

unread,
Apr 18, 2013, 9:08:22 AM4/18/13
to jep-...@googlegroups.com
Ok, perferct it works if i set StandardConfigurableParser().
 
But it works only if i made 
a & b 
 
i can't do
 
a & b == b
 
i got this error:
Exception in thread "main" com.singularsys.jep.EvaluationException: Both arguments must implement Number, they are 1.0 (Double), true (Boolean)
 at com.singularsys.jep.misc.bitwise.BitAnd.run(Unknown Source)
 
????

Il giorno giovedì 18 aprile 2013 14:57:36 UTC+2, Simone Di Nobile ha scritto:

Simone Di Nobile

unread,
Apr 18, 2013, 9:49:02 AM4/18/13
to jep-...@googlegroups.com
I found the solution....
 
formula = (a & b) == b
Reply all
Reply to author
Forward
0 new messages